Commit 02ef8dfd by Van Hau Le

Merge branch 'job_list' into 'master'

Job list

See merge request !7
parents df25189d ff2a10a1
Pipeline #907 canceled with stages
in 0 seconds
...@@ -33,7 +33,7 @@ gem 'whenever', require: false ...@@ -33,7 +33,7 @@ gem 'whenever', require: false
gem 'rubocop', '~> 0.88.0', require: false gem 'rubocop', '~> 0.88.0', require: false
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
gem 'will_paginate', '3.3.0' gem 'kaminari'
# Reduces boot times through caching; required in config/boot.rb # Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false gem 'bootsnap', '>= 1.1.0', require: false
......
...@@ -91,6 +91,18 @@ GEM ...@@ -91,6 +91,18 @@ GEM
io-like (0.3.1) io-like (0.3.1)
jbuilder (2.10.0) jbuilder (2.10.0)
activesupport (>= 5.0.0) activesupport (>= 5.0.0)
kaminari (1.2.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.1)
kaminari-activerecord (= 1.2.1)
kaminari-core (= 1.2.1)
kaminari-actionview (1.2.1)
actionview
kaminari-core (= 1.2.1)
kaminari-activerecord (1.2.1)
activerecord
kaminari-core (= 1.2.1)
kaminari-core (1.2.1)
listen (3.1.5) listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4) rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7) rb-inotify (~> 0.9, >= 0.9.7)
...@@ -234,7 +246,6 @@ GEM ...@@ -234,7 +246,6 @@ GEM
websocket-extensions (0.1.5) websocket-extensions (0.1.5)
whenever (1.0.0) whenever (1.0.0)
chronic (>= 0.6.3) chronic (>= 0.6.3)
will_paginate (3.3.0)
xpath (3.2.0) xpath (3.2.0)
nokogiri (~> 1.8) nokogiri (~> 1.8)
...@@ -248,6 +259,7 @@ DEPENDENCIES ...@@ -248,6 +259,7 @@ DEPENDENCIES
chromedriver-helper chromedriver-helper
coffee-rails (~> 4.2) coffee-rails (~> 4.2)
jbuilder (~> 2.5) jbuilder (~> 2.5)
kaminari
listen (>= 3.0.5, < 3.2) listen (>= 3.0.5, < 3.2)
mechanize (~> 2.7.6) mechanize (~> 2.7.6)
mysql2 (~> 0.5.3) mysql2 (~> 0.5.3)
...@@ -264,7 +276,6 @@ DEPENDENCIES ...@@ -264,7 +276,6 @@ DEPENDENCIES
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console (>= 3.3.0) web-console (>= 3.3.0)
whenever whenever
will_paginate (= 3.3.0)
RUBY VERSION RUBY VERSION
ruby 2.6.6p146 ruby 2.6.6p146
......
...@@ -25,3 +25,4 @@ ...@@ -25,3 +25,4 @@
.viet-nam, .international { .viet-nam, .international {
cursor: pointer; cursor: pointer;
} }
...@@ -6,4 +6,60 @@ ...@@ -6,4 +6,60 @@
margin: 5px; margin: 5px;
padding: 5px; padding: 5px;
} }
.details-banner{
position: relative;
width: 100%;
height: 50vh;
}
.job-details-banner {
background-image: url('job-details.jpg');
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-size: cover;
}
.job-info {
position: absolute;
width: 100%;
bottom: 0;
background-color: #e6e6e6;
color: #262626;
font-size: 16px;
font-family: Bookman, URW Bookman L, serif;
}
.apply-job {
position: absolute;
right: 5%;
top: 10%;
border: 2px solid #006080;
border-radius: 12px;
width: 20%;
text-align: center;
color: white;
background: rgb(2,0,36);
background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(2,93,2,1) 52%, rgba(0,212,255,1) 100%);
}
.info {
background-color: #cce6ff;
margin: 20px;
padding: 20px;
}
.under-descrip {
text-align: center;
}
.apply-btn, .favorite-btn {
margin: 20px;
padding: 20px;
}
.company:hover , .company{
text-decoration: none;
color: gray;
}
.industry::after, .location::after {
margin: 5px;
content: "|";
color: black;
}
.industry:last-child::after, .location:last-child::after {
content: "";
}
...@@ -110,3 +110,26 @@ ...@@ -110,3 +110,26 @@
} }
} }
} }
.result-for {
background-color: #99ff99;
border: 2px solid green;
border-radius: 12px;
text-align: center;
}
.total {
background-color: #b3ecff;
border: 2px solid #006080;
border-radius: 12px;
text-align: center;
font-size: 20px;
font-family: Bookman, URW Bookman L, serif;
}
.job-details .title a {
color: black;
text-decoration: none;
}
.job-details .title a:hover {
color: #e6b800;
transition: 1s;
text-decoration: none;
}
class JobsController < ApplicationController class JobsController < ApplicationController
before_action :set_job, only: [:show]
before_action :general_variables
def index def index
@total_job = Job.count @jobs_list = Job.all.page(params[:page]).per(Job::LIMIT_PAGE)
@jobs_list = Job.all_job end
def city_jobs
@city = City.find_by(converted_name: params[:converted_name])
@jobs_list = @city.jobs.page(params[:page]).per(Job::LIMIT_PAGE)
@result_for_job = @city.jobs.count
end
def industry_jobs
@industry = Industry.find_by(converted_name: params[:converted_name])
@jobs_list = @industry.jobs.page(params[:page]).per(Job::LIMIT_PAGE)
@result_for_job = @industry.jobs.count
end
def company_jobs
@company = Company.find_by(converted_name: params[:converted_name])
@jobs_list = @company.jobs.page(params[:page]).per(Job::LIMIT_PAGE)
@result_for_job = @company.jobs.count
redirect_to jobs_path unless @company
end
def show
redirect_to jobs_path unless @job
end
private
def set_job
@job ||= Job.find_by(params[:id])
end
def general_variables
@cities = City.all @cities = City.all
@industries = Industry.all @industries = Industry.all
@total_job = Job.count
end end
end end
module JobsHelper
def job_description(description)
strip_tags(description).truncate_words(250)
end
end
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
def convert_attribute(val)
return '' if val.blank?
[val, rand(10000)].join.mb_chars.normalize(:kd).gsub(/[Đđ]/, 'd').gsub(/[^\x00-\x7F]/,'').gsub(/[\W+]/,' ').downcase.to_s.split(' ').join('-')
end
end end
class City < ApplicationRecord class City < ApplicationRecord
before_save :set_converted_name
has_many :city_jobs has_many :city_jobs
has_many :jobs, through: :city_jobs has_many :jobs, through: :city_jobs
...@@ -7,4 +9,10 @@ class City < ApplicationRecord ...@@ -7,4 +9,10 @@ class City < ApplicationRecord
scope :top_city, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC').limit(9) } scope :top_city, -> { joins(:jobs).group(:city_id).order('count(job_id) DESC').limit(9) }
scope :location, ->(number) { joins(:jobs).group(:city_id).order('count(job_id) DESC').where(location: number) } scope :location, ->(number) { joins(:jobs).group(:city_id).order('count(job_id) DESC').where(location: number) }
private
def set_converted_name
converted_name = convert_attribute(name)
end
end end
class Company < ApplicationRecord class Company < ApplicationRecord
before_save :set_converted_name
has_many :jobs has_many :jobs
private
def set_converted_name
converted_name = convert_attribute(name)
end
end end
class Industry < ApplicationRecord class Industry < ApplicationRecord
before_save :set_converted_name
has_many :industry_jobs has_many :industry_jobs
has_many :jobs, through: :industry_jobs has_many :jobs, through: :industry_jobs
scope :top_industry, -> { joins(:jobs).group(:industry_id).order('count(job_id) DESC').limit(9) } scope :top_industry, -> { joins(:jobs).group(:industry_id).order('count(job_id) DESC').limit(9) }
scope :all_industry, -> { joins(:jobs).group(:industry_id).order('count(job_id) DESC') } scope :all_industry, -> { joins(:jobs).group(:industry_id).order('count(job_id) DESC') }
private
def set_converted_name
converted_name = convert_attribute(name)
end
end end
class Job < ApplicationRecord class Job < ApplicationRecord
before_save :set_converted_name
belongs_to :company belongs_to :company
has_many :city_jobs has_many :city_jobs
has_many :cities, through: :city_jobs has_many :cities, through: :city_jobs
...@@ -15,11 +17,22 @@ class Job < ApplicationRecord ...@@ -15,11 +17,22 @@ class Job < ApplicationRecord
has_many :histories has_many :histories
has_many :users, through: :histories has_many :users, through: :histories
LIMIT_PAGE = 20
scope :limit_job, -> { includes(:cities, :company).order(created_at: :desc).limit(5) } scope :limit_job, -> { includes(:cities, :company).order(created_at: :desc).limit(5) }
scope :all_job, -> { limit(20).order(created_at: :desc) }
def company_name def company_name
company&.name company&.name
end end
def format_desc
description.truncate_words(250)
end
private
def set_converted_name
converted_name = convert_attribute(title)
end
end end
<div class="col-3 remove-decoration"> <div class="col-3 remove-decoration">
<%= link_to '#' do %> <%= link_to city_jobs_path(converted_name: city.converted_name) do %>
<div class="border border-dark rounded vn-name"> <div class="border border-dark rounded vn-name">
<div> <div>
<strong><%= city.name %></strong> <strong><%= city.name %></strong>
......
<div class="col-3 remove-decoration"> <div class="col-3 remove-decoration">
<%= link_to '#' do %> <%= link_to city_jobs_path(converted_name: city.converted_name) do %>
<div class="border border-dark rounded international-name"> <div class="border border-dark rounded international-name">
<div> <div>
<strong><%= city.name %></strong> <strong><%= city.name %></strong>
......
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
<div class="city-banner rounded vietnam-area">Việt Nam</div> <div class="city-banner rounded vietnam-area">Việt Nam</div>
<div class="city-vietnam"> <div class="city-vietnam">
<div class="row"> <div class="row">
<%= render partial: "vietnam", collection: @cities_vietnam, as: :city %> <%= render partial: "vietnam", collection: @vietnam, as: :city %>
</div> </div>
</div> </div>
<div class="city-banner rounded international-area">International</div> <div class="city-banner rounded international-area">International</div>
<div class="city-international"> <div class="city-international">
<div class="row"> <div class="row">
<%= render partial: "international", collection: @cities_international, as: :city %> <%= render partial: "international", collection: @international, as: :city %>
</div> </div>
</div> </div>
</div> </div>
<div class="col-3 remove-decoration"> <div class="col-3 remove-decoration">
<%= link_to '#' do %> <%= link_to industry_jobs_path(converted_name: industry.converted_name) do %>
<div class="border border-dark rounded industry-details"> <div class="border border-dark rounded industry-details">
<div> <div>
<strong><%= industry.name %></strong> <strong><%= industry.name %></strong>
......
<% if job.cities.present? %> <% if job.cities.present? %>
<div class="border border-dark rounded"> <div class="border border-dark rounded">
<div class="job-details"> <div class="job-details">
<div class="title"><strong><%= job.title %></strong></div> <div class="title">
<div class="row"> <%= link_to job_detail_path(job.id) do %>
<div class="col-4"> <strong><%= job.title %></strong>
<% job.cities.each do |city| %>
<%= city.name %>
<% end %> <% end %>
</div> </div>
<div class="col-4 salary">Salary: <%= job.salary %></div> <div class="row">
<div class="col-5">
<%= job.cities.map(&:name).join(' | ') %>
</div>
<div class="col-5 salary">Salary: <%= job.salary %></div>
<div class="col-10 introduction"> <div class="col-10 introduction">
<%= job_description(job.description) %><br> <%= strip_tags(job.format_desc) %><br>
<%= link_to 'Read more..', '#'%> <%= link_to 'Read more..', job_detail_path(job.id) %>
</div> </div>
</div> </div>
<button type="button" class="btn btn-success" id="button-follow">♥ Favorite</button> <button type="button" class="btn btn-success" id="button-follow">♥ Favorite</button>
......
<div class="row panigation">
<div class="col-12 d-flex justify-content-end paginate-jobs">
<%= paginate @jobs_list, outer_window: 3, window: 2 %>
</div>
</div>
<% provide(:title, 'City Jobs') %>
<div class="container">
<div class="search-bar">
<%= render 'layouts/search_bar' %>
</div>
<div class="total-jobs">
<div class="total">Total: <strong><%= @result_for_job %></strong> jobs in <strong><%= @city.name %></strong></div>
</div>
<%= render "jobs/pagination" %>
<div class="job-list">
<%= render partial: "job", collection: @jobs_list, as: :job %>
</div>
<%= render "jobs/pagination" %>
</div>
<% provide(:title, 'Company Jobs') %>
<div class="container">
<div class="search-bar">
<%= render 'layouts/search_bar' %>
</div>
<div class="total-jobs">
<div class="total">Total: <strong><%= @result_for_job %></strong> jobs in <strong><%= @company.name %></strong></div>
</div>
<%= render "jobs/pagination" %>
<div class="job-list">
<%= render partial: "job", collection: @jobs_list, as: :job %>
</div>
<%= render "jobs/pagination" %>
</div>
...@@ -5,9 +5,10 @@ ...@@ -5,9 +5,10 @@
</div> </div>
<div class="row total-jobs"> <div class="row total-jobs">
<div class="col-4"><strong>Total: <%= @total_job %> jobs</strong></div> <div class="col-4"><strong>Total: <%= @total_job %> jobs</strong></div>
<div class="col-4"><strong>Result for: ... jobs</strong></div>
</div> </div>
<%= render "jobs/pagination" %>
<div class="job-list"> <div class="job-list">
<%= render partial: "job", collection: @jobs_list, as: :job %> <%= render partial: "job", collection: @jobs_list, as: :job %>
</div> </div>
<%= render "jobs/pagination" %>
</div> </div>
<% provide(:title, 'Industry Jobs') %>
<div class="container">
<div class="search-bar">
<%= render 'layouts/search_bar' %>
</div>
<div class="total-jobs">
<div class="total">Total: <strong><%= @result_for_job %></strong> jobs in <strong><%= @industry.name %></strong></div>
</div>
<%= render "jobs/pagination" %>
<div class="job-list">
<%= render partial: "job", collection: @jobs_list, as: :job %>
</div>
<%= render "jobs/pagination" %>
</div>
<div class="container">
<div class="details-banner">
<div class="job-details-banner">
<div class="job-info">
<div><strong><%= @job.title %></strong></div>
<div>
<%= link_to @job.company_name, company_jobs_path(converted_name: @job.company.converted_name), class: 'company' %>
</div>
<div class="breadcrumb">
<%= link_to "TOP", root_path %>&ensp;/&ensp;
<div>
<% @job.cities.each do |city| %>
<%= link_to city.name, city_jobs_path(converted_name: city.converted_name) , class: 'location' %>
<% end %>/&ensp;
</div>
<% @job.industries.each do |industry| %>
<%= link_to industry.name, industry_jobs_path(converted_name: industry.converted_name), class: 'industry' %>
<% end %>/&ensp;
<%= @job.title.truncate_words(5) %>
</div>
<%= link_to '#' do %>
<div class="apply-job">
<strong>Apply Now</strong>
</div>
<% end %>
</div>
</div>
</div>
<div class="details">
<div class="job-infomation">
<h1><%= @job.title %></h1>
<div class="row info border border-dark">
<div class="col-6">
<div class="city">
<strong>Location:</strong>
<% @job.cities.each do |city| %>
<%= link_to city.name, city_jobs_path(converted_name: city.converted_name), class: 'location' %>
<% end %>
</div>
<div class="created-day">
<strong>Created at</strong>: <%= @job.created_at.strftime('%d/%m/%Y') %>
</div>
<div class="industry">
<strong>Industry:</strong> <%= @job.industries.map(&:name).join(', ') %>
</div>
</div>
<div class="col-6">
<div class="salary-detail">
<strong>Salary:</strong> <%= @job.salary %>
</div>
<% if @job.experience.present? %>
<div class="experience">
<strong>Experience:</strong> <%= @job.experience %>
</div>
<% end %>
<div class="level">
<strong>Level:</strong> <%= @job.level %>
</div>
<div class="expiration-date">
<strong>Expiration date:</strong> <%= @job.expiration_date %>
</div>
</div>
</div>
</div>
<div class="job-description">
<%= @job.description.html_safe %>
</div>
</div>
<div class="row under-descrip">
<div class="col-6">
<%= link_to '#' do %>
<div class="btn btn-info btn-lg apply-btn">
<strong>Apply Now</strong>
</div>
<% end %>
</div>
<div class="col-6">
<%= link_to '#' do %>
<div class="btn btn-danger btn-lg favorite-btn">
<strong>Favorite</strong>
</div>
<% end %>
</div>
</div>
</div>
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %>
</li>
<li class='page-item disabled'>
<%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %>
</li>
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %>
</li>
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %>
</li>
<% if page.current? %>
<li class="page-item active">
<%= content_tag :a, page, data: { remote: remote }, rel: page.rel, class: 'page-link' %>
</li>
<% else %>
<li class="page-item">
<%= link_to page, url, remote: remote, rel: page.rel, class: 'page-link' %>
</li>
<% end %>
<%= paginator.render do %>
<nav>
<ul class="pagination">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| %>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
</nav>
<% end %>
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, rel: 'prev', remote: remote, class: 'page-link' %>
</li>
<div class="col-4"> <div class="col-4">
<div class="row-table border border-dark rounded city-list"> <div class="row-table border border-dark rounded city-list">
<%= link_to '#' do %> <%= link_to city_jobs_path(converted_name: city.converted_name) do %>
<div class="city-name"><strong><%= city.name %></strong></div> <div class="city-name"><strong><%= city.name %></strong></div>
<div class="count-job"><%= city.jobs.count %></div> <div class="count-job"><%= city.jobs.count %></div>
<% end %> <% end %>
......
<div class="col-4"> <div class="col-4">
<div class="row-table border border-dark rounded industry-list"> <div class="row-table border border-dark rounded industry-list">
<%= link_to '#' do %> <%= link_to industry_jobs_path(converted_name: industry.converted_name) do %>
<div class="industry-name"><strong><%= industry.name %></strong></div> <div class="industry-name"><strong><%= industry.name %></strong></div>
<div class="count-job"><%= industry.jobs.count %></div> <div class="count-job"><%= industry.jobs.count %></div>
<% end %> <% end %>
......
<% if job.cities.present? %> <% if job.cities.present? %>
<div class="border border-dark rounded"> <div class="border border-dark rounded">
<div class="job-details"> <div class="job-details">
<div class="title"><strong><%= job.title %></strong></div> <div class="title">
<%= link_to job_detail_path(job.id) do %><strong>
<%= job.title %></strong>
<% end %>
</div>
<div><%= job.company_name %></div> <div><%= job.company_name %></div>
<div class="salary">Salary: <%= job.salary %></div> <div class="salary">Salary: <%= job.salary %></div>
<div> <div>
<% job.cities.each do |city| %> <%= job.cities.map(&:name).join(' | ') %>
<%= city.name %>
<% end %>
</div> </div>
<div class="row"> <div class="row">
<div class="col-10 introduction"> <div class="col-10 introduction">
<%= job_description(job.description) %><br> <%= strip_tags(job.format_desc) %><br>
<%= link_to 'Read more..', '#'%> <%= link_to 'Read more..', job_detail_path(job.id) %>
</div> </div>
</div> </div>
<button type="button" class="btn btn-primary" id="button-follow">♥ Follow</button> <button type="button" class="btn btn-primary" id="button-follow">♥ Follow</button>
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<div class="total-job">Having <%= @total_jobs %> jobs for you!</div> <div class="total-job">Having <%= @total_jobs %> jobs for you!</div>
</div> </div>
</div> </div>
<div class="container"> <div class="container">
<div class="search-bar"> <div class="search-bar">
<%= render 'layouts/search_bar' %> <%= render 'layouts/search_bar' %>
......
Rails.application.routes.draw do Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :jobs resources :jobs
get 'detail/:id', action: :show, controller: 'jobs' , as: :job_detail
get 'jobs/city/:converted_name', to: 'jobs#city_jobs', as: :city_jobs
get 'jobs/industry/:converted_name', to: 'jobs#industry_jobs', as: :industry_jobs
get 'jobs/company/:converted_name', to: 'jobs#company_jobs', as: :company_jobs
resources :top_pages resources :top_pages
resources :industries resources :industries
resources :cities resources :cities
......
...@@ -8,6 +8,8 @@ class CreateJobs < ActiveRecord::Migration[5.2] ...@@ -8,6 +8,8 @@ class CreateJobs < ActiveRecord::Migration[5.2]
t.string :experience t.string :experience
t.string :expiration_date t.string :expiration_date
t.bigint :company_id t.bigint :company_id
t.string :converted_name
t.timestamps t.timestamps
end end
end end
......
...@@ -3,6 +3,7 @@ class CreateCities < ActiveRecord::Migration[5.2] ...@@ -3,6 +3,7 @@ class CreateCities < ActiveRecord::Migration[5.2]
create_table :cities, :options => 'COLLATE=utf8_general_ci' do |t| create_table :cities, :options => 'COLLATE=utf8_general_ci' do |t|
t.string :name t.string :name
t.boolean :location t.boolean :location
t.string :converted_name
t.timestamps t.timestamps
end end
......
...@@ -2,6 +2,7 @@ class CreateIndustries < ActiveRecord::Migration[5.2] ...@@ -2,6 +2,7 @@ class CreateIndustries < ActiveRecord::Migration[5.2]
def change def change
create_table :industries, :options => 'COLLATE=utf8_general_ci' do |t| create_table :industries, :options => 'COLLATE=utf8_general_ci' do |t|
t.string :name t.string :name
t.string :converted_name
t.timestamps t.timestamps
end end
......
...@@ -4,6 +4,7 @@ class CreateCompanies < ActiveRecord::Migration[5.2] ...@@ -4,6 +4,7 @@ class CreateCompanies < ActiveRecord::Migration[5.2]
t.string :name t.string :name
t.text :address t.text :address
t.text :introduction t.text :introduction
t.string :converted_name
t.timestamps t.timestamps
end end
......
...@@ -10,11 +10,12 @@ ...@@ -10,11 +10,12 @@
# #
# 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_07_23_071239) do ActiveRecord::Schema.define(version: 2020_07_15_035356) do
create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "cities", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
t.boolean "location" t.boolean "location"
t.string "converted_name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
...@@ -30,6 +31,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do ...@@ -30,6 +31,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do
t.string "name" t.string "name"
t.text "address" t.text "address"
t.text "introduction" t.text "introduction"
t.string "converted_name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
...@@ -50,6 +52,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do ...@@ -50,6 +52,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do
create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t| create_table "industries", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name" t.string "name"
t.string "converted_name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
...@@ -79,6 +82,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do ...@@ -79,6 +82,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_071239) do
t.string "experience" t.string "experience"
t.string "expiration_date" t.string "expiration_date"
t.bigint "company_id" t.bigint "company_id"
t.string "converted_name"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
......
...@@ -3,6 +3,7 @@ class Crawler ...@@ -3,6 +3,7 @@ class Crawler
VIETNAM = 0 VIETNAM = 0
FOREIGN = 1 FOREIGN = 1
def initialize(logger, url) def initialize(logger, url)
@logger = logger @logger = logger
@url = url @url = url
......
...@@ -6,6 +6,7 @@ class CSVImporter ...@@ -6,6 +6,7 @@ class CSVImporter
NAME_DOMAIN = '192.168.1.156'.freeze NAME_DOMAIN = '192.168.1.156'.freeze
FTP_USERNAME = 'training'.freeze FTP_USERNAME = 'training'.freeze
FTP_PASSWORD = 'training'.freeze FTP_PASSWORD = 'training'.freeze
def initialize(logger) def initialize(logger)
@logger = logger @logger = logger
@extracting_directory = Rails.root.join('lib', 'csv') @extracting_directory = Rails.root.join('lib', 'csv')
...@@ -53,13 +54,18 @@ class CSVImporter ...@@ -53,13 +54,18 @@ class CSVImporter
description_job = "#{row["description"]} #{row["requirement"]}" description_job = "#{row["description"]} #{row["requirement"]}"
level = row["level"] level = row["level"]
salary = row["salary"] salary = row["salary"]
job = Job.find_or_create_by!(title: title_job, job = Job.find_or_create_by!(title: title_job,
description: description_job, description: description_job,
level: level, level: level,
salary: salary, salary: salary,
company_id: company_id) company_id: company_id)
job = Job.find_or_create_by!(title: title_job,
description: description_job,
level: level,
salary: salary,
company_id: company.id)
industry_name = row["category"] industry_name = row["category"]
industries_relationship = Industry.where(name: industry_name) industries_relationship = Industry.where(name: industry_name)
next if industries_relationship.blank? next if industries_relationship.blank?
...@@ -67,7 +73,7 @@ class CSVImporter ...@@ -67,7 +73,7 @@ class CSVImporter
industry_job_relationship = IndustryJob.where(job_id: job.id, industry_id: industries_relationship.ids) industry_job_relationship = IndustryJob.where(job_id: job.id, industry_id: industries_relationship.ids)
next if industry_job_relationship.present? next if industry_job_relationship.present?
job.industries << industries_relationship job.industries << industries_relationship if industry_job_relationship.blank?
location_data = row["work place"] location_data = row["work place"]
location = location_data.gsub('["', '').gsub('"]', '') location = location_data.gsub('["', '').gsub('"]', '')
...@@ -77,7 +83,7 @@ class CSVImporter ...@@ -77,7 +83,7 @@ class CSVImporter
location_job_relationship = CityJob.where(job_id: job.id ,city_id: location_relationship.ids) location_job_relationship = CityJob.where(job_id: job.id ,city_id: location_relationship.ids)
next if location_job_relationship.present? next if location_job_relationship.present?
job.cities << location_relationship job.cities << location_relationship if location_job_relationship.blank?
rescue StandardError => e rescue StandardError => e
@logger.error e.message @logger.error e.message
......
...@@ -9,9 +9,9 @@ namespace :import do ...@@ -9,9 +9,9 @@ namespace :import do
end end
desc 'Crontab' desc 'Crontab'
task auto: :environment do task auto: :environment do
crontab = JobParser.new(logger, url) parser = JobParser.new(logger, url)
csv_importer = CSVImporter.new(logger) csv_importer = CSVImporter.new(logger)
crontab.crawl_all parser.crawl_all
csv_importer.import csv_importer.import
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment