Backend: Editing existing reservation
GitHub Issue: #191
Last modified with commit e90a924 on
by Aljaž.
Backend task for loading and updating a Vozni park reservation (GET and POST /drivepark/reservations/{reservationId}) – check the API spec and DB structure, reuse the lock and overlap check while ignoring the reservation's own booking, handle a vehicle change, implement, and verify against the spec.
Docs: Editing existing reservation
Spec: GET /drivepark/reservations/{reservationId} (getDriveParkReservation), POST /drivepark/reservations/{reservationId} (updateDriveParkReservation), DriveParkReservationNewRequest, DriveParkReservation, DriveParkReservationNotFound, DriveParkReservationConflict in api-docs/openapi.yaml
DB: DriveParkReservations, VehicleReservations in api/database/pending_schema.sql (-- DRIVE PARK --)
1. Double check API spec and DB structure
- The form has the same fields as Adding new reservation, prefilled. Check
DriveParkReservationreturns everything the form needs (vehicle id, brand, name and plate for the dropdown, dates, company, fullName, contact). - Past reservations can be edited (docs). Check the spec has no “past” rule.
- Overlap check ignores the reservation’s own VehicleReservations row.
- Archived / deleted vehicle: checked only when
vehicleIdchanges, so a past reservation of a since-archived vehicle can still be edited. Neispravno is always checked (period ending today or later). - Vehicle change: both vehicles are locked, ascending Id. Check the lock order against the events/vehicles locking PR.
- Zapisnici: not linked to reservations; an update changes no record. Check nothing in the records reads reservation data.
- Labels: Figma CTA “PRIHVATI REZERVACIJU” and title “Uredi rezervaciju” are frontend only; the toast says the reservation was updated.
- Roles and permissions:
drivepark.accesson both endpoints.
2. Implementation
- Roles and permissions: require
drivepark.access→ 403. -
GET: load the reservation with its VehicleReservations row and vehicle → 200DriveParkReservation; unknown id → 404. -
POST: in one transaction, lock the vehicle(s), run the shared availability and overlap helpers from Backend: Adding new reservation (excluding the own row), then update DriveParkReservations (UpdatedAt) and its VehicleReservations row (VehicleId,StartTime,EndTime). - Validation → 400
validation_error, same as create. - Response 200 with the updated
DriveParkReservation.
3. Verify implementation against spec
- Routes, methods, request and response shapes match
getDriveParkReservationandupdateDriveParkReservation. - 400 / 404 / 409
vehicle_unavailable/ 409vehicle_conflictcan be produced; no undocumented ones. - Moving a reservation by one day where it only overlaps itself → 200.
- Changing the vehicle to one booked on those days → 409; to a free one → 200, and the bar moves to the new row.
- Editing a past reservation of a vehicle that is now archived (same vehicle) → 200.
- BrandManager → 403.
Done when
A Manager of Vozni park can change any reservation, including past ones, without creating an overlap.