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
Mai Hoang Thai Ha
VenJob
Commits
c4008be4
Commit
c4008be4
authored
Nov 02, 2021
by
Thai Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin search service
parent
b8c1c756
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
28 deletions
+36
-28
app/controllers/admins_controller.rb
+4
-28
app/services/admin_search_service.rb
+32
-0
No files found.
app/controllers/admins_controller.rb
View file @
c4008be4
class
AdminsController
<
ApplicationController
before_action
:authenticate_admin!
before_action
:apply_jobs
def
applies
@city
=
City
.
all
.
map
{
|
c
|
[
c
.
name
,
c
.
id
]
}
@industry
=
Industry
.
all
.
map
{
|
i
|
[
i
.
name
,
i
.
id
]
}
search
return
:applies
if
params
[
:search
]
redirect_to
admin_export_csv_path
(
format: :csv
,
params:
applied_params
)
if
params
[
:csv
]
...
...
@@ -12,7 +12,6 @@ class AdminsController < ApplicationController
def
export_csv
date
=
DateTime
.
current
.
to_formatted_s
(
:number
)
search
csv
=
ExportCsvService
.
new
(
@apply_jobs
,
Admin
::
CSV_ATTRIBUTES
)
respond_to
do
|
format
|
format
.
csv
{
send_data
csv
.
perform
,
filename:
"
#{
date
}
_applied.csv"
}
...
...
@@ -21,32 +20,9 @@ class AdminsController < ApplicationController
private
def
search
if
applied_params
.
present?
date_value
params_query
@apply_jobs
=
Kaminari
.
paginate_array
(
@query
).
page
(
params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
else
@apply_jobs
=
ApplyJob
.
includes
(
:job
,
cv_attachment: :blob
).
all
.
page
(
params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
end
end
def
date_value
return
unless
applied_params
[
:date_start
].
present?
&&
params
[
:date_end
].
present?
@d_start
=
Date
.
parse
(
applied_params
[
:date_start
]).
beginning_of_day
@d_end
=
Date
.
parse
(
applied_params
[
:date_end
]).
end_of_day
end
def
params_query
search_params
=
{
apply_jobs:
{
email:
applied_params
[
:email
],
created_at:
(
@d_start
..
@d_end
if
@d_start
&&
@d_end
)
},
cities_jobs:
{
city_id:
applied_params
[
:city
]
},
industries_jobs:
{
industry_id:
applied_params
[
:industry
]
}
}
.
transform_values
{
|
v
|
v
.
delete_if
{
|
_
,
value
|
value
.
blank?
}
}
mapping
=
search_params
.
delete_if
{
|
_
,
value
|
value
.
blank?
}
@query
=
ApplyJob
.
admin_queries
.
where
(
mapping
).
uniq
def
apply_jobs
admin_search
=
AdminSearchService
.
new
(
applied_params
)
@apply_jobs
=
admin_search
.
search
end
def
applied_params
...
...
app/services/admin_search_service.rb
0 → 100644
View file @
c4008be4
class
AdminSearchService
def
initialize
(
applied_params
)
@params
=
applied_params
end
def
search
if
@params
.
present?
date_value
params_query
Kaminari
.
paginate_array
(
@query
).
page
(
@params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
else
ApplyJob
.
includes
(
:job
,
cv_attachment: :blob
).
all
.
page
(
@params
[
:page
]).
per
(
Job
::
JOB_PER_PAGE
)
end
end
def
date_value
return
unless
@params
[
:date_start
].
present?
&&
@params
[
:date_end
].
present?
@d_start
=
Date
.
parse
(
@params
[
:date_start
]).
beginning_of_day
@d_end
=
Date
.
parse
(
@params
[
:date_end
]).
end_of_day
end
def
params_query
search_params
=
{
apply_jobs:
{
email:
@params
[
:email
],
created_at:
(
@d_start
..
@d_end
if
@d_start
&&
@d_end
)
},
cities_jobs:
{
city_id:
@params
[
:city
]
},
industries_jobs:
{
industry_id:
@params
[
:industry
]
}
}
.
transform_values
{
|
v
|
v
.
delete_if
{
|
_
,
value
|
value
.
blank?
}
}
mapping
=
search_params
.
delete_if
{
|
_
,
value
|
value
.
blank?
}
@query
=
ApplyJob
.
admin_queries
.
where
(
mapping
).
uniq
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