Skip to content

EstimateArrivalTimesの入力をstation_idに変更しvia_line_idsを配列化 - #1570

Merged
TinyKitten merged 3 commits into
devfrom
feature/estimate-arrival-station-id-input
Jun 30, 2026
Merged

EstimateArrivalTimesの入力をstation_idに変更しvia_line_idsを配列化#1570
TinyKitten merged 3 commits into
devfrom
feature/estimate-arrival-station-id-input

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 30, 2026

Copy link
Copy Markdown
Member

概要

EstimateArrivalTimes RPC の入力を明示的な station_id ベースに変更し、via_line_id を配列化。実用上、両端の駅IDがわからないままクエリを投げるケースが無いため station_group_idstation_id に変更。直通運転対応のため via_line_idrepeated via_line_ids に配列化。

⚠️ マージ順序: 先に TrainLCD/gRPCProto#26 をマージし、サブモジュール参照を更新してからこのPRをマージしてください。

変更の種類

  • バグ修正
  • 新機能
  • データの修正・追加
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • Proto: EstimateArrivalTimesRequest メッセージを新設(from_station_id, to_station_id, repeated via_line_ids
  • Proto: EstimateArrivalTimes RPC のリクエスト型を GetRouteRequestEstimateArrivalTimesRequest に変更
  • gRPCハンドラ: 新リクエスト型に対応
  • Use case / Repository: via_line_id: Option<u32>via_line_ids: &[u32] に変更
  • SQL: 検索条件を station_g_cdstation_cd に変更、via_line_id フィルタを ANY($5::int[]) による配列フィルタに変更
  • Use case interactor: ルート含有チェックを station_g_cdstation_cd に変更
  • sqlx オフラインキャッシュを cargo sqlx prepare --workspace で再生成

テスト

  • cargo fmt --all -- --check が通ること
  • cargo clippy -- -D warnings が通ること
  • cargo testSQLX_OFFLINE=true)が通ること

関連Issue

スクリーンショット(任意)

Summary by CodeRabbit

  • New Features
    • 経由路線を複数指定して、経路検索や到着時刻予測を行えるようになりました。
    • 経由路線の指定が不要な場合は、従来どおり条件なしで検索できます。
  • Bug Fixes
    • 経由条件や駅コードの判定基準を見直し、経路検索結果の精度を改善しました。
    • 結果データの空欄(null)判定を更新し、取得・表示の安定性を向上しました。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TinyKitten TinyKitten self-assigned this Jun 30, 2026
@github-actions github-actions Bot added feature 要望対応や課題解決 deploy-dev labels Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf5fb543-db24-4dcb-ac17-85498f89f5e2

📥 Commits

Reviewing files that changed from the base of the PR and between 16178ce and abbfef7.

📒 Files selected for processing (5)
  • .sqlx/query-26948acea9cc4f77097d6cc9ce3be83aa7bd8d442b32b781de7016663e362378.json
  • .sqlx/query-798b96a32fa32b2c306de99d300447ce83af5aece9ead36f3a31de63dd96b97a.json
  • stationapi/src/domain/repository/station_repository.rs
  • stationapi/src/infrastructure/station_repository.rs
  • stationapi/src/use_case/interactor/query.rs
📝 Walkthrough

Walkthrough

経由路線指定を via_line_id: Option<u32> から via_line_ids: &[u32] へ変更し、リポジトリ契約、ユースケース、SQL、gRPC、モック、テスト、SQLxメタデータを一貫して更新した。

Changes

経由路線の複数指定対応

Layer / File(s) Summary
リポジトリ・ユースケース契約変更
stationapi/src/domain/repository/station_repository.rs, stationapi/src/use_case/traits/query.rs
get_route_stopsestimate_route_arrival_times の引数が via_line_ids: &[u32] に変更された。
インフラ層のSQL・メタデータ更新
stationapi/src/infrastructure/station_repository.rs, .sqlx/query-*.json, stationapi/proto
station_cd 基準と配列 ANY 比較へSQLが更新され、対応する .sqlx の型・nullable・hash と proto 参照が更新された。
ユースケース層の呼び出し更新
stationapi/src/use_case/interactor/query.rs
各ルート取得処理で via_ids を渡すようになり、到着時刻推定の候補判定も station_cd 基準に変わった。
gRPCコントローラ変更
stationapi/src/presentation/controller/grpc.rs
estimate_arrival_timesEstimateArrivalTimesRequest を受け取り、via_line_ids を use case に渡すようになった。
モック・テスト更新
stationapi/src/domain/repository/station_repository.rs, stationapi/src/use_case/interactor/query.rs
モック実装とテスト呼び出しが &[u32] 形式に合わせて更新された。

