Skip to content

Commit

Permalink
Fix Objectives
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtin590 committed Oct 15, 2024
1 parent cf6002f commit 86a736e
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 11 deletions.
109 changes: 109 additions & 0 deletions app/Http/Controllers/Api/Admin/ExperienceLevelsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace App\Http\Controllers\Api\Admin;

use App\Http\Controllers\Controller;
use App\Models\ExperienceLevel; // Đảm bảo rằng bạn đã import model này
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class ExperienceLevelsController extends Controller
{
// Hiển thị danh sách các cấp độ kinh nghiệm
public function index()
{
$experienceLevels = ExperienceLevel::all();
return response()->json([
'success' => true,
'message' => "Lấy danh sách cấp độ kinh nghiệm thành công",
'data' => $experienceLevels,
'status_code' => 200
]);
}

// Tạo cấp độ kinh nghiệm mới
public function store(Request $request)
{
$data = $request->only('name'); // Lấy dữ liệu từ request

$validator = Validator::make($data, [
'name' => 'required|string|min:3|max:50',
], [
'name.required' => 'Trường tên là bắt buộc.',
'name.min' => 'Tên cấp độ kinh nghiệm phải có ít nhất :min ký tự.',
'name.max' => 'Tên cấp độ kinh nghiệm không được vượt quá :max ký tự.',
]);

if ($validator->fails()) {
return response()->json([
'success' => false,
'message' => 'Lỗi xác thực',
'errors' => $validator->errors(),
'status_code' => 400
], 400);
}

$experienceLevel = ExperienceLevel::create($validator->validated());

return response()->json([
'success' => true,
'message' => "Tạo cấp độ kinh nghiệm thành công!",
'data' => $experienceLevel,
'status_code' => 200
]);
}

// Hiển thị chi tiết một cấp độ kinh nghiệm
public function show(ExperienceLevel $experienceLevel)
{
return response()->json([
'success' => true,
'message' => 'Lấy thông tin cấp độ kinh nghiệm thành công',
'data' => $experienceLevel,
'status_code' => 200
]);
}

// Cập nhật thông tin cấp độ kinh nghiệm
public function update(Request $request, ExperienceLevel $experienceLevel)
{
$data = $request->only('name');

$validator = Validator::make($data, [
'name' => 'required|string|min:3|max:50',
], [
'name.required' => 'Trường tên là bắt buộc.',
'name.min' => 'Tên cấp độ kinh nghiệm phải có ít nhất :min ký tự.',
'name.max' => 'Tên cấp độ kinh nghiệm không được vượt quá :max ký tự.',
]);

if ($validator->fails()) {
return response()->json([
'success' => false,
'message' => 'Lỗi xác thực',
'errors' => $validator->errors(),
'status_code' => 400
], 400);
}

$experienceLevel->update($validator->validated());

return response()->json([
'success' => true,
'message' => 'Cập nhật cấp độ kinh nghiệm thành công',
'data' => $experienceLevel,
'status_code' => 200
]);
}

// Xóa cấp độ kinh nghiệm
public function destroy(ExperienceLevel $experienceLevel)
{
$experienceLevel->delete();
return response()->json([
'success' => true,
'message' => 'Xóa cấp độ kinh nghiệm thành công',
'status_code' => 200
]);
}
}
18 changes: 9 additions & 9 deletions app/Http/Controllers/Api/Resume/ObjectivesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function index()
'desired_level_id' => $objective->desiredLevel->name ?? null,
'profession_id' => $objective->profession->name ?? null,
'employment_type_id' => $objective->employmentType->name ?? null,
'experience_years' => $objective->experience_years,
'experience_level_id' => $objective->experienceLevel->name ?? null,
'work_address' => $objective->work_address,
'education_level_id' => $objective->educationLevel->name ?? null,
'salary_from' => $objective->salary_from,
Expand Down Expand Up @@ -103,7 +103,7 @@ public function store(Request $request)
'desired_level_id' => 'required|integer',
'profession_id' => 'required|integer',
'employment_type_id' => 'required|integer',
'experience_years' => 'required|integer|min:0',
'experience_level_id' => 'required|integer',
'work_address' => 'required|string|max:255',
'education_level_id' => 'required|integer',
'salary_from' => 'required|integer|min:0',
Expand All @@ -118,7 +118,7 @@ public function store(Request $request)
'desired_level_id.required' => 'Vui lòng chọn cấp bậc mong muốn.',
'profession_id.required' => 'Vui lòng chọn nghề nghiệp.',
'employment_type_id.required' => 'Vui lòng chọn hình thức làm việc.',
'experience_years.required' => 'Vui lòng nhập số năm kinh nghiệm.',
'experience_level_id.required' => 'Vui lòng nhập số năm kinh nghiệm.',
'work_address.required' => 'Vui lòng nhập địa chỉ làm việc.',
'education_level_id.required' => 'Vui lòng chọn trình độ học vấn.',
'salary_from.required' => 'Vui lòng nhập mức lương bắt đầu.',
Expand Down Expand Up @@ -162,13 +162,13 @@ public function store(Request $request)
'desired_level_id' => $objective->desiredLevel->name ?? null,
'profession_id' => $objective->profession->name ?? null,
'employment_type_id' => $objective->employmentType->name ?? null,
'experience_years' => $objective->experience_years,
'experience_level_id' => $objective->experienceLevel->name ?? null,
'work_address' => $objective->work_address,
'education_level_id' => $objective->educationLevel->name ?? null,
'salary_from' => $objective->salary_from,
'salary_to' => $objective->salary_to,
'file' => asset('cvs/' . $objective->file),
'status' => $objective->status,
'status' => ($objective->status == 3) ? 'hoạt động' : (($objective->status == 4) ? 'không hoạt động' : 'không xác định'),
'country' => $objective->country ? $objective->country->name : null, // Tên quốc gia
'city' => $objective->city ? $objective->city->name : null, // Tên thành phố
'district' => $objective->district ? $objective->district->name : null, // Tên quận/huyện
Expand Down Expand Up @@ -203,7 +203,7 @@ public function update(Request $request, $id)
'desired_level_id' => '|integer',
'profession_id' => '|integer',
'employment_type_id' => '|integer',
'experience_years' => '|integer|min:0',
'experience_level_id' => '|integer',
'work_address' => '|string|max:255',
'education_level_id' => '|integer',
'salary_from' => '|integer|min:0',
Expand Down Expand Up @@ -258,7 +258,7 @@ public function update(Request $request, $id)
'desired_level_id' => $objective->desiredLevel->name ?? null,
'profession_id' => $objective->profession->name ?? null,
'employment_type_id' => $objective->employmentType->name ?? null,
'experience_years' => $objective->experience_years,
'experience_level_id' => $objective->experienceLevel->name ?? null,
'work_address' => $objective->work_address,
'education_level_id' => $objective->educationLevel->name ?? null,
'salary_from' => $objective->salary_from,
Expand Down Expand Up @@ -437,7 +437,7 @@ public function uploadFile(Request $request, $id)
'desired_level_id' => $objective->desiredLevel->name ?? null,
'profession_id' => $objective->profession->name ?? null,
'employment_type_id' => $objective->employmentType->name ?? null,
'experience_years' => $objective->experience_years,
'experience_level_id' => $objective->experienceLevel->name ?? null,
'work_address' => $objective->work_address,
'education_level_id' => $objective->educationLevel->name ?? null,
'salary_from' => $objective->salary_from,
Expand Down Expand Up @@ -482,7 +482,7 @@ public function show (Objective $objective): \Illuminate\Http\JsonResponse
'desired_level_id' => $objective->desiredLevel->name ?? null,
'profession_id' => $objective->profession->name ?? null,
'employment_type_id' => $objective->employmentType->name ?? null,
'experience_years' => $objective->experience_years,
'experience_level_id' => $objective->experienceLevel->name ?? null,
'work_address' => $objective->work_address,
'education_level_id' => $objective->educationLevel->name ?? null,
'salary_from' => $objective->salary_from,
Expand Down
16 changes: 16 additions & 0 deletions app/Models/ExperienceLevel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ExperienceLevel extends Model
{
use HasFactory;
protected $table = 'experience_levels';
protected $primaryKey = 'id';
protected $guarded = [];


}
4 changes: 4 additions & 0 deletions app/Models/Objective.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function desiredLevel()
return $this->belongsTo(DesiredLevel::class, 'desired_level_id');
}

