Skip to content

Conversation

@TinyKitten
Copy link
Member

@TinyKitten TinyKitten commented Jan 15, 2026

Summary by CodeRabbit

リリースノート

  • バグ修正
    • RailAndBusフィルター選択時に、駅検索結果の表示順序を改善しました。鉄道駅がバス駅の前に表示されるようになり、各交通機関タイプ内での距離順序は保持されます。

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

概要

gRPCコントローラーでTransportTypeのインポートを追加し、駅コレクションをミュータブル化。RailAndBusフィルター使用時に、距離順序を保持しながら鉄道を路線バスの前に安定的に並び替えるロジックを実装した。

変更内容

コホート / ファイル 変更サマリー
TransportType関連の拡張インポート
stationapi/src/presentation/controller/grpc.rs
ドメインGTFSエンティティからTransportTypeFilterに加えてTransportTypeをインポート
RailAndBus時の駅並び替え機能
stationapi/src/presentation/controller/grpc.rs
座標で取得した駅をミュータブル化し、RailAndBusフィルター使用時に大文字小文字を区別しない安定ソートで鉄道を路線バスより前に配置

推定レビュー時間

🎯 2 (Simple) | ⏱️ ~10分

関連する可能性のあるPR

ウサギの詩

🚄 線路と走る乗りもの
並ぶ距離も大切だが
鉄路がまず前へ
かしこき並び替えで
旅人の迷い晴らす ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRのタイトルは変更内容の主要な目的を正確に反映しており、RailAndBusフィルター使用時にRailを先頭にソートする動作が明確に記述されています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
stationapi/src/presentation/controller/grpc.rs (1)

135-142: ソートロジックは正しいですが、ユニットテストの追加を検討してください。

Rustの sort_by は安定ソートなので、コメント通り距離順は維持されます。ロジックも正しいです。

ただし、この新しいソート動作をカバーするユニットテストが見当たりません。RailAndBus フィルタ時に Rail が Bus より前にソートされることを検証するテストを追加することをお勧めします。

📝 テスト追加の提案
#[tokio::test]
async fn test_get_stations_by_coordinates_rail_and_bus_sorts_rail_first() {
    // Bus が先、Rail が後の順序で返されるケースをシミュレート
    let bus_station1 = create_test_station(1, TransportType::Bus);
    let rail_station1 = create_test_station(2, TransportType::Rail);
    let bus_station2 = create_test_station(3, TransportType::Bus);
    let rail_station2 = create_test_station(4, TransportType::Rail);
    
    let mock = MockQueryUseCase::with_stations(vec![
        bus_station1.clone(),
        rail_station1.clone(),
        bus_station2.clone(),
        rail_station2.clone(),
    ]);

    let result = mock
        .get_stations_by_coordinates(35.0, 139.0, Some(10), TransportTypeFilter::RailAndBus)
        .await
        .unwrap();

    // Rail が先頭にソートされていることを確認
    assert_eq!(result[0].transport_type, TransportType::Rail);
    assert_eq!(result[1].transport_type, TransportType::Rail);
    assert_eq!(result[2].transport_type, TransportType::Bus);
    assert_eq!(result[3].transport_type, TransportType::Bus);
    
    // 安定ソートにより、同じタイプ内での順序が維持されていることを確認
    assert_eq!(result[0].station_cd, 2); // rail_station1
    assert_eq!(result[1].station_cd, 4); // rail_station2
    assert_eq!(result[2].station_cd, 1); // bus_station1
    assert_eq!(result[3].station_cd, 3); // bus_station2
}

注意: このテストは MockQueryUseCase を直接テストしているため、実際のソートロジック(MyApi::get_stations_by_coordinates 内)をテストするには、MyApi のインスタンスを使ったテストが必要になります。


📜 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 5b51e72 and 343f359.

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

📄 CodeRabbit inference engine (AGENTS.md)

gRPC presentation layer controller should wire service implementations (e.g., MyApi) to generated server types in presentation/controller/grpc.rs

Files:

  • stationapi/src/presentation/controller/grpc.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/presentation/controller/grpc.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/presentation/controller/grpc.rs
🧠 Learnings (7)
📚 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/presentation/controller/**/*.rs : gRPC presentation layer controller should wire service implementations (e.g., `MyApi`) to generated server types in `presentation/controller/grpc.rs`

Applied to files:

  • stationapi/src/presentation/controller/grpc.rs
📚 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/domain/**/*.rs : In Rust domain layer, entity definitions and repository abstractions should be organized in the `entity/` module mirroring the gRPC schema, with repository interfaces using `async_trait`

Applied to files:

  • stationapi/src/presentation/controller/grpc.rs
📚 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/presentation/controller/grpc.rs
📚 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/proto/**/*.proto : Keep gRPC contract definitions in `proto/stationapi.proto` and use `build.rs` with `tonic-build` to generate server code and `FILE_DESCRIPTOR_SET`

Applied to files:

  • stationapi/src/presentation/controller/grpc.rs
📚 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/**/*.rs : Application logic in use case layer should implement contract traits defined in `traits/` module (e.g., `QueryUseCase` in `interactor/query.rs`)

Applied to files:

  • stationapi/src/presentation/controller/grpc.rs
📚 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/**/*.rs : Run `cargo test --lib --package stationapi` or `make test-unit` for unit tests focusing on entities and repository mocks without database

Applied to files:

  • stationapi/src/presentation/controller/grpc.rs
📚 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/domain/repository/**/*.rs : Use `async_trait` for defining repository abstractions in Rust

Applied to files:

  • stationapi/src/presentation/controller/grpc.rs
🧬 Code graph analysis (1)
stationapi/src/presentation/controller/grpc.rs (1)
stationapi/src/use_case/interactor/query.rs (1)
  • stations (235-238)
🔇 Additional comments (2)
stationapi/src/presentation/controller/grpc.rs (2)

2-2: LGTM!

TransportType のインポート追加は、新しいソートロジックで必要となるため適切です。


126-133: LGTM!

mut の追加は、後続のソート処理のために必要です。

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

@TinyKitten TinyKitten self-assigned this Jan 15, 2026
@TinyKitten TinyKitten merged commit 7b89c15 into dev Jan 15, 2026
10 checks passed
@TinyKitten TinyKitten deleted the fix/nearby-stations branch January 15, 2026 15:54
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.

2 participants