feat: add admin trip listing endpoints (list + get)#80
Open
diveshpatil9104 wants to merge 2 commits intoOneBusAway:mainfrom
Open
feat: add admin trip listing endpoints (list + get)#80diveshpatil9104 wants to merge 2 commits intoOneBusAway:mainfrom
diveshpatil9104 wants to merge 2 commits intoOneBusAway:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Completes the trip management feature from README Milestone 2: "Trips: start, end, list active, list historical". PR #55 (merged) implemented start/end so this adds the remaining two read endpoints so admins can see which drivers are currently on the road and review historical trips.
Endpoints
GET/api/v1/admin/tripsstatus,vehicle_id,user_id,limit,offset)GET/api/v1/admin/trips/{id}Both endpoints are protected with
authMiddleware(adminMiddleware(...)).What changed
New files (4):
trip_list_store.go—TripLister/TripGetterinterfaces, compile-time assertions,ListTrips/GetTripstore methods,tripToResponsehelpertrip_list_handlers.go— Handler functions with query param validationtrip_list_handlers_test.go- ~19 unit tests (mocks, validation, boundary, nullable end_time)trip_list_store_test.go- ~9 integration tests (filters, pagination, empty results, not-found, nullable round-trip)Modified files (5):
db/query.sql- AddedListTripsFiltered(single parameterized query withsqlc.narg) andGetTripByIDdb/query.sql.go- Auto-regenerated viamake generatestore_trips.go- AddedCreatedAt/UpdatedAttoTripResponse, splitErrTripNotFoundfromErrActiveTripNotFoundtrip_handlers.go- UpdatedEndTriphandler to useErrActiveTripNotFoundmain.go- Registered 2 new admin routesDesign decisions
Single parameterized query over combinatorial explosion:
ListTripsFilteredusessqlc.nargnullable params (WHERE narg IS NULL OR col = narg) instead of separate queries per filter combination. Scales cleanly when future filters are added.*string/*int64for optional filters:nilmeans "no filter" , avoids zero-value bugs where""or0accidentally matches rows.Split
ErrTripNotFound/ErrActiveTripNotFound: The original sentinel said "active trip not found" (correct forEndTrip) butGetTripreused it for any missing trip. Now each has the right semantics for logging and error wrapping.