Sequence Diagram(s)

sequenceDiagram
  participant GrpcController
  participant QueryInteractor
  participant StationRepository
  participant Database
  GrpcController->>QueryInteractor: estimate_route_arrival_times(via_line_ids)
  QueryInteractor->>StationRepository: get_route_stops(from, to, via_line_ids)
  StationRepository->>Database: SQL ANY(via_line_ids) on station_cd
  Database-->>StationRepository: 該当駅一覧
  StationRepository-->>QueryInteractor: Vec<Station>
  QueryInteractor-->>GrpcController: EstimateArrivalTimesResponse
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

ぴょんと跳ねて 配列の道
うさぎの耳で 線路を聞けば
station_cd が ぴたりと光る
ANY でわたる みんなの路
ふわりと更新 たのしい春よ 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.64% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 主要変更であるEstimateArrivalTimesの入力をstation_idベースへ変更し、via_line_idsを配列化する内容を正しく要約しています。
Description check ✅ Passed テンプレートの各セクションが概ね埋まっており、概要・変更内容・テストが具体的に記載されています。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/estimate-arrival-station-id-input

Comment @coderabbitai help to get the list of available commands.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
stationapi/src/infrastructure/station_repository.rs (1)

1945-1954: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

既存 route 系 RPC の group ID 契約を壊しています。

Line 1945/1954 と Line 2092/2102 が station_cd に変わっていますが、既存の get_routes / get_routes_minimal / get_route_typesfrom_station_group_id / to_station_group_id を渡す経路のままです。station_g_cd != station_cd の駅で経路が取れなくなるため、EstimateArrivalTimes 用の station-id 経路と既存 group-id 経路を分けるか、呼び出し側の契約も揃えてください。

Also applies to: 2092-2102

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@stationapi/src/infrastructure/station_repository.rs` around lines 1945 -
1954, The route RPC query has been switched to use station_cd in places where
the existing get_routes, get_routes_minimal, and get_route_types contract still
passes from_station_group_id/to_station_group_id, which breaks stations where
station_g_cd and station_cd differ. Update the relevant query-building logic in
station_repository::get_routes-related code to keep the existing group-id path
intact, or split the EstimateArrivalTimes station-id path into a separate
query/entry point so both contracts remain consistent. Use the existing symbols
get_routes, get_routes_minimal, get_route_types, and the CTEs around
from_cte/to_cte to locate the affected SQL.
🧹 Nitpick comments (2)
stationapi/src/domain/repository/station_repository.rs (1)

333-344: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

station_cd != station_g_cd の経路テストを追加してください。

Line 343 の fixture が常に station_g_cd = station_cd なので、今回の station-id / group-id 契約差分をこのテスト群では検出できません。少なくとも 1 ケースは別値にして、get_route_stops が station ID 前提なのか group ID 前提なのかを明示してください。

Also applies to: 502-541

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@stationapi/src/domain/repository/station_repository.rs` around lines 333 -
344, Add a test case in the Station repository tests where create_test_station
(or the relevant fixture setup used by get_route_stops) sets station_cd and
station_g_cd to different values instead of always mirroring them. Update one of
the route/path test scenarios around get_route_stops to assert the expected
behavior under this mismatch so the station ID vs group ID contract is
explicitly covered.
stationapi/src/use_case/interactor/query.rs (1)

2322-2322: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

station_cd と station_g_cd が異なるケースも追加してください。

到着推定は station_id ベースへ変わりましたが、現テストの helper は station_cd == station_g_cd なので Line 1108 の差分を検証できません。片方だけ異なる駅データで、group_id ではなく station_id でフィルタされることを固定すると安全です。

Also applies to: 2360-2360

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@stationapi/src/use_case/interactor/query.rs` at line 2322, The existing route
arrival time tests only cover the case where station_cd and station_g_cd are the
same, so they do not verify the new station_id-based filtering behavior. Update
the affected tests around estimate_route_arrival_times to add a fixture/helper
case where station_cd differs from station_g_cd, and assert that the logic still
filters by station_id rather than group_id. Make sure the new coverage is added
in the query.rs test area that exercises estimate_route_arrival_times so the
station_id change is fixed by a test that would fail under the old helper data.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@stationapi/src/use_case/interactor/query.rs`:
- Around line 629-632: The route lookup path is mixing group-based IDs with a
repository method that now filters by station_cd, so existing gRPC callers using
from_station_group_id/to_station_group_id will miss routes when station_cd
differs from station_g_cd. Update the query flow in get_routes,
get_routes_minimal, get_train_types, and the related get_route_stops call sites
to keep a group_id-based repository query for these APIs, or rename the
API/trait inputs so they consistently use station_id/station_cd end to end. Use
the symbols get_route_stops, get_routes, get_routes_minimal, and get_train_types
to locate and align the contract.

