From ef373a9f5b8c70609aa3f34c6411fcc05e7e8a2a Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 22 Apr 2025 14:36:43 +0330 Subject: [PATCH] add confirm and reject api --- .../Dashboard/SafetyAndPrivacyController.php | 47 ++++++++++++++++--- app/Models/SafetyAndPrivacy.php | 3 +- ...add_column_to_safety_and_privacy_table.php | 3 +- routes/v3.php | 2 +- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php index ce39c5e3..d5d6aa2a 100644 --- a/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php +++ b/app/Http/Controllers/V3/Dashboard/SafetyAndPrivacyController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\V3\Dashboard; use App\Enums\AxisTypes; +use App\Enums\SafetyAndPrivacyStatus; use App\Exports\V3\SafetyAndPrivacy\CartableReport; use App\Facades\DataTable\DataTableFacade; use App\Facades\File\FileFacade; @@ -18,10 +19,8 @@ use App\Services\Cartables\SafetyAndPrivacyTableService; use App\Services\NominatimService; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\Validator; use Maatwebsite\Excel\Facades\Excel; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Throwable; @@ -33,9 +32,9 @@ class SafetyAndPrivacyController extends Controller /** * @throws Throwable */ - public function index(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse + public function operatorIndex(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse { - return response()->json($safetyAndPrivacyTableService->datatable($request)); + return response()->json($safetyAndPrivacyTableService->operatorDatatable($request)); } /** @@ -44,7 +43,7 @@ class SafetyAndPrivacyController extends Controller public function excelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse { $name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx'; - $data = $safetyAndPrivacyTableService->datatable($request); + $data = $safetyAndPrivacyTableService->operatorDatatable($request); return Excel::download(new CartableReport($data['data']), $name); } @@ -78,7 +77,8 @@ class SafetyAndPrivacyController extends Controller 'axis_type_id' => $request->axis_type_id, 'axis_type_name' => AxisTypes::name($request->axis_type_id), 'step' => 1, - 'step_fa' => 'گام اول (شناسایی)' + 'step_fa' => 'گام اول (شناسایی)', + 'is_finished' => false ]); $safety_and_privacy->recognize_picture = $request->has('recognize_picture') ? @@ -197,4 +197,39 @@ class SafetyAndPrivacyController extends Controller allowedSelects: ['id', 'lat', 'lon', 'step'] )); } + + public function confirm(Request $request, SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + $safetyAndPrivacy->update([ + 'status' => SafetyAndPrivacyStatus::CONFIRM->value, + 'supervisor_description' => $request->supervisor_description + ]); + + return $this->successResponse(); + } + + public function reject(Request $request, SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + $safetyAndPrivacy->update([ + 'status' => SafetyAndPrivacyStatus::REJECT->value, + 'supervisor_description' => $request->supervisor_description + ]); + + return $this->successResponse(); + } + + public function finish(Request $request, SafetyAndPrivacy $safetyAndPrivacy): JsonResponse + { + $safetyAndPrivacy->update([ + 'is_finished' => $request->is_finished, + 'final_description' => $request->final_description + ]); + + return $this->successResponse(); + } + + public function supervisorIndex(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse + { + return response()->json($safetyAndPrivacyTableService->supervisorDataTable($request)); + } } diff --git a/app/Models/SafetyAndPrivacy.php b/app/Models/SafetyAndPrivacy.php index 77a64138..d1c6cc3f 100644 --- a/app/Models/SafetyAndPrivacy.php +++ b/app/Models/SafetyAndPrivacy.php @@ -39,7 +39,8 @@ class SafetyAndPrivacy extends Model 'action_date', 'status', 'final_description', - 'is_finished' + 'is_finished', + 'supervisor_description' ]; public $table = "safety_and_privacy"; diff --git a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php index 1a63dd23..49d997a7 100644 --- a/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php +++ b/database/migrations/2025_04_22_100327_add_column_to_safety_and_privacy_table.php @@ -14,6 +14,7 @@ return new class extends Migration Schema::table('safety_and_privacy', function (Blueprint $table) { $table->boolean('is_finished')->nullable(); $table->integer('status')->nullable(); + $table->string('supervisor_description')->nullable(); $table->string('final_description')->nullable(); }); } @@ -24,7 +25,7 @@ return new class extends Migration public function down(): void { Schema::table('safety_and_privacy', function (Blueprint $table) { - $table->dropColumn(['status', 'final_description', 'is_finished']); + $table->dropColumn(['status', 'final_description', 'is_finished', 'supervisor_description']); }); } }; diff --git a/routes/v3.php b/routes/v3.php index 5d58b5b5..d0924334 100644 --- a/routes/v3.php +++ b/routes/v3.php @@ -337,7 +337,7 @@ Route::prefix('safety_and_privacy') ->name('SafetyAndPrivacy.') ->controller(SafetyAndPrivacyController::class) ->group(function () { - Route::get('/', 'index')->name('index')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri'); + Route::get('/', 'operatorIndex')->name('operatorIndex')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri'); Route::get('/excel_report', 'excelReport')->name('excelReport')->middleware('permission:show-safety-and-privacy-operator-cartable|show-safety-and-privacy-operator-cartable-province|show-safety-and-privacy-operator-cartable-edarate-shahri'); Route::post('/first_step_store', 'firstStepStore')->name('firstStepStore') ->middleware(['validate-store-access', 'permission:add-safety-and-privacy']);