Merge pull request 'Refactor/ride lifecycle' (#26) from refactor/ride_lifecycle into dev

Reviewed-on: #26
This commit was merged in pull request #26.
This commit is contained in:
2026-09-18 06:51:51 +00:00
28 changed files with 12769 additions and 184 deletions
@@ -1,11 +1,36 @@
# [Refactor] Ride Lifecycle — Route-Free, Type-Free Rides
**Status**: Proposed (design only — no code changes yet)
**Status**: Mostly implemented — see [Implementation Status](#implementation-status-2026-09-17)
**Refactors**: [../03_ride_lifecycle.md](../03_ride_lifecycle.md) (kept as-is, this is the target design)
**Depends On**: 02 — Stock Ledger
---
## Implementation Status (2026-09-17)
**Done**, verified against `Models/DeliveryRun.cs`, `Features/Ride/*`:
- `RideStatus` collapsed to `Open`/`Cancelled`/`Closed` — no Draft/Active stage anywhere.
- `FK_RouteId`, `RideType`, `ActivatedAt`, `FK_SourceWarehouseId` are all gone from `DeliveryRun`.
- `POST /api/rides` creates directly into `Open` with `StartedAt` set; no `/open`/`/activate` routes.
- `POST /api/rides/{id}/cancel` cancels an `Open` ride directly — no approval step, no
`CancelRequested` stage.
- Driver compliance check (`CheckDriverComplianceAsync`) and the "vehicle can't have two Open rides"
guard are both wired into `RideService.CreateAsync`.
- Dead `RideCancelRequest` model/repository/table removed (2026-09-17) — see Migration Notes.
**Not done / diverges from this doc:**
1. **`GET /api/rides/breakdown-assist/{rideId}`** — not implemented at all (no route in
`RideController.cs`), not even the trimmed "vehicle stock levels only" version this doc describes.
2. **Impact item 1 (delivery task generation) confirmed still broken, honestly**:
`DeliveryTaskService.GenerateAsync` is a one-line `throw new NotImplementedException("... route-
based dispatch not yet implemented.")` — matches this doc's prediction exactly, not yet designed.
3. **Impact item 4 (stock reconciliation at Close/Cancel without a source warehouse)** — still
unaddressed; `CloseAsync`/`CancelAsync` do not touch `StockBalance` at all.
4. **Impact item 2 (loading sheet auto-population)** — resolved differently than either this doc or
`loading_event.md` predicted; see that document's own Implementation Status section.
---
## Goal
Ride should not require a `Route`, should not carry a `RideType`, should not be gated by a warehouse's `Type`, and should not even pin down a source warehouse on the ride record itself. Per direction from the business owner, the ride record carries only what a real dispatch needs to track — **"a ride only carries vehicle, driver assign, and meter reading from start to end."** Everything route-shaped (which stores get visited, which orders/items travel on this trip) and everything warehouse-shaped (where stock loads from/returns to) moves out of the Ride entity's responsibility entirely; neither is replaced by another matching mechanism here.
@@ -215,9 +240,10 @@ Not part of this docs-only pass, but captured for the eventual implementation st
`DeliveryRun`/`Ride` and their Fluent/EF configuration. `Status` stays, re-typed to the narrowed
`RideStatus` (`Open`/`Cancelled`/`Closed`). Add `CancelTypeCode`, `CancelReason`, `CancelledAt`
columns to `DeliveryRun`.
- Drop the `RideCancelRequest` table, its Fluent/EF configuration, and
`RideCancelRequestRepository`/`IRideCancelRequestRepository` — the request/approve/reject flow is
gone.
- ~~Drop the `RideCancelRequest` table, its Fluent/EF configuration, and
`RideCancelRequestRepository`/`IRideCancelRequestRepository`~~ — **Done (2026-09-17)**: model,
repository, `DbSet`, and seed data removed; `CancelRequestStatus` enum removed as unused;
migration `RemoveRideCancelRequest` applied, dropping the table.
- Remove `RouteId`, `RideType`, and `SourceWarehouseId`/`SourceWarehouseName` from
`CreateRideRequest`, `RideResponse`, and `BreakdownAssistRideResponse` in `RideDTOs.cs`. Remove the
open-orders list from `BreakdownAssistResponse`. Remove the `RaiseCancelRequest`/cancel-request