public function experienceLevel()
{
return $this->belongsTo(ExperienceLevel::class, 'experience_level_id');
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('experience_levels', function (Blueprint $table) {
$table->id();
$table->string("name");
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('experience_levels');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function up(): void

$table->unsignedBigInteger('profession_id')->nullable(); // Khóa ngoại tới bảng professions
$table->unsignedBigInteger('employment_type_id')->nullable(); // Khóa ngoại tới bảng employment_types
$table->integer('experience_years')->nullable(); // Kinh nghiệm (năm)
$table->unsignedBigInteger('experience_level_id')->nullable();
$table->string('work_address')->nullable(); // Địa chỉ làm việc

$table->integer('salary_from')->nullable();
Expand All @@ -38,6 +38,8 @@ public function up(): void
$table->foreign('education_level_id')->references('id')->on('education_levels')->onDelete('set null');
$table->foreign('profession_id')->references('id')->on('professions')->onDelete('set null');
$table->foreign('employment_type_id')->references('id')->on('employment_types')->onDelete('set null');
$table->foreign('experience_level_id')->references('id')->on('experience_levels')->onDelete('set null');

$table->foreign('profiles_id')->references('id')->on('profiles')->onDelete('cascade');

$table->timestamps();
Expand Down
3 changes: 2 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function run(): void
ProfessionsTableSeeder::class,
EmploymentTypeSeeder::class,
EducationLevelsTableSeeder::class,
DesiredLevelsTableSeeder::class
DesiredLevelsTableSeeder::class,
ExperienceLevelsSeeder::class
]);
}
}
28 changes: 28 additions & 0 deletions database/seeders/ExperienceLevelsSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class ExperienceLevelsSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run()
{
// Dữ liệu cho bảng experience_levels
$experienceLevels = [
['name' => '1-2 năm'],
['name' => '3-5 năm'],
['name' => '6-8 năm'],
['name' => '9-11 năm'],
['name' => '12+ năm'],
];

// Chèn dữ liệu vào bảng
DB::table('experience_levels')->insert($experienceLevels);
}
}
4 changes: 4 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DistrictsController,
EducationLevelsController,
EmploymentTypesController,
ExperienceLevelsController,
JobtypesControllerController,
CompaniesController as AdminCompaniesController,
LanguagesController,
Expand Down Expand Up @@ -171,6 +172,8 @@

Route::middleware(CheckUserRole::class)->group(function () {
Route::resource('jobs', JobsController::class);
Route::get('/jobs/suggest-jobs', [JobsController::class, 'searchForEmployer']);

Route::post('/process_application/{jobId}/{userId}', [JobApplicationController::class, 'processApplication']);
Route::get('/applications', [JobApplicationController::class, 'index']);
Route::post('/{id}/toggle', [JobApplicationController::class, 'toggle']);
Expand Down Expand Up @@ -221,6 +224,7 @@

Route::resource('/desired-levels', DesiredLevelsController::class);

Route::resource('/experience-levels', ExperienceLevelsController::class);

});
});

0 comments on commit 86a736e

Please sign in to comment.