---

Outside diff comments:
In `@stationapi/src/infrastructure/station_repository.rs`:
- Around line 1945-1954: The route RPC query has been switched to use station_cd
in places where the existing get_routes, get_routes_minimal, and get_route_types
contract still passes from_station_group_id/to_station_group_id, which breaks
stations where station_g_cd and station_cd differ. Update the relevant
query-building logic in station_repository::get_routes-related code to keep the
existing group-id path intact, or split the EstimateArrivalTimes station-id path
into a separate query/entry point so both contracts remain consistent. Use the
existing symbols get_routes, get_routes_minimal, get_route_types, and the CTEs
around from_cte/to_cte to locate the affected SQL.

---

Nitpick comments:
In `@stationapi/src/domain/repository/station_repository.rs`:
- Around line 333-344: Add a test case in the Station repository tests where
create_test_station (or the relevant fixture setup used by get_route_stops) sets
station_cd and station_g_cd to different values instead of always mirroring
them. Update one of the route/path test scenarios around get_route_stops to
assert the expected behavior under this mismatch so the station ID vs group ID
contract is explicitly covered.

In `@stationapi/src/use_case/interactor/query.rs`:
- Line 2322: The existing route arrival time tests only cover the case where
station_cd and station_g_cd are the same, so they do not verify the new
station_id-based filtering behavior. Update the affected tests around
estimate_route_arrival_times to add a fixture/helper case where station_cd
differs from station_g_cd, and assert that the logic still filters by station_id
rather than group_id. Make sure the new coverage is added in the query.rs test
area that exercises estimate_route_arrival_times so the station_id change is
fixed by a test that would fail under the old helper data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ac2622a-c4a5-4837-b488-c0c81f66cb4a

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd95d0 and bac3cc6.

📒 Files selected for processing (10)
  • .sqlx/query-425870f89d0a0ae2c79e80ef7a468c5ef805d7a3f98b56e1b6ad93a1554683b7.json
  • .sqlx/query-6c3b77baaf7b51c4986b8d2a4cfb3f94275ee3595d31aa43938cc1bbd43f0268.json
  • .sqlx/query-c153bbe0cade8f513aeef1475527327a7240e45dd257123047ed4b4618c3c329.json
  • .sqlx/query-cce67d0ec979a71c4e7de242d6c38589c009ae80ee0bc865f5e98a81699c18ee.json
  • stationapi/proto
  • stationapi/src/domain/repository/station_repository.rs
  • stationapi/src/infrastructure/station_repository.rs
  • stationapi/src/presentation/controller/grpc.rs
  • stationapi/src/use_case/interactor/query.rs
  • stationapi/src/use_case/traits/query.rs

Comment thread stationapi/src/use_case/interactor/query.rs
…tops_by_station_cdを新設

get_routes/get_routes_minimal/get_train_typesはstation_group_idを受け取るため
station_g_cdで検索する必要がある。station_cdで検索するのはEstimateArrivalTimes専用。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TinyKitten

Copy link
Copy Markdown
Member Author

Fixes Applied Successfully

Fixed 3 file(s) based on 1 CodeRabbit feedback item(s).

Issue fixed:

  • get_route_stops SQL reverted to station_g_cd for get_routes/get_routes_minimal/get_train_types (which receive station_group_id)
  • Added get_route_stops_by_station_cd for EstimateArrivalTimes (which receives station_cd)

Files modified:

  • stationapi/src/domain/repository/station_repository.rs
  • stationapi/src/infrastructure/station_repository.rs
  • stationapi/src/use_case/interactor/query.rs

Commit: abbfef7

The latest autofix changes are on the feature/estimate-arrival-station-id-input branch.

@TinyKitten

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@TinyKitten
TinyKitten merged commit 12f0de9 into dev Jun 30, 2026
11 checks passed
@TinyKitten
TinyKitten deleted the feature/estimate-arrival-station-id-input branch June 30, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy-dev feature 要望対応や課題解決

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant