Skip to content

feat: add admin trip listing endpoints (list + get)#80

Open
diveshpatil9104 wants to merge 2 commits intoOneBusAway:mainfrom
diveshpatil9104:feat/admin-trip-listing
Open

feat: add admin trip listing endpoints (list + get)#80
diveshpatil9104 wants to merge 2 commits intoOneBusAway:mainfrom
diveshpatil9104:feat/admin-trip-listing

Conversation

@diveshpatil9104
Copy link
Copy Markdown
Contributor

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

Method Path Description
GET /api/v1/admin/trips List trips with optional filters (status, vehicle_id, user_id, limit, offset)
GET /api/v1/admin/trips/{id} Get a single trip by ID

Both endpoints are protected with authMiddleware(adminMiddleware(...)).

What changed

New files (4):

  • trip_list_store.goTripLister / TripGetter interfaces, compile-time assertions, ListTrips / GetTrip store methods, tripToResponse helper
  • trip_list_handlers.go — Handler functions with query param validation
  • trip_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 - Added ListTripsFiltered (single parameterized query with sqlc.narg) and GetTripByID
  • db/query.sql.go - Auto-regenerated via make generate
  • store_trips.go - Added CreatedAt/UpdatedAt to TripResponse, split ErrTripNotFound from ErrActiveTripNotFound
  • trip_handlers.go - Updated EndTrip handler to use ErrActiveTripNotFound
  • main.go - Registered 2 new admin routes

Design decisions

Single parameterized query over combinatorial explosion: ListTripsFiltered uses sqlc.narg nullable params (WHERE narg IS NULL OR col = narg) instead of separate queries per filter combination. Scales cleanly when future filters are added.

*string / *int64 for optional filters: nil means "no filter" , avoids zero-value bugs where "" or 0 accidentally matches rows.

Split ErrTripNotFound / ErrActiveTripNotFound: The original sentinel said "active trip not found" (correct for EndTrip) but GetTrip reused it for any missing trip. Now each has the right semantics for logging and error wrapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant