Commit db3ba1fb by Trịnh Hoàng Phúc

Fix review 12/05/2020

parent 079c82d0
Pipeline #612 failed with stages
in 0 seconds
class City < ApplicationRecord
validates :title, presence: true
validates :title, presence: true, uniqueness: true
has_and_belongs_to_many :jobs
end
class Industry < ApplicationRecord
validates :title, presence: true
validates :title, presence: true, uniqueness: true
has_and_belongs_to_many :jobs
end
class Job < ApplicationRecord
validates :title, presence: true
scope :by_cities, -> (city_id) {includes(:cities).where("cities.id = ?", city_id).references(:cities)}
scope :by_industries, -> (industry_id) {includes(:industries).where("industries.id = ?", industry_id).references(:industries)}
scope :by_companies, -> (company_id) {where("company_id = #{company_id}")}
EXPORT_CSV_ATTRIBUTES = %w(title updated_date_job level years_of_experience salary expiration_date).freeze
belongs_to :company
has_many :applies
......@@ -12,9 +16,15 @@ class Job < ApplicationRecord
has_and_belongs_to_many :industries
has_and_belongs_to_many :cities
scope :by_cities, -> (city_id) {includes(:cities).where("cities.id = ?", city_id).references(:cities)}
scope :by_industries, -> (industry_id) {includes(:industries).where("industries.id = ?", industry_id).references(:industries)}
scope :by_companies, -> (company_id) {where("company_id = #{company_id}")}
validate :updated_date_job_cannot_be_greater_than_expiration_date, on: :create
validates :title, length: { minimum: 6 }
validates :title, :updated_date_job, :level, :expiration_date, :salary, :min_salary, :max_salary, presence: true, on: :create
validates :min_salary, :max_salary, numericality: { only_integer: true }
EXPORT_CSV_ATTRIBUTES = %w(title updated_date_job level years_of_experience salary expiration_date).freeze
def updated_date_job_cannot_be_greater_than_expiration_date
if DateTime.parse(updated_date_job).to_i > DateTime.parse(expiration_date).to_i
errors.add(:updated_date_job, "can't be greater than expiration date")
end
end
end
class CityService
def import cities
City.import cities
end
def check_exist_or_create_city city_title
cities = City.where("title LIKE ?", city_title)
if cities.length == 0
city = City.create(title: city_title)
else
city = cities[0]
end
return city
end
end
\ No newline at end of file
class CompanyService
def check_exist_or_create_company company_attributes
find_company = Company.find_or_create_by(company_attributes)
return find_company.id
end
end
\ No newline at end of file
class CrawlerService
def self.convert_salary salary
if salary == "Cạnh tranh"
[0, 999999999]
elsif salary.include? "Dưới"
max_salary = (salary.gsub("Dưới ","").gsub(" Tr VND","").gsub(",",".").to_f*1000000).to_i
[0, max_salary]
elsif salary.include? "Trên"
min_salary = (salary.gsub("Trên ","").gsub(" Tr VND","").gsub(",",".").to_f*1000000).to_i
max_salary = 999999999
[min_salary, max_salary]
else
range_salary = salary.split("-")
min_salary = (range_salary[0].gsub("$ ","").gsub(" Tr ","").to_f*1000000).to_i
max_salary = (range_salary[1].gsub(" Tr VND","").gsub(" ","").to_f*1000000).to_i
[min_salary, max_salary]
end
end
end
\ No newline at end of file
class IndustryService
def import industries
Industry.import industries
end
def check_exist_or_create_industry industry_title
industries = Industry.where("title LIKE ?", industry_title)
if industries.length == 0
industry = Industry.create(title: industry_title)
else
industry = industries[0]
end
return industry
end
end
\ No newline at end of file
class JobService
def check_exist_or_create_job job_attributes
def self.check_exist_or_create_job job_attributes
job = Job.find_or_create_by(job_attributes)
return job
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