From 68109744f059a6a1dd1ec229e0947e96a7b4b532 Mon Sep 17 00:00:00 2001 From: amirghasempoor Date: Tue, 31 Dec 2024 16:40:21 +0330 Subject: [PATCH] add new columns to road patrol --- .../V3/RoadPatrolProjectController.php | 5 ++- .../V3/RoadPatrolProject/StoreRequest.php | 11 +++-- ...33123_add_column_to_road_patrols_table.php | 40 +++++++++++++++++++ 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2024_12_31_133123_add_column_to_road_patrols_table.php diff --git a/app/Http/Controllers/V3/RoadPatrolProjectController.php b/app/Http/Controllers/V3/RoadPatrolProjectController.php index a66cf00a..4e2fbded 100644 --- a/app/Http/Controllers/V3/RoadPatrolProjectController.php +++ b/app/Http/Controllers/V3/RoadPatrolProjectController.php @@ -145,7 +145,7 @@ class RoadPatrolProjectController extends Controller return response()->json($data); } - public function store(StoreRequest $request, NominatimService $nominatimService) + public function store(StoreRequest $request, NominatimService $nominatimService): JsonResponse { $user = auth()->user(); @@ -195,6 +195,9 @@ class RoadPatrolProjectController extends Controller 'start_time' => $request->start_time, 'end_time' => $request->end_time, 'description' => $request->description ?? null, + 'fuel_consumption' => $request->fuel_consumption, + 'vehicle_runtime' => $request->vehicle_runtime, + 'stop_points' => json_encode($request->stop_points), ]); $road_patrol->rahdaran()->attach($request->road_patrol_rahdaran_id); diff --git a/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php b/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php index 8a71cb1b..353a814c 100644 --- a/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php +++ b/app/Http/Requests/V3/RoadPatrolProject/StoreRequest.php @@ -30,6 +30,13 @@ class StoreRequest extends FormRequest 'officer_phone_number' => 'required|digits:11', 'start_time' => 'required|date_format:Y-m-d H:i', 'end_time' => 'required|date_format:Y-m-d H:i|after:start_time', + 'fuel_consumption' => 'required|integer', + 'vehicle_runtime' => 'required|integer', + 'stop_points' => 'required|array', + 'road_patrol_machines_id' => 'required|array', + 'road_patrol_machines_id.*' => 'required|exists:cmms_machines,id', + 'road_patrol_rahdaran_id' => 'required|array', + 'road_patrol_rahdaran_id.*' => 'required|exists:rahdaran,id', 'observed_items' => 'array', 'observed_items.*.item_id' => 'required|integer', @@ -47,10 +54,6 @@ class StoreRequest extends FormRequest 'observed_items.*.priority' => 'integer|in:1,2,3|required_if:observed_items.*.instant_action,0', 'observed_items.*.priority_fa' => 'string|required_if:observed_items.*.instant_action,0', 'description' => 'string|required_with:observed_items', - 'road_patrol_machines_id' => 'required|array', - 'road_patrol_machines_id.*' => 'required|exists:cmms_machines,id', - 'road_patrol_rahdaran_id' => 'required|array', - 'road_patrol_rahdaran_id.*' => 'required|exists:rahdaran,id', 'observed_items.*.road_item_machines_id' => 'required_if:observed_items.*.instant_action,1|array', 'observed_items.*.road_item_machines_id.*' => 'required_if:observed_items.*.instant_action,1|exists:cmms_machines,id', diff --git a/database/migrations/2024_12_31_133123_add_column_to_road_patrols_table.php b/database/migrations/2024_12_31_133123_add_column_to_road_patrols_table.php new file mode 100644 index 00000000..47cbc9dd --- /dev/null +++ b/database/migrations/2024_12_31_133123_add_column_to_road_patrols_table.php @@ -0,0 +1,40 @@ +decimal('start_lat', 12, 10)->nullable()->change(); + $table->decimal('start_lng', 12, 10)->nullable()->change(); + $table->decimal('end_lat', 12, 10)->nullable()->change(); + $table->decimal('end_lng', 12, 10)->nullable()->change(); + $table->integer('fuel_consumption')->nullable(); + $table->integer('vehicle_runtime')->nullable(); + $table->json('stop_points')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('road_patrols', function (Blueprint $table) { + $table->decimal('start_lat', 12, 10)->change(); + $table->decimal('start_lng', 12, 10)->change(); + $table->decimal('end_lat', 12, 10)->change(); + $table->decimal('end_lng', 12, 10)->change(); + $table->dropColumn('fuel_consumption'); + $table->dropColumn('vehicle_runtime'); + $table->dropColumn('stop_points'); + }); + } +};