Backend: Kalendar zauzetosti
GitHub Issue: #190
Last modified with commit e90a924 on
by Aljaž.
Backend task for the Kalendar zauzetosti (GET /drivepark/calendar) – check the API spec and DB structure, return all vehicles (archived only with bookings in the month) with their reservations and event bookings for a month, implement, and verify against the spec.
Docs: Kalendar zauzetosti
Spec: GET /drivepark/calendar (getDriveParkCalendar), DriveParkCalendar, DriveParkCalendarVehicle (allOf Vehicle), DriveParkCalendarEntry in api-docs/openapi.yaml
DB: Vehicles, VehicleReservations, DriveParkReservations, Events in api/database/pending_schema.sql (-- DRIVE PARK --) and create_schema.sql
1. Double check API spec and DB structure
- Vehicles shown: all non-deleted vehicles; archived ones only when they have an entry in the month (the docs show archived vehicles so past reservations stay visible). Confirm this with the docs comment (“Recommended: only in months where they have a reservation or an event”).
- Groups: Vozni park =
IsForDrive, grouped byPurpose(frontend valuesit,after-sales,vip,press); Događaji =IsForEvent. Grouping and counts (“1 vozilo”, “2 vozila”) are done by the frontend. Check every vehicle has exactly one of the two flags, or decide where a vehicle with both / neither goes. - Entries: VehicleReservations rows overlapping the month,
reservation(blue, label = company – fullName) orevent(green, event name). Check past event bookings are kept when an event is archived (only future bookings are released) so past green bars stay. - Neispravno: not an entry; the frontend shows grey from today when
isActiveis false. Check the docs agree (based on the current status, from today on). - Brand filter:
brandCode(nice-to-have “SVE MARKE”). NolimitedBrandCodesrestriction: Vozni park shows all brands. - Not shown: pickup/return records (Zapisnici).
- Event dates: green bars span the event’s StartTime–EndTime from its VehicleReservations row. The docs comment (“Recommended: the event’s start to end date”) matches; confirm.
- Roles and permissions:
drivepark.access. - DB:
IX_VehicleReservations_VehicleIdis enough for one month of data. If the query is slow, add an index on (StartTime, EndTime) with a migration.
2. Implementation
- Roles and permissions: require
drivepark.access→ 403. - Validate
month(YYYY-MM) andbrandCode→ 400validation_error. - One query for the vehicles and one for the entries of the month (
StartTime < first day of next month AND EndTime > first day of month),LEFT JOINDriveParkReservations and Events for the label; group entries per vehicle in code. No query per vehicle. - Order vehicles: Vozni park (by purpose) first, then Događaji; then brandCode, name, plate. Entries by start.
- Map to
DriveParkCalendarVehicle(Vehiclefields,isOccupied/canVehicleBeDeletedomitted) andDriveParkCalendarEntry(startDate/startTime/endDate/endTime,HH:mm).
3. Verify implementation against spec
- Route, method, query parameters and response shape match
getDriveParkCalendar. - 400 (bad month) / 401 / 403 / 500 can be produced; no undocumented status codes.
- A reservation from 28.11. to 3.12. shows in both November and December.
- An archived vehicle with a reservation in the month is included; without one it isn’t. A deleted vehicle is never included.
- A vehicle with
IsActive = 0is returned withisActive: falseand its existing entries. -
brandCode=Areturns only Audi vehicles.
Done when
The calendar shows every vehicle of the month with its blue reservation bars, green event bars and Neispravno state.