# Module: DataAccess/Repositories/RouteRepository ## Purpose Dapper-based repository for the `routes`, `route_points`, and `route_regions` tables. Handles route persistence, point storage, and route-region linking (including geofence metadata). ## Public Interface ### IRouteRepository (interface) - `GetByIdAsync(Guid id) → Task` - `GetRoutePointsAsync(Guid routeId) → Task>`: ordered by `sequence_number` - `InsertRouteAsync(RouteEntity route) → Task` - `InsertRoutePointsAsync(IEnumerable points) → Task`: bulk insert - `UpdateRouteAsync(RouteEntity route) → Task` - `DeleteRouteAsync(Guid id) → Task` - `LinkRouteToRegionAsync(Guid routeId, Guid regionId, bool isGeofence, int? geofencePolygonIndex) → Task`: inserts into `route_regions` with `ON CONFLICT DO NOTHING` - `GetRegionIdsByRouteAsync(Guid routeId) → Task>`: non-geofence region IDs - `GetGeofenceRegionIdsByRouteAsync(Guid routeId) → Task>`: geofence-only region IDs - `GetGeofenceRegionsByPolygonAsync(Guid routeId) → Task>>`: groups geofence regions by polygon index - `GetRoutesWithPendingMapsAsync() → Task>`: routes where `request_maps = true AND maps_ready = false` ### RouteRepository (implementation) Same connection-per-call pattern. `InsertRoutePointsAsync` uses Dapper's bulk execute to insert all points in a single round-trip. ## Internal Logic - `LinkRouteToRegionAsync` uses `ON CONFLICT DO NOTHING` to handle duplicate links gracefully - `GetGeofenceRegionsByPolygonAsync` groups results into a dictionary keyed by `geofence_polygon_index` - `GetRoutesWithPendingMapsAsync` drives the `RouteProcessingService` polling loop ## Dependencies - NuGet: `Dapper`, `Npgsql` - `SatelliteProvider.DataAccess.Models.RouteEntity`, `RoutePointEntity` - `Microsoft.Extensions.Logging` ## Consumers - `RouteService` — insert route, points, link regions - `RouteProcessingService` — read route state, points, region links; update route after map generation ## Data Models Operates on `RouteEntity`, `RoutePointEntity`, and the `route_regions` junction table. ## Configuration Connection string via constructor. ## External Integrations PostgreSQL. ## Security None. ## Tests No dedicated tests.