From 1e352e01c3381c0bb742fe554d6e8ef172289fe2 Mon Sep 17 00:00:00 2001 From: joddyabott Date: Sat, 2 Aug 2025 15:59:24 +0330 Subject: [PATCH] create controller and rote and form request for harim office --- app/Enums/HarimAction.php | 25 ++++++ .../Dashboard/Harim/HarimOfficeController.php | 80 +++++++++++++++++++ ...oller.php => ProvinceOfficeController.php} | 15 +++- .../Dashboard/Harim/HarimOffice/NoRequest.php | 29 +++++++ .../Harim/HarimOffice/YesRequest.php | 30 +++++++ .../{ => ProvinceOffice}/FeedBackRequest.php | 2 +- database/seeders/HarimActionSeeder.php | 8 +- routes/v3.php | 17 +++- 8 files changed, 195 insertions(+), 11 deletions(-) create mode 100644 app/Enums/HarimAction.php create mode 100644 app/Http/Controllers/V3/Dashboard/Harim/HarimOfficeController.php rename app/Http/Controllers/V3/Dashboard/Harim/{ProvinceOfficesController.php => ProvinceOfficeController.php} (78%) create mode 100644 app/Http/Requests/V3/Dashboard/Harim/HarimOffice/NoRequest.php create mode 100644 app/Http/Requests/V3/Dashboard/Harim/HarimOffice/YesRequest.php rename app/Http/Requests/V3/Dashboard/Harim/{ => ProvinceOffice}/FeedBackRequest.php (92%) diff --git a/app/Enums/HarimAction.php b/app/Enums/HarimAction.php new file mode 100644 index 00000000..3bf8f850 --- /dev/null +++ b/app/Enums/HarimAction.php @@ -0,0 +1,25 @@ + "بازخورد", + 2 => "بله", + 3 => "خیر", + 4 => "تائید کردن", + 5 => "رد درخواست", + ]; + + return $mapArray[$state]; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Harim/HarimOfficeController.php b/app/Http/Controllers/V3/Dashboard/Harim/HarimOfficeController.php new file mode 100644 index 00000000..609ec75c --- /dev/null +++ b/app/Http/Controllers/V3/Dashboard/Harim/HarimOfficeController.php @@ -0,0 +1,80 @@ +where('edareh_shahri_id', '=', auth()->user()->edarate_shahri_id); + $data = DataTableFacade::run( + $query, + $request, + allowedFilters: ['*'], + allowedSortings: ['*'], + ); + return response()->json($data); + } + public function yes(YesRequest $request, Harim $harim ): JsonResponse + { + DB::transaction(function () use ($request,$harim) { + $action = HarimAction::YES->value; + $harim->histories()->create([ + 'user_id' => auth()->user()->id, + 'previous_state_id' => $harim->state_id, + 'previous_state_name' => $harim->state_name, + 'expert_description' => $request->expert_description, + 'action_id' => $action, + 'action_name' => HarimAction::name($action), + ]); + + $state = HarimStates::Baresi_Imeni_Rah_Tavasot_Moaven->value; + + $harim ->update([ + 'state_id' => $state, + 'state_name' => HarimStates::name($state), + ]); + }); + return $this->successResponse(); + } + public function no(NoRequest $request, Harim $harim ): JsonResponse + { + DB::transaction(function () use ($request,$harim) { + $action = HarimAction::NO->value; + $harim->histories()->create([ + 'user_id' => auth()->user()->id, + 'previous_state_id' => $harim->state_id, + 'previous_state_name' => $harim->state_name, + 'expert_description' => $request->expert_description, + 'action_id' => $action, + 'action_name' => HarimAction::name($action), + ]); + + $state = HarimStates::Baresi_Imeni_Rah_Tavasot_Moaven->value; + + $harim ->update([ + 'state_id' => $state, + 'state_name' => HarimStates::name($state), + ]); + }); + return $this->successResponse(); + } + public function show(Harim $harim): JsonResponse + { + return $this->successResponse($harim); + } +} diff --git a/app/Http/Controllers/V3/Dashboard/Harim/ProvinceOfficesController.php b/app/Http/Controllers/V3/Dashboard/Harim/ProvinceOfficeController.php similarity index 78% rename from app/Http/Controllers/V3/Dashboard/Harim/ProvinceOfficesController.php rename to app/Http/Controllers/V3/Dashboard/Harim/ProvinceOfficeController.php index 521943ec..1faf9abe 100644 --- a/app/Http/Controllers/V3/Dashboard/Harim/ProvinceOfficesController.php +++ b/app/Http/Controllers/V3/Dashboard/Harim/ProvinceOfficeController.php @@ -2,17 +2,18 @@ namespace App\Http\Controllers\V3\Dashboard\Harim; +use App\Enums\HarimAction; use App\Enums\HarimStates; use App\Facades\DataTable\DataTableFacade; use App\Http\Controllers\Controller; -use App\Http\Requests\V3\Dashboard\Harim\FeedBackRequest; +use App\Http\Requests\V3\Dashboard\Harim\ProvinceOffice\FeedBackRequest; use App\Http\Traits\ApiResponse; use App\Models\Harim; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -class ProvinceOfficesController extends Controller +class ProvinceOfficeController extends Controller { use ApiResponse; @@ -36,7 +37,9 @@ class ProvinceOfficesController extends Controller 'user_id' => auth()->user()->id, 'previous_state_id' => $harim->state_id, 'previous_state_name' => $harim->state_name, - 'expert_description' => $request->expert_description + 'expert_description' => $request->expert_description, + 'action_id' => HarimAction::FEEDBACK->value, + 'action_name' => HarimAction::FEEDBACK->name, ]); $state = HarimStates::Baresi_Imeni_Rah_Tavasot_Daftar_Harim->value; @@ -48,4 +51,10 @@ class ProvinceOfficesController extends Controller }); return $this->successResponse(); } + + public function show(Harim $harim): JsonResponse + { + return $this->successResponse($harim); + + } } diff --git a/app/Http/Requests/V3/Dashboard/Harim/HarimOffice/NoRequest.php b/app/Http/Requests/V3/Dashboard/Harim/HarimOffice/NoRequest.php new file mode 100644 index 00000000..9e35c3b8 --- /dev/null +++ b/app/Http/Requests/V3/Dashboard/Harim/HarimOffice/NoRequest.php @@ -0,0 +1,29 @@ +harim->edare_shahri_id == auth()->user()->edarate_shahri_id && + $this->harim->state_id == HarimStates::Baresi_Imeni_Rah_Tavasot_Daftar_Harim->value; } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + 'expert_description' => 'required|string', + ]; + } +} diff --git a/app/Http/Requests/V3/Dashboard/Harim/HarimOffice/YesRequest.php b/app/Http/Requests/V3/Dashboard/Harim/HarimOffice/YesRequest.php new file mode 100644 index 00000000..a61edd56 --- /dev/null +++ b/app/Http/Requests/V3/Dashboard/Harim/HarimOffice/YesRequest.php @@ -0,0 +1,30 @@ +harim->edare_shahri_id == auth()->user()->edarate_shahri_id && + $this->harim->state_id == HarimStates::Baresi_Imeni_Rah_Tavasot_Daftar_Harim->value; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array|string> + */ + public function rules(): array + { + return [ + 'expert_description' => 'required|string', + ]; + } +} diff --git a/app/Http/Requests/V3/Dashboard/Harim/FeedBackRequest.php b/app/Http/Requests/V3/Dashboard/Harim/ProvinceOffice/FeedBackRequest.php similarity index 92% rename from app/Http/Requests/V3/Dashboard/Harim/FeedBackRequest.php rename to app/Http/Requests/V3/Dashboard/Harim/ProvinceOffice/FeedBackRequest.php index 021ff3f0..d9260edf 100644 --- a/app/Http/Requests/V3/Dashboard/Harim/FeedBackRequest.php +++ b/app/Http/Requests/V3/Dashboard/Harim/ProvinceOffice/FeedBackRequest.php @@ -1,6 +1,6 @@ insert([ ['id' => 1, 'name' => 'feedback', 'created_at' => now(), 'updated_at' => now(),], - ['id' => 1, 'name' => 'yes', 'created_at' => now(), 'updated_at' => now(),], - ['id' => 2, 'name' => 'no', 'created_at' => now(), 'updated_at' => now(),], - ['id' => 3, 'name' => 'confirm', 'created_at' => now(), 'updated_at' => now(),], - ['id' => 4, 'name' => 'refer', 'created_at' => now(), 'updated_at' => now(),], + ['id' => 2, 'name' => 'yes', 'created_at' => now(), 'updated_at' => now(),], + ['id' => 3, 'name' => 'no', 'created_at' => now(), 'updated_at' => now(),], + ['id' => 4, 'name' => 'confirm', 'created_at' => now(), 'updated_at' => now(),], + ['id' => 5, 'name' => 'reject', 'created_at' => now(), 'updated_at' => now(),], ]); } } diff --git a/routes/v3.php b/routes/v3.php index b27bb37f..47e6f1fd 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -8,7 +8,8 @@ use App\Http\Controllers\V3\Dashboard\Accident\AccidentReceiptReportController; use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshController; use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshSampleController; use App\Http\Controllers\V3\Dashboard\Azmayesh\AzmayeshTypeController; -use App\Http\Controllers\V3\Dashboard\Harim\ProvinceOfficesController; +use App\Http\Controllers\V3\Dashboard\Harim\HarimOfficeController; +use App\Http\Controllers\V3\Dashboard\Harim\ProvinceOfficeController; use App\Http\Controllers\V3\Dashboard\ItemsManagementController; use App\Http\Controllers\V3\Dashboard\Mission\ControlUnitController; use App\Http\Controllers\V3\Dashboard\Mission\DetailController; @@ -512,10 +513,20 @@ Route::prefix('harim') ->group(function () { Route::prefix('province_office') ->name('province_office.') - ->controller(ProvinceOfficesController::class) + ->controller(ProvinceOfficeController::class) ->group(function () { Route::get('/', 'index')->name('index'); - Route::post('/feedback', 'feedback')->name('feedback'); + Route::post('/feedback/{harim}', 'feedback')->name('feedback'); + Route::get('/{harim}', 'show')->name('show'); + }); + Route::prefix('harim_office') + ->name('harim_office.') + ->controller(HarimOfficeController::class) + ->group(function () { + Route::get('/', 'index')->name('index'); + Route::post('/yes/{harim}', 'yes')->name('yes'); + Route::post('/no/{harim}', 'no')->name('no'); + Route::get('/{harim}', 'show')->name('show'); }); });