Repository navigation
feat(N4+N6+N7): 司機端看得到全程停靠點+到站/跳過標記 - #34
Merged
Merged
Conversation
thothawei
force-pushed
the
claude/n1-n3-ride-stops
branch
2 times, most recently
from
July 17, 2026 06:34
f99cd71 to
281d3f1
Compare
thothawei
force-pushed
the
claude/n4-n6-n7-stops-visibility
branch
from
July 17, 2026 06:36
0e2b1be to
f08ba00
Compare
N 章節第二批(第三批 N5 計費)。 N4 派單:邏輯完全沒動——仍以 rides.pickup_point(=第一個上車點,N3 已推導)找最近 司機。ride.assigned 與司機端 ride.accepted 加 stops,司機接單前就看得到「A 在哪上、 B 在哪下、最終到哪」。單點訂單不放 stops 鍵。座標攤平成 lat/lng,與既有 pickup_lat/lng 一致,App 端不必另寫解析。讀停靠點失敗不擋派單,退化成看不到全程但仍可執行。 FCM 註記修正:TODO 原提醒「FCM data 要 JSON 字串化」,但盤點後發現後端根本還沒送 data——notify.SendRideOffer 只送 title/body/ride_id 且實作是 stub(真 FCM 是 A2)。 stops 目前只走 WS;提醒移到 rideAssignedPayload 註解留給日後做真 FCM 的人。 N6 司機 active:DriverRideView 內嵌 *model.Ride(JSON 攤平,既有欄位一個不少), 單點訂單 omitempty 不會多出空陣列。停靠點含 arrived_at/skipped_at,只在真的發生時帶。 N7 到站/跳過標記:POST /api/rides/:id/stops/:stop_id/arrive 與 /skip。 授權是重點:stop_id 全域遞增 → 只驗 ride 歸屬不夠,必須同時驗 stop.RideID == rideID, 否則司機可拿自己的 ride_id 改別人行程的停靠點。 不覆寫既有事實:條件式更新(WHERE arrived_at IS NULL AND skipped_at IS NULL),重複 標記回 409;已到達的站不得反悔改成跳過——那會讓 N5 計費路線少算司機真的開過的路。 行程已完成/取消一律 409(計費已定格)。 測試本身踩過一個坑並修正:兩個 fixture 各起一個容器時 id 都從 1 開始,「別趟的 stop_id」會撞到自己那趟的同號 stop 而合法通過(假綠)。改為同一個 DB 建兩趟。 驗收:build/vet/gofmt 綠;service 1341s、repository 611s、handler 45s、constants 全套通過。反向驗證:拿掉 stop.RideID 檢查 → 可標記別趟停靠點,FAIL。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
thothawei
force-pushed
the
claude/n4-n6-n7-stops-visibility
branch
from
July 17, 2026 06:36
f08ba00 to
3d48786
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 章節第二批(第三批=N5 計費)。
N4 派單
派單邏輯完全沒動——仍以
rides.pickup_point(=第一個上車點,N3 已推導)找最近司機。ride.assigned與司機端ride.acceptedpayload 加stops:司機接單前就要看得到「A 在哪上、B 在哪下、最終到哪」,才知道要不要接。stops鍵lat/lng,與既有的pickup_lat/pickup_lng一致,App 端不必為 stops 另寫解析pickup_point前往第一個上車點——比整趟派不出去好FCM 註記(盤點後修正 TODO)
TODO 原本提醒「FCM data 要 JSON 字串化」,但現況根本還沒送 data:
notify.SendRideOffer只送 title/body/ride_id,且實作是 stub(真 FCM 是 A2 待辦)。故 stops 目前只走 WS。提醒已移到rideAssignedPayload註解,留給日後做真 FCM 的人(見 pitfall-fcm-data-all-strings:漏掉會讓推播接單直接崩)。N6 司機端 active
GET /api/driver/rides/active回DriverRideView——內嵌*model.Ride讓 JSON 攤平,既有欄位一個不少,只多stops(單點訂單omitempty,不會多出空陣列)。每站含
id/seq/kind/lat/lng/passenger_label/address,以及arrived_at/skipped_at(只在真的發生時帶,兩者皆無=待處理)→ 司機知道「下一站是誰、在哪、處理了沒」。N7 到站/跳過標記
POST /api/rides/:id/stops/:stop_id/arrive/.../skip(driver JWT,被指派司機限定)。授權是重點:
stop_id是全域遞增的 → 只驗 ride 歸屬不夠,必須同時驗stop.RideID == rideID,否則司機可拿自己的 ride_id 去改別人行程的停靠點狀態。不覆寫既有事實:
MarkArrived/MarkSkipped皆為條件式更新(WHERE arrived_at IS NULL AND skipped_at IS NULL),重複標記回 409。已到達的站不得反悔改成跳過——那會讓 N5 的計費路線少算一段司機真的開過的路。行程已完成/取消時一律 409(計費已定格)。驗收(實際跑過)
go build/go vet/gofmt綠;service 1341s、repository 611s、handler 45s、constants 全套通過。stopViews(座標攤平、狀態鍵只在發生時帶、空回 nil)、rideAssignedPayload/rideAcceptedDriverPayload帶/不帶 stops。ListForDriver。stop.RideID != rideID檢查 → 可標記別趟的停靠點,FAIL。未驗:docker compose 起全服務的 live E2E。
過程中修掉一個「假綠」測試
「不得拿自己的 ride_id 去標記別趟的停靠點」原本用第二個 fixture 取得 stop_id——但
newServiceTestDB每次都起一個新容器,兩個 DB 的自增 id 都從 1 開始,於是「別趟的 stop_id=1」在自己的 DB 裡恰好就是自己那趟的第一站,合法通過。測試改為在同一個 DB 建兩趟行程。這個坑很隱蔽:若產品碼當初沒寫歸屬檢查,這個測試會「通過」而讓漏洞溜過去。
下一步
N5(最後一批):OSRM 多 waypoint(現行 client 介面寫死兩點)+ haversine 逐段累加+
Complete走全程路線,排除已跳過的停靠點——沒去就沒開那段路,計入等於收乘客沒走的路的錢。🤖 Generated with Claude Code