Skip to content

バス路線はline_typeをOtherLineTypeに強制#1372

Merged
TinyKitten merged 1 commit into
devfrom
fix/sql-issues
Jan 6, 2026
Merged

バス路線はline_typeをOtherLineTypeに強制#1372
TinyKitten merged 1 commit into
devfrom
fix/sql-issues

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jan 6, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

リリースノート

  • バグ修正

    • バス路線のデータ変換処理を改善しました。
  • テスト

    • バスと鉄道路線の処理パターンに関する包括的なテストを追加しました。

✏️ Tip: You can customize this high-level summary in your review settings.

@TinyKitten TinyKitten self-assigned this Jan 6, 2026
@coderabbitai

coderabbitai Bot commented Jan 6, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

stationapi/src/use_case/dto/line.rsにて、Line型からGrpcLine型への変換時に、transport_typeがBusの場合にline_typeを強制的に0(OtherLineType)に設定するバス固有の正規化ロジックを導入しました。これまでのunwrap_or_defaultを計算済みのline_type変数に置き換え、包括的なテストモジュールを追加しました。

Changes

Cohort / File(s) 変更サマリー
バス正規化ロジックとテスト
stationapi/src/use_case/dto/line.rs
transport_typeがBusの場合にline_typeを強制的にOtherLineType(0)に設定する条件付き正規化ロジックを実装。Rail型の場合は既存のline_typeを保持またはデフォルト値を使用。複数のバス・レール線種ケース、convert_transport_type関数動作、エッジケース処理、未知のline_type処理、および線路ID変換を網羅した包括的なテストモジュールを追加。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰✨ バスの線も、統一の手で
OtherLineTypeへ優しく導かれ
レールは個性を保ちながら
テストが全てを照らすように
正規化の旅、完成だね!🚌🚃

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed バス路線のline_typeをOtherLineTypeに強制する変更を正確に説明しており、プルリクエストの主要な変更内容を明確に示している。
Docstring Coverage ✅ Passed Docstring coverage is 89.29% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7be4886 and ba2e953.

📒 Files selected for processing (1)
  • stationapi/src/use_case/dto/line.rs
🧰 Additional context used
📓 Path-based instructions (3)
stationapi/src/use_case/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Application logic in use case layer should implement contract traits defined in traits/ module (e.g., QueryUseCase in interactor/query.rs)

Files:

  • stationapi/src/use_case/dto/line.rs
