diff --git a/rental-car-backend/app/Http/Controllers/ReservationController.php b/rental-car-backend/app/Http/Controllers/ReservationController.php new file mode 100644 index 0000000..51c6c55 --- /dev/null +++ b/rental-car-backend/app/Http/Controllers/ReservationController.php @@ -0,0 +1,67 @@ +json($reservations); + } + + public function store(Request $request) + { + $validated = $request->validate([ + 'pickup_date' => 'required|date', + 'dropoff_date' => 'required|date|after_or_equal:pickup_date', + 'pickup_location' => 'required|string|max:255', + 'dropoff_location' => 'required|string|max:255', + 'car_id' => 'required|exists:cars,id', + 'first_name' => 'required|string|max:100', + 'last_name' => 'required|string|max:100', + 'phone_number' => 'required|string|max:20', + 'email' => 'required|email|max:255', + 'address' => 'required|string', + ]); + + $reservation = Reservation::create($validated); + + return response()->json($reservation, 201); + } + + public function show(Reservation $reservation) + { + return response()->json($reservation); + } + + public function update(Request $request, Reservation $reservation) + { + $validated = $request->validate([ + 'pickup_date' => 'required|date', + 'dropoff_date' => 'required|date|after_or_equal:pickup_date', + 'pickup_location' => 'required|string|max:255', + 'dropoff_location' => 'required|string|max:255', + 'car_id' => 'required|exists:cars,id', + 'first_name' => 'required|string|max:100', + 'last_name' => 'required|string|max:100', + 'phone_number' => 'required|string|max:20', + 'email' => 'required|email|max:255', + 'address' => 'required|string', + ]); + + $reservation->update($validated); + + return response()->json($reservation); + } + + public function destroy(Reservation $reservation) + { + $reservation->delete(); + + return response()->json(null, 204); + } +}