Backend: Zapisnici list
GitHub Issue: #194
Last modified with commit 374306c on
by Aljaž.
Backend task for the Zapisnici list and the PDF download (GET /drivepark/records, GET /drivepark/records/{recordId}/pdf/{stage}) – check the API spec and DB structure, compute the status, search and sort, stream the stored PDFs, implement, and verify against the spec.
Docs: Zapisnici list
Spec: GET /drivepark/records (getDriveParkRecords), GET /drivepark/records/{recordId}/pdf/{stage} (downloadDriveParkRecordPdf), DriveParkRecord, DriveParkRecordStatus, DriveParkRecordStage in api-docs/openapi.yaml
DB: DriveParkRecords in api/database/pending_schema.sql (-- DRIVE PARK --)
1. Double check API spec and DB structure
- Every list column has a field in
DriveParkRecord: Vozilo (vehicleBrandCode,vehicleName,vehiclePlate), Korisnik (fullName,company), Razdoblje (usageFrom–usageTo, the record’s own Rok korištenja), Status (status). - Status is computed (Draft / Preuzeto / Vraćeno from
PickupCompletedAt/ReturnCompletedAt), not stored. Check the button table in the docs can be built fromstatusalone: Draft → open pickup form; Preuzeto → pickup view + pickup PDF + open return form; Vraćeno → both views + both PDFs. (The spec and Figma show only “Download PDF” for completed records; the docs add “Otvori zapisnik …” to open the views. The client decides.) - Sorting and page size: not specified (docs comment: “Recommended: 10 records per page,
sorted by Razdoblje Od, newest first”). The spec sorts by
usageFromdescending, nulls first. Confirm; the frontend sendsperPage=10. - Search: vehicle (name, plate) and user (fullName, company). Check the docs agree (“Pretraži po vozilu ili korisniku”).
- Two PDFs per record, one per stage. The PDF layout is not specified yet.
- Roles and permissions:
drivepark.access. - DB:
IX_DriveParkRecords_UsageFromfor the sort.
2. Implementation
- Roles and permissions: require
drivepark.access→ 403. - List: one count query and one page query (
OFFSET/FETCH), joined with Vehicles forvehicleBrandCode,vehicleName,vehiclePlate(noDeletedAt/ archived filter); search withLIKEon Vehicles.Name, Vehicles.Plate, FullName and Company; status as aCASEexpression. - PDF: load the record; the stage’s
*PdfBlobis null (stage not completed) → 404; otherwise stream the blob asapplication/pdfwithContent-Disposition(e.g.Zapisnik-o-preuzimanju-ZG-123-AA.pdf).
3. Verify implementation against spec
- Routes, query parameters and response shapes match
getDriveParkRecordsanddownloadDriveParkRecordPdf. - 401 / 403 / 404 / 500 can be produced; no undocumented ones.
- One record of each status →
draft,picked-up,returned. - Search by part of the plate and by part of the company name both find the record.
- Return PDF of a Preuzeto record → 404; pickup PDF of a Draft → 404.
Done when
The Zapisnici list shows every record with its status and the right buttons, and the PDFs can be downloaded.