Repository navigation
feat(N1-N3): 多乘客/多停靠點——ride_stops 表、配對驗證、建單 API - #33
Merged
Merged
Conversation
This was referenced Jul 17, 2026
thothawei
force-pushed
the
claude/o4-o7-vehicle-visibility
branch
2 times, most recently
from
July 17, 2026 06:32
5671332 to
972003a
Compare
thothawei
force-pushed
the
claude/n1-n3-ride-stops
branch
from
July 17, 2026 06:34
03237ec to
f99cd71
Compare
N 章節第一批(共三批:N1-N3 → N4/N6/N7 → N5)。 N1 migration 000021:ride_stops(ride_id FK CASCADE、seq、kind、point、address、 passenger_label、arrived_at、skipped_at)。CHECK seq>=1 與 kind 白名單; UNIQUE(ride_id, seq)——seq=「第幾站」,重複的話「下一站是誰」沒有答案。 狀態用兩個時間欄而非 status 字串:天然互斥且都需要「何時發生」,時間欄一次回答 「是否」與「何時」,不必另維護狀態機。skipped_at 對應 2026-07-17 拍板的「司機可 跳過缺席乘客」。passenger_label 不做值域 CHECK——不參與邏輯判斷,髒了不會算錯錢。 N2 驗證(純函式 validateStops):上限 5 位/10 停放 constants 而非 fleet_settings (產品規則不是營運費率,放常數才能被編譯期引用)。規則:seq 不重複、每位乘客成對 pickup+dropoff、dropoff.seq > pickup.seq(不能先送再接)。錯誤分成多個而非一個籠統 的 ErrInvalidStops——乘客填錯要知道錯在哪。全部回 400。 N3 建單 API:body 加選填 stops。無 stops=完全維持現行行為(測試釘住:單點訂單不 產生任何 ride_stops 列)。有 stops 時 pickup/dropoff 由 stops 推導(第一個 pickup/ seq 最大的 dropoff)→ rides 照樣有值,派單、導航、地圖、F3 退路、報表一行都不用改。 ride_stops 是額外資訊不是替代品。 停靠點寫在 rides.Create 之後、派單之前(派單一發出司機就該看得到全程),寫失敗則整筆 建單失敗——「只有第一個上車點、少載其餘乘客」比沒建成更糟。未注入 repo 卻收到 stops → 503 而非 400(伺服器沒接好,不是乘客填錯)。 驗收:build/vet/gofmt 綠;service 1274s、repository 604s、handler 47s、constants 全套通過。14 個驗證單元案+5 個整合案。反向驗證:ST_MakePoint 經緯度對調 → 座標跑到 lat=58.48(愛沙尼亞)FAIL;拿掉推導 → 建單以「無效的上車座標」FAIL。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
thothawei
force-pushed
the
claude/n1-n3-ride-stops
branch
from
July 17, 2026 06:34
f99cd71 to
281d3f1
Compare
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.
N 章節(多乘客/多停靠點)第一批。全章分三批:N1-N3(本 PR) → N4/N6/N7(payload 帶 stops、到站與跳過標記)→ N5(OSRM 多 waypoint 計費)。
這不是陌生人拼車:同一張訂單、同行的多位乘客、依序停靠(車隊包車情境),不需配對演算法、不需跨訂單分帳。
相容性是這批的重點
既有單點訂單不產生任何
ride_stops列;多停靠點訂單也照樣寫rides.pickup_point(第一個上車點)與dropoff_point(最終目的地)。→ 派單找最近司機、司機導航、地圖、F3 路線里程退路、報表,全部照原樣讀
rides,一行都不用改。ride_stops是額外資訊,不是替代品。兩條都有測試釘住。N1 migration 000021
ride_stops:ride_id(FK ON DELETE CASCADE)、seq、kind、point、address、passenger_label、arrived_at、skipped_at。seq >= 1、kind IN ('pickup','dropoff')(ride_id, seq)——seq=「第幾站」,重複的話「下一站是誰」沒有答案(UNIQUE 已隱含索引,不另建)狀態用兩個時間欄(
arrived_at/skipped_at)而非 status 字串:兩者天然互斥、且都需要「何時發生」——時間欄一次回答「是否發生」與「何時」,不必另外維護狀態機。皆 NULL = 尚未處理。skipped_at對應 2026-07-17 拍板的「司機可跳過缺席乘客」。passenger_label不做值域 CHECK(不同於車種):純粹給司機辨識,不參與邏輯判斷,值髒掉不會算錯錢。N2 驗證
上限放
internal/constants/ride_stop.go(MaxRidePassengers=5/MaxRideStops=10),不放fleet_settings——TODO 寫「實作時定」:它是產品規則不是營運費率,沒有後台隨時要調的需求,放常數才能被編譯期引用。規則(全部回 400):停靠點數 ≤10、乘客數 ≤5、kind 白名單、座標合法、seq 不得重複、每位乘客成對 pickup+dropoff、dropoff.seq > pickup.seq(不能叫司機先送再接)。
錯誤刻意分成多個而非一個籠統的
ErrInvalidStops——乘客填錯時要知道錯在哪。N3 建單 API
POST /api/ridesbody 加選填stops: [{seq, kind, lat, lng, address, passenger_label}]。stops= 完全維持現行行為stops→ pickup/dropoff 由 stops 推導並覆蓋 body 的pickup_lat/lngrides.Create之後、派單之前(派單一發出,司機就該看得到全程)。寫失敗則整筆建單失敗——「只有第一個上車點、少載其餘乘客」的行程比沒建成更糟ErrStopsUnavailable→ 503(不是 400:伺服器沒接好,不該讓乘客以為自己填錯,更不能默默當單點訂單建出去)驗收(實際跑過)
go build/go vet/gofmt綠;service 1274s、repository 604s、handler 47s、constants 全套通過。ST_MakePoint經緯度對調 → 台北車站跑到 lat=58.48(愛沙尼亞),FAIL;拿掉「由 stops 推導」→ 建單以「無效的上車座標」FAIL。未驗:docker compose 起全服務的 live E2E。
本批未做(後續兩批)
ride.assigned/司機 active 帶 stops;到站與跳過標記 API。🤖 Generated with Claude Code