Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VeNJOB
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
Nguyen Hoang Mai Phuong
VeNJOB
Commits
294232a1
Commit
294232a1
authored
Sep 08, 2021
by
Nguyen Hoang Mai Phuong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix reviews
parent
7a5094b1
Pipeline
#1418
failed with stages
in 0 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
36 additions
and
24 deletions
+36
-24
app/controllers/favorite_jobs_controller.rb
+12
-8
app/controllers/history_jobs_controller.rb
+3
-3
app/controllers/jobs_controller.rb
+9
-8
app/queries/favorite_query.rb
+2
-2
app/queries/history_query.rb
+2
-1
app/views/jobs/index.html.slim
+4
-1
app/views/jobs/show.html.slim
+4
-1
No files found.
app/controllers/favorite_jobs_controller.rb
View file @
294232a1
class
FavoriteJobsController
<
ApplicationController
include
ApplicationHelper
def
index
@favorites
=
job
_query
.
order_favorite
(
current_user
).
page
(
params
[
:page
])
@favorites
=
favorite
_query
.
order_favorite
(
current_user
).
page
(
params
[
:page
])
end
def
update
favorite
=
job_query
.
find_favorite
(
job_params
,
current_user
)
if
favorite
.
empty?
FavoriteJob
.
create
(
job:
Job
.
find
(
params
[
:job_id
]),
user:
current_user
)
job
=
Job
.
find_by
(
id:
params
[
:job_id
])
or
not_found
favorite
=
favorite_query
.
find_favorite
(
job_params
,
current_user
)
if
favorite
.
nil?
FavoriteJob
.
create
(
job:
job
,
user:
current_user
)
@favorite_exists
=
true
else
favorite
.
first
.
destroy
favorite
.
destroy
@favorite_exists
=
false
end
respond_to
do
|
format
|
format
.
html
{
redirect_to
new_user_session_path
,
alert:
'Please sign in.'
}
format
.
js
{}
end
end
def
destroy
@favorite
=
job_query
.
find_favorite
(
job_params
,
current_user
).
first
.
destroy
@favorite
=
favorite_query
.
find_favorite
(
job_params
,
current_user
)
.
destroy
redirect_to
favorite_url
flash
[
:success
]
=
"
#{
@favorite
.
job
.
title
}
was completed and destroyed."
end
...
...
@@ -29,7 +33,7 @@ class FavoriteJobsController < ApplicationController
params
.
permit
(
:job_id
)
end
def
job
_query
@
job
_query
||=
FavoriteQuery
.
new
def
favorite
_query
@
favorite
_query
||=
FavoriteQuery
.
new
end
end
app/controllers/history_jobs_controller.rb
View file @
294232a1
class
HistoryJobsController
<
ApplicationController
def
index
@histories
=
job
_query
.
order_history
(
current_user
)
@histories
=
history
_query
.
order_history
(
current_user
)
end
private
def
job
_query
@
job
_query
||=
HistoryQuery
.
new
def
history
_query
@
history
_query
||=
HistoryQuery
.
new
end
end
app/controllers/jobs_controller.rb
View file @
294232a1
class
JobsController
<
ApplicationController
after_action
:history_action
,
only:
[
:show
]
include
ApplicationHelper
after_action
:history_action
,
only:
[
:show
]
def
index
if
params
[
:city_slug
].
present?
city
=
City
.
find_by
(
slug:
params
[
:city_slug
])
...
...
@@ -16,18 +17,18 @@ class JobsController < ApplicationController
end
def
show
@job
=
Job
.
latest_jobs
.
find_by
(
slug:
params
[
:job_slug
])
@favorite_exists
=
FavoriteJob
.
where
(
job:
@job
,
user:
current_user
)
!=
[]
@job
=
Job
.
find_by
(
slug:
params
[
:job_slug
])
or
not_found
@favorite_exists
=
!
FavoriteJob
.
find_by
(
job:
@job
,
user:
current_user
).
nil?
end
private
def
history_action
history
=
job
_query
.
find_history
(
job_params
,
current_user
)
if
history
.
empty
?
history
=
history
_query
.
find_history
(
job_params
,
current_user
)
if
history
.
nil
?
HistoryJob
.
create
(
job:
Job
.
find
(
params
[
:job_slug
]),
user:
current_user
)
else
history
.
touch
_all
(
:updated_at
)
history
.
touch
(
:updated_at
)
end
HistoryJob
.
first
.
destroy
if
HistoryJob
.
count
>
20
end
...
...
@@ -36,7 +37,7 @@ class JobsController < ApplicationController
params
.
permit
(
:job_slug
)
end
def
job
_query
@
job
_query
||=
HistoryQuery
.
new
def
history
_query
@
history
_query
||=
HistoryQuery
.
new
end
end
app/queries/favorite_query.rb
View file @
294232a1
...
...
@@ -4,11 +4,11 @@ class FavoriteQuery
end
def
find_favorite
(
params
,
current_user
)
@favorites
.
where
(
job:
Job
.
find
(
params
[
:job_id
]),
user:
current_user
)
@favorites
.
find_by
(
job:
Job
.
find
(
params
[
:job_id
]),
user:
current_user
)
end
def
find_favorite_slug
(
params
,
current_user
)
@favorites
.
where
(
job:
Job
.
find
(
params
[
:job_slug
]),
user:
current_user
)
@favorites
.
find_by
(
job:
Job
.
find
(
params
[
:job_slug
]),
user:
current_user
)
end
def
order_favorite
(
current_user
)
...
...
app/queries/history_query.rb
View file @
294232a1
...
...
@@ -8,6 +8,6 @@ class HistoryQuery
end
def
find_history
(
params
,
current_user
)
@histories
.
where
(
job:
Job
.
find
(
params
[
:job_slug
]),
user:
current_user
)
@histories
.
find_by
(
job:
Job
.
find
(
params
[
:job_slug
]),
user:
current_user
)
end
end
\ No newline at end of file
app/views/jobs/index.html.slim
View file @
294232a1
...
...
@@ -28,7 +28,10 @@
p
.mb-1
=
truncate
(
job
.
overview
,
length:
250
)
.col-sm-2.p-3.favourite
=
link_to
favorite_text
,
favorite_update_path
(
job_id:
job
.
id
),
id:
'favorite_link'
,
remote:
true
,
class:
"btn btn-outline-primary"
-
unless
current_user
.
favorite_jobs
.
exists?
(
job
.
id
)
=
link_to
favorite_text
,
favorite_update_path
(
job_id:
job
.
id
),
id:
'favorite_link'
,
remote:
true
,
class:
"btn btn-outline-primary btn-lg"
-
else
=
link_to
favorite_text
,
favorite_update_path
(
job_id:
job
.
id
),
class:
"btn btn-outline-primary btn-lg"
h6
.offset-md-4.px-5
=
page_entries_info
@jobs
h6
.offset-md-4
...
...
app/views/jobs/show.html.slim
View file @
294232a1
...
...
@@ -51,4 +51,7 @@
.col.text-end
=
link_to
"Apply this Job"
,
apply_path
(
job_id:
@job
.
id
),
class:
"btn btn-outline-primary btn-lg"
.col.text-start
=
link_to
favorite_text
,
favorite_update_path
(
job_id:
@job
.
id
),
id:
'favorite_link'
,
remote:
true
,
class:
"btn btn-outline-primary btn-lg"
-
if
user_signed_in?
=
link_to
favorite_text
,
favorite_update_path
(
job_id:
@job
.
id
),
id:
'favorite_link'
,
remote:
true
,
class:
"btn btn-outline-primary btn-lg"
-
else
=
link_to
favorite_text
,
favorite_update_path
(
job_id:
@job
.
id
),
class:
"btn btn-outline-primary btn-lg"
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