stationapi/src/**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

Run cargo test --lib --package stationapi or make test-unit for unit tests focusing on entities and repository mocks without database

Files:

  • stationapi/src/use_case/dto/line.rs
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Before committing, run cargo fmt on all Rust code
Before committing, run cargo clippy --all-targets --all-features and resolve new Clippy warnings unless covered by existing #![allow] attributes

Files:

  • stationapi/src/use_case/dto/line.rs
🧠 Learnings (1)
📚 Learning: 2025-11-25T10:50:36.694Z
Learnt from: CR
Repo: TrainLCD/StationAPI PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T10:50:36.694Z
Learning: Applies to stationapi/src/use_case/interactor/query.rs : When modifying `QueryInteractor`, ensure enrichment steps (companies, train types, line symbols) still behave as expected and verify helper methods such as `update_station_vec_with_attributes` and `build_route_tree_map`

Applied to files:

  • stationapi/src/use_case/dto/line.rs
🧬 Code graph analysis (1)
stationapi/src/use_case/dto/line.rs (4)
stationapi/src/domain/entity/line.rs (1)
  • create_test_line (152-189)
stationapi/src/use_case/interactor/query.rs (1)
  • create_test_line (1207-1244)
stationapi/src/domain/entity/train_type.rs (1)
  • create_test_line (66-103)
stationapi/src/presentation/controller/grpc.rs (3)
  • test_convert_transport_type_rail (406-410)
  • convert_transport_type (22-29)
  • test_convert_transport_type_bus (413-417)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test Suite
🔇 Additional comments (4)
stationapi/src/use_case/dto/line.rs (4)

8-14: 実装は正確で、コメントも明確です。

バス路線のline_typeを強制的にOtherLineType(0)に設定するロジックは正しく実装されています。鉄道路線ではunwrap_or_default()を使用して既存の値を保持し、Noneの場合はデフォルト値(0)を返すようになっています。

Also applies to: 25-25


39-44: ヘルパー関数の実装は正しいです。

convert_transport_type関数はTransportTypeからGrpcTransportTypeへのマッピングを正確に行っています。


46-221: テストカバレッジが非常に包括的です。

バス路線と鉄道路線の両方について、様々なline_type値の変換ロジックを網羅的にテストしています。エッジケース(None値、境界値)も適切にカバーされています。


227-366: テスト実装は適切で、コーディングガイドラインに準拠しています。

convert_transport_type、Line から GrpcLine への変換、境界値、エッジケースのテストすべてが正しく実装されています。以下の項目を確認しました:

  • フィールドマッピング:id、名前、色などの基本フィールドが正しく変換される
  • オプショナルフィールド:None 値が適切にデフォルト値に変換される
  • 関連オブジェクト:station、company、train_type が正しく None になる
  • 境界値:line_type 0-5 が各 GrpcLineType に正確に変換される
  • エッジケース:
    • 鉄道路線の未知の line_type(99)は保持される
    • バス路線の未知の line_type(99)は OtherLineType になる
  • 型変換:line_cd が u32 に正しく変換される
  • コード形式:cargo fmt チェック合格

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

@TinyKitten TinyKitten merged commit c231ef3 into dev Jan 6, 2026
10 checks passed
@TinyKitten TinyKitten deleted the fix/sql-issues branch January 6, 2026 09:35
TinyKitten added a commit that referenced this pull request Jan 8, 2026
* SQLの致命的なバグをいくつか修正 (#1371)

* ひらがな混じりで駅検索ができないバグを修正

* get_train_types_by_station_idが動かないバグを修正

* GetStationsByLineGroupIdの修正

* ユニットテスト拡充

* cargo fmt

* バス路線はline_typeをOtherLineTypeに強制 (#1372)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正 (#1373)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正

GTFSの仕様ではdirection_idはオプショナルであり、NULLの場合でも
バス停は有効な停留所として扱うべきである。

これまではvariant_only_with_neighbors CTEで「direction_id IS NOT NULL」
のトリップにのみ存在するバス停をフィルタリングしていたため、
早81の原宿駅前や渋谷駅東口などのバス停がレスポンスから除外されていた。

* バリアントバス停の位置推定でメイントリップに存在する隣接バス停を優先

variant_only_with_neighborsでバス停の隣接情報を選択する際に、
隣接バス停(prev_stop_id/next_stop_id)がメイントリップに存在する
レコードを優先するよう修正。

これにより、原宿駅前などのバス停がより正確な位置に挿入される。

---------

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
TinyKitten added a commit that referenced this pull request Mar 6, 2026
* master<-dev (#1337)

* GetRoutesMinimal RPCを実装 (#1334)

* Add minimal route retrieval functionality and related proto types

* Refactor code formatting for improved readability in grpc.rs and query.rs

* Add line symbols to LineMinimal in get_lines_by_station_group_id

* Update subproject commit reference in stationapi/proto

* Add get_lines_by_id_list method and update QueryUseCase trait

* Refactor import order for improved readability in grpc.rs

* Use entry method for inserting line_minimal in all_lines to avoid overwriting

* Refactor route_row_tree_map creation into a separate build_route_tree_map method for improved readability

* Enhance line symbol handling in QueryInteractor: populate line_symbols for all lines and update line_minimal entries conditionally

* Refactor line symbol handling in QueryInteractor: update all_lines conditionally based on line_symbols presence

* Add AGENTS.md for automation agent and contributor workflow guidelines

* Update AGENTS.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* 石橋阪大前駅ローカライズ修正 (#1336)

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* master<-dev (#1374)

* SQLの致命的なバグをいくつか修正 (#1371)

* ひらがな混じりで駅検索ができないバグを修正

* get_train_types_by_station_idが動かないバグを修正

* GetStationsByLineGroupIdの修正

* ユニットテスト拡充

* cargo fmt

* バス路線はline_typeをOtherLineTypeに強制 (#1372)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正 (#1373)

* direction_idがNULLのトリップに存在するバス停も正しく取り込むよう修正

GTFSの仕様ではdirection_idはオプショナルであり、NULLの場合でも
バス停は有効な停留所として扱うべきである。

これまではvariant_only_with_neighbors CTEで「direction_id IS NOT NULL」
のトリップにのみ存在するバス停をフィルタリングしていたため、
早81の原宿駅前や渋谷駅東口などのバス停がレスポンスから除外されていた。

* バリアントバス停の位置推定でメイントリップに存在する隣接バス停を優先

variant_only_with_neighborsでバス停の隣接情報を選択する際に、
隣接バス停(prev_stop_id/next_stop_id)がメイントリップに存在する
レコードを優先するよう修正。

これにより、原宿駅前などのバス停がより正確な位置に挿入される。

---------

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>

* 西鉄データ更新 (#1375)

* 春日原駅を特急停車駅に指定

* 聖マリア病院前の駅名修正

* master<-dev (#1391)

* GetStationsByLineIdList RPC追加

複数のline_idを一括で処理するバッチRPCを追加。
既存のGetStationByIdList/GetLineByIdListと同じバッチパターンに従う。

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

* cargo fmt

* get_by_line_id_vecのORDER BYを入力順序保持のCASE式に変更

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

* Merge pull request #1389 from TrainLCD/feature/tt-batch

GetStationsByLineGroupIdList RPC追加

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット (#1390)

* get_stations_by_line_group_id_vecで列車種別を一括取得してセット

N+1問題を回避しつつ、train_type_repository.get_by_line_group_id_vecで
複数line_group_idの列車種別を1クエリで取得し、top-levelとlines[].station
の両方にセットするよう修正。

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

* get_stations_by_line_group_id_vecのユニットテストを追加

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

* ネストされた駅のtrain_typeをis_some()で明示的に検証するよう修正

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

* train_typeをtrain_type_mapから常に上書きしてリーク防止

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>

* 近鉄種別修正

* 近鉄種別修正

駅コード修正

---------

Co-authored-by: Tsubasa SEKIGUCHI <oss@tinykitten.me>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant