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

Fix review 22/05/2020

parent f8287fd5
Pipeline #634 canceled with stages
in 0 seconds
module CookiesHistory
def set_job_histories
if cookies[:job_ids_history].nil?
cookies[:job_ids_history] = { value: @job.id, expires: Time.now + 3600 }
else
arr_job_ids = cookies[:job_ids_history].split(",")
arr_job_ids = cookies[:job_ids_history].to_s.split(",")
unless arr_job_ids.include? (@job.id.to_s)
arr_job_ids.shift if arr_job_ids.count == 10
arr_job_ids << @job.id.to_s
end
cookies[:job_ids_history] = { value: arr_job_ids.join(","), expires: Time.now + 3600 }
end
end
end
\ No newline at end of file
class HistoryController < ApplicationController
def index
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
arr_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
\ No newline at end of file
......@@ -23,7 +23,12 @@ class JobsController < ApplicationController
if user_signed_in?
@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)
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
set_job_histories
end
......
class History < ApplicationRecord
belongs_to :user
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
......@@ -34,6 +34,6 @@ class Job < ApplicationRecord
end
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
......@@ -3,6 +3,8 @@ class CreateHistories < ActiveRecord::Migration[6.0]
create_table :histories do |t|
t.references :user, null: false, foreign_key: true
t.references :job, null: false, foreign_key: true
t.timestamps
end
end
end
......@@ -10,9 +10,9 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_05_18_023337) do
ActiveRecord::Schema.define(version: 2020_05_19_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 "encrypted_password", default: "", null: false
t.string "reset_password_token"
......@@ -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
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 "job_id", null: false
t.datetime "created_at", precision: 6, null: false
......@@ -33,21 +33,21 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t.index ["user_id"], name: "index_applies_on_user_id"
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.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.boolean "foreign", default: false
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 "job_id", null: false
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"
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 "address"
t.string "logo"
......@@ -56,7 +56,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t.datetime "updated_at", precision: 6, null: false
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 "job_id", null: false
t.datetime "created_at", precision: 6, null: false
......@@ -65,20 +65,29 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t.index ["user_id"], name: "index_favorites_on_user_id"
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.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
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 "job_id", null: false
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"
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 "updated_date_job"
t.string "level"
......@@ -97,7 +106,7 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t.index ["company_id"], name: "index_jobs_on_company_id"
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 "encrypted_password", default: "", null: false
t.string "reset_password_token"
......@@ -110,7 +119,6 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "full_name"
t.string "image"
t.string "cv"
t.string "provider"
t.string "uid"
......@@ -123,4 +131,6 @@ ActiveRecord::Schema.define(version: 2020_05_18_023337) do
add_foreign_key "applies", "users"
add_foreign_key "favorites", "jobs"
add_foreign_key "favorites", "users"
add_foreign_key "histories", "jobs"
add_foreign_key "histories", "users"
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