Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
ven-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Trịnh Hoàng Phúc
ven-job
Commits
ee707e8a
Commit
ee707e8a
authored
May 22, 2020
by
Trịnh Hoàng Phúc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix review 22/05/2020
parent
f8287fd5
Pipeline
#634
canceled with stages
in 0 seconds
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
34 additions
and
29 deletions
+34
-29
app/controllers/concerns/cookies_history.rb
+1
-6
app/controllers/history_controller.rb
+2
-5
app/controllers/jobs_controller.rb
+6
-1
app/models/history.rb
+0
-4
app/models/job.rb
+1
-1
db/migrate/20200519030913_create_histories.rb
+2
-0
db/schema.rb
+22
-12
No files found.
app/controllers/concerns/cookies_history.rb
View file @
ee707e8a
module
CookiesHistory
module
CookiesHistory
def
set_job_histories
def
set_job_histories
if
cookies
[
:job_ids_history
].
nil?
arr_job_ids
=
cookies
[
:job_ids_history
].
to_s
.
split
(
","
)
cookies
[
:job_ids_history
]
=
{
value:
@job
.
id
,
expires:
Time
.
now
+
3600
}
else
arr_job_ids
=
cookies
[
:job_ids_history
].
split
(
","
)
unless
arr_job_ids
.
include?
(
@job
.
id
.
to_s
)
unless
arr_job_ids
.
include?
(
@job
.
id
.
to_s
)
arr_job_ids
.
shift
if
arr_job_ids
.
count
==
10
arr_job_ids
.
shift
if
arr_job_ids
.
count
==
10
arr_job_ids
<<
@job
.
id
.
to_s
arr_job_ids
<<
@job
.
id
.
to_s
end
end
cookies
[
:job_ids_history
]
=
{
value:
arr_job_ids
.
join
(
","
),
expires:
Time
.
now
+
3600
}
cookies
[
:job_ids_history
]
=
{
value:
arr_job_ids
.
join
(
","
),
expires:
Time
.
now
+
3600
}
end
end
end
end
end
\ No newline at end of file
app/controllers/history_controller.rb
View file @
ee707e8a
class
HistoryController
<
ApplicationController
class
HistoryController
<
ApplicationController
def
index
def
index
if
user_signed_in?
if
user_signed_in?
@jobs_history
=
History
.
includes
(
:job
,
:user
).
where
(
"user_id =
#{
current_user
.
id
}
"
)
@jobs_history
=
History
.
includes
(
:job
,
:user
).
where
(
user_id:
current_user
.
id
).
order
(
updated_at: :desc
)
else
else
arr_job_ids
=
cookies
[
:job_ids_history
].
split
(
","
)
job_ids
=
cookies
[
:job_ids_history
].
split
(
","
)
job_ids
=
cookies
[
:job_ids_history
].
split
(
","
)
@jobs_history
=
Job
.
where
(
"id IN (?)"
,
job_ids
).
order
(
"id DESC"
)
@jobs_history
=
Job
.
find
(
job_ids
).
reverse
end
end
end
end
end
end
\ No newline at end of file
app/controllers/jobs_controller.rb
View file @
ee707e8a
...
@@ -23,7 +23,12 @@ class JobsController < ApplicationController
...
@@ -23,7 +23,12 @@ class JobsController < ApplicationController
if
user_signed_in?
if
user_signed_in?
@apply
=
Apply
.
find_by
(
job_id:
params
[
:id
],
user_id:
current_user
.
id
)
@apply
=
Apply
.
find_by
(
job_id:
params
[
:id
],
user_id:
current_user
.
id
)
@favorite
=
Favorite
.
find_by
(
job_id:
params
[
:id
],
user_id:
current_user
.
id
)
@favorite
=
Favorite
.
find_by
(
job_id:
params
[
:id
],
user_id:
current_user
.
id
)
History
.
create_history
(
params
[
:id
],
current_user
.
id
)
@history
=
History
.
find_by
(
user_id:
current_user
.
id
,
job_id:
params
[
:id
])
if
@history
.
nil?
History
.
create
(
user_id:
current_user
.
id
,
job_id:
params
[
:id
])
else
@history
.
update
(
updated_at:
Time
.
now
)
end
else
else
set_job_histories
set_job_histories
end
end
...
...
app/models/history.rb
View file @
ee707e8a
class
History
<
ApplicationRecord
class
History
<
ApplicationRecord
belongs_to
:user
belongs_to
:user
belongs_to
:job
belongs_to
:job
def
self
.
create_history
(
job_id
,
user_id
)
return
History
.
find_or_create_by
({
job_id:
job_id
,
user_id:
user_id
})
end
end
end
app/models/job.rb
View file @
ee707e8a
...
@@ -34,6 +34,6 @@ class Job < ApplicationRecord
...
@@ -34,6 +34,6 @@ class Job < ApplicationRecord
end
end
def
self
.
related_jobs
(
company_id
,
job_id
)
def
self
.
related_jobs
(
company_id
,
job_id
)
@related_jobs
||=
includes
(
:cities
,
:company
).
where
(
"company_id =
#{
company_id
}
and id !=
#{
job_id
}
"
).
order
(
"id DESC"
).
limit
(
10
)
@related_jobs
||=
includes
(
:cities
,
:company
).
where
(
"company_id =
#{
company_id
}
and id !=
#{
job_id
}
"
).
order
(
id: :desc
).
limit
(
10
)
end
end
end
end
db/migrate/20200519030913_create_histories.rb
View file @
ee707e8a
...
@@ -3,6 +3,8 @@ class CreateHistories < ActiveRecord::Migration[6.0]
...
@@ -3,6 +3,8 @@ class CreateHistories < ActiveRecord::Migration[6.0]
create_table
:histories
do
|
t
|
create_table
:histories
do
|
t
|
t
.
references
:user
,
null:
false
,
foreign_key:
true
t
.
references
:user
,
null:
false
,
foreign_key:
true
t
.
references
:job
,
null:
false
,
foreign_key:
true
t
.
references
:job
,
null:
false
,
foreign_key:
true
t
.
timestamps
end
end
end
end
end
end
db/schema.rb
View file @
ee707e8a
...
@@ -10,9 +10,9 @@
...
@@ -10,9 +10,9 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2020_05_1
8_023337
)
do
ActiveRecord
::
Schema
.
define
(
version:
2020_05_1
9_030913
)
do
create_table
"admins"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"admins"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"reset_password_token"
t
.
string
"reset_password_token"
...
@@ -24,7 +24,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
...
@@ -24,7 +24,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t
.
index
[
"reset_password_token"
],
name:
"index_admins_on_reset_password_token"
,
unique:
true
t
.
index
[
"reset_password_token"
],
name:
"index_admins_on_reset_password_token"
,
unique:
true
end
end
create_table
"applies"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"applies"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"user_id"
,
null:
false
t
.
bigint
"user_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
...
@@ -33,21 +33,21 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
...
@@ -33,21 +33,21 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t
.
index
[
"user_id"
],
name:
"index_applies_on_user_id"
t
.
index
[
"user_id"
],
name:
"index_applies_on_user_id"
end
end
create_table
"cities"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"cities"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
string
"title"
t
.
string
"title"
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
boolean
"foreign"
,
default:
false
t
.
boolean
"foreign"
,
default:
false
end
end
create_table
"cities_jobs"
,
id:
false
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"cities_jobs"
,
id:
false
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"city_id"
,
null:
false
t
.
bigint
"city_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
index
[
"city_id"
,
"job_id"
],
name:
"index_cities_jobs_on_city_id_and_job_id"
t
.
index
[
"city_id"
,
"job_id"
],
name:
"index_cities_jobs_on_city_id_and_job_id"
t
.
index
[
"job_id"
,
"city_id"
],
name:
"index_cities_jobs_on_job_id_and_city_id"
t
.
index
[
"job_id"
,
"city_id"
],
name:
"index_cities_jobs_on_job_id_and_city_id"
end
end
create_table
"companies"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"companies"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
string
"title"
t
.
string
"title"
t
.
string
"address"
t
.
string
"address"
t
.
string
"logo"
t
.
string
"logo"
...
@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
...
@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
end
end
create_table
"favorites"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"favorites"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"user_id"
,
null:
false
t
.
bigint
"user_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
...
@@ -65,20 +65,29 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
...
@@ -65,20 +65,29 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t
.
index
[
"user_id"
],
name:
"index_favorites_on_user_id"
t
.
index
[
"user_id"
],
name:
"index_favorites_on_user_id"
end
end
create_table
"industries"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci"
,
force: :cascade
do
|
t
|
create_table
"histories"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"user_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
index
[
"job_id"
],
name:
"index_histories_on_job_id"
t
.
index
[
"user_id"
],
name:
"index_histories_on_user_id"
end
create_table
"industries"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
string
"title"
t
.
string
"title"
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
end
end
create_table
"industries_jobs"
,
id:
false
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"industries_jobs"
,
id:
false
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
bigint
"industry_id"
,
null:
false
t
.
bigint
"industry_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
bigint
"job_id"
,
null:
false
t
.
index
[
"industry_id"
,
"job_id"
],
name:
"index_industries_jobs_on_industry_id_and_job_id"
t
.
index
[
"industry_id"
,
"job_id"
],
name:
"index_industries_jobs_on_industry_id_and_job_id"
t
.
index
[
"job_id"
,
"industry_id"
],
name:
"index_industries_jobs_on_job_id_and_industry_id"
t
.
index
[
"job_id"
,
"industry_id"
],
name:
"index_industries_jobs_on_job_id_and_industry_id"
end
end
create_table
"jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
string
"title"
t
.
string
"title"
t
.
string
"updated_date_job"
t
.
string
"updated_date_job"
t
.
string
"level"
t
.
string
"level"
...
@@ -97,7 +106,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
...
@@ -97,7 +106,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t
.
index
[
"company_id"
],
name:
"index_jobs_on_company_id"
t
.
index
[
"company_id"
],
name:
"index_jobs_on_company_id"
end
end
create_table
"users"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_0900_ai_ci
"
,
force: :cascade
do
|
t
|
create_table
"users"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"
,
force: :cascade
do
|
t
|
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"email"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"encrypted_password"
,
default:
""
,
null:
false
t
.
string
"reset_password_token"
t
.
string
"reset_password_token"
...
@@ -110,7 +119,6 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
...
@@ -110,7 +119,6 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"created_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
datetime
"updated_at"
,
precision:
6
,
null:
false
t
.
string
"full_name"
t
.
string
"full_name"
t
.
string
"image"
t
.
string
"cv"
t
.
string
"cv"
t
.
string
"provider"
t
.
string
"provider"
t
.
string
"uid"
t
.
string
"uid"
...
@@ -123,4 +131,6 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
...
@@ -123,4 +131,6 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
add_foreign_key
"applies"
,
"users"
add_foreign_key
"applies"
,
"users"
add_foreign_key
"favorites"
,
"jobs"
add_foreign_key
"favorites"
,
"jobs"
add_foreign_key
"favorites"
,
"users"
add_foreign_key
"favorites"
,
"users"
add_foreign_key
"histories"
,
"jobs"
add_foreign_key
"histories"
,
"users"
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment