Skip to content

GetTrainRouteのline_group_idをprotoどおりoptional扱いにし未指定時は路線の駅列にフォールバック - #1586

Merged
TinyKitten merged 1 commit into
devfrom
fix/train-route-optional-line-group
Jul 3, 2026
Merged

GetTrainRouteのline_group_idをprotoどおりoptional扱いにし未指定時は路線の駅列にフォールバック#1586
TinyKitten merged 1 commit into
devfrom
fix/train-route-optional-line-group

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jul 3, 2026

Copy link
Copy Markdown
Member

概要

GetTrainRouteRequest.line_group_id は proto で optional と定義されているにもかかわらず、実装が未指定時に INVALID_ARGUMENT (line_group_id is required) を返していた乖離を解消する。

変更の種類

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

変更内容

  • コントローラの line_group_id is required ガードを削除し、Option<u32> のまま use case へ渡すように変更
  • get_train_route(trait / interactor / モック)のシグネチャを line_group_id: Option<u32> に変更
  • line_group_id 未指定時は from 駅の所属路線(line_cd)の駅列にフォールバックし、種別なし(各駅停車・単一路線走行)の経路を返す。指定時は従来どおり line_group ベースの経路
  • 経路スライス時の NotFound エラーの entity_type を両経路で共通の station in route に変更

テスト

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

上記に加え、ローカルDBに対して実機確認済み: line_group_id なし(山手線 大崎→渋谷)で segments が正常返却、line_group_id あり(363)で従来どおり返却されることを grpcurl で確認。

関連Issue

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

Summary by CodeRabbit

  • Bug Fixes
    • 路線検索で、路線グループIDが未指定でもルートを取得できるようになりました。
    • 未指定時は出発駅の路線情報をもとに経路を判定し、より自然な検索結果を返します。
    • ルートに含まれない駅がある場合のエラー表示も、より適切な内容に改善されました。

@TinyKitten TinyKitten self-assigned this Jul 3, 2026
@github-actions github-actions Bot added fix 直した deploy-dev and removed fix 直した labels Jul 3, 2026
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e1134152-cacc-4e4a-b7f2-349a89137f22

📥 Commits

Reviewing files that changed from the base of the PR and between 925cf58 and 5db2b67.

📒 Files selected for processing (3)
  • stationapi/src/presentation/controller/grpc.rs
  • stationapi/src/use_case/interactor/query.rs
  • stationapi/src/use_case/traits/query.rs

📝 Walkthrough

Walkthrough

get_train_route の line_group_id 引数が u32 から Option に変更された。トレイト、ユースケース実装、gRPC ハンドラ、テストモックが更新され、line_group_id 未指定時は from_station_id の line_cd を用いて駅列を構築する分岐が追加された。NotFound エラーの entity_type 文言も変更された。

Changes

line_group_id の Optional 化

Layer / File(s) Summary
トレイト契約の変更
stationapi/src/use_case/traits/query.rs
get_train_route の line_group_id 引数型を u32 から Option に変更。
ユースケース実装の分岐処理
stationapi/src/use_case/interactor/query.rs
Some/None で駅列取得経路を分岐し、None 時は from 駅の line_cd から get_stations_by_line_id で駅列を構築、NotFound の entity_type 文字列を"station in route"に変更。
gRPCハンドラとテストモックの更新
stationapi/src/presentation/controller/grpc.rs
line_group_id の必須バリデーションを削除し Option をそのまま渡すよう変更、モックの引数型も同期。

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant GrpcHandler
  participant QueryInteractor
  Client->>GrpcHandler: get_train_route(line_group_id: Option<u32>)
  GrpcHandler->>QueryInteractor: get_train_route(from, to, line_group_id)
  alt line_group_id が Some
    QueryInteractor->>QueryInteractor: get_stations_by_line_group_id
  else line_group_id が None
    QueryInteractor->>QueryInteractor: from駅取得 -> line_cdでget_stations_by_line_id
  end
  QueryInteractor-->>GrpcHandler: 駅列
  GrpcHandler-->>Client: レスポンス
Loading

Possibly related PRs

  • TrainLCD/StationAPI#1568: 同じ get_train_route の line_group_id 処理に手を入れており、必須指定からOptionへの変更と直接関連する。

Suggested labels: fix

Poem

line_group_id よ、任意になったね
None のときも道を探すよ
from駅からline_cdたどって
駅列つなげてぴょんと跳ねる
🐇 route in station、迷わずゴール

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 主要変更であるline_group_idのoptional化と未指定時のフォールバックを具体的に示しており、内容に合っています。
Description check ✅ Passed 概要・変更種別・変更内容・テストが揃っており、テンプレートの必須要素を概ね満たしています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/train-route-optional-line-group

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

@TinyKitten
TinyKitten merged commit 4392f41 into dev Jul 3, 2026
11 checks passed
@TinyKitten
TinyKitten deleted the fix/train-route-optional-line-group branch July 3, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant