Skip to content

GetStationsByLineIdList RPC追加#1388

Merged
TinyKitten merged 3 commits into
devfrom
feature/lines-batch
Feb 8, 2026
Merged

GetStationsByLineIdList RPC追加#1388
TinyKitten merged 3 commits into
devfrom
feature/lines-batch

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Feb 8, 2026

Copy link
Copy Markdown
Member

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

Summary by CodeRabbit

  • 新機能
    • 複数の路線IDを指定して駅情報を一括取得できるAPIを追加しました。運輸タイプによる絞り込みにも対応し、まとめて効率的に駅データを取得できます。

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

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TinyKitten TinyKitten self-assigned this Feb 8, 2026
@coderabbitai

coderabbitai Bot commented Feb 8, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

複数の行IDで駅情報を一括取得するAPI/ユースケース/リポジトリ経路が追加され、protoサブモジュール参照が更新されました。新しい非同期メソッド群が公開インターフェースと各実装に導入されています。

Changes

Cohort / File(s) Summary
Submodule Update
stationapi/proto
protoサブモジュール参照をコミット0e77c9f...からb050805...へ更新。
Domain / Repository
stationapi/src/domain/repository/station_repository.rs, stationapi/src/infrastructure/station_repository.rs
StationRepositoryトレイトにget_by_line_id_vec(&[u32])を追加。インフラ実装で空入力短絡、IN句生成、CASE順序付けで複数行IDから駅を取得する内部実装を追加。
UseCase / Traits
stationapi/src/use_case/traits/query.rs, stationapi/src/use_case/interactor/query.rs
QueryUseCaseget_stations_by_line_id_vec(&[u32], TransportTypeFilter)を追加。インタラクタ実装でリポジトリ呼び出し、TransportTypeFilterによる絞り込みと属性更新を行う処理を追加。テスト用モックも対応。
Presentation / gRPC
stationapi/src/presentation/controller/grpc.rs
gRPCトレイトにget_stations_by_line_id_listを追加し、GetStationByLineIdListRequestを受けて内部ユースケースget_stations_by_line_id_vecを呼び、MultipleStationResponseを返す実装を追加。

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant gRPC as gRPC API
    participant UseCase as Query UseCase
    participant Repository as Station Repository
    participant DB as Database

    Client->>gRPC: get_stations_by_line_id_list(line_ids, transport_type)
    gRPC->>UseCase: get_stations_by_line_id_vec(line_ids, transport_type)
    UseCase->>Repository: get_by_line_id_vec(line_ids)
    Repository->>DB: SELECT ... WHERE line_cd IN (...)
    DB-->>Repository: station_rows
    Repository-->>UseCase: Vec<Station>
    UseCase->>UseCase: filter by transport_type / update attributes
    UseCase-->>gRPC: Vec<Station>
    gRPC->>gRPC: build MultipleStationResponse
    gRPC-->>Client: MultipleStationResponse
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • 10mocy

Poem

🐰 線路の列を数えて跳ぶよ
IDを集めて駅を呼ぶよ
IN句で集めて並べ直し
API通して届けるよ
ウサギはぴょんと今日も祝う ✨

🚥 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 プルリクエストのタイトルは、複数のline_idをバッチ処理するRPCの追加という主要な変更を明確に要約しており、変更セット全体の主要な目的と一致している。

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/lines-batch

No actionable comments were generated in the recent review. 🎉


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

@TinyKitten TinyKitten marked this pull request as ready for review February 8, 2026 04:25

@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

🤖 Fix all issues with AI agents
In `@stationapi/src/infrastructure/station_repository.rs`:
- Around line 614-706: get_by_line_id_vec currently orders by s.line_cd which
doesn't preserve the input order from line_ids; change the ORDER BY to use a
CASE expression like ORDER BY CASE l.line_cd WHEN $1 THEN 1 WHEN $2 THEN 2 ...
ELSE 999 END, s.e_sort, s.station_cd so the rows follow the input line_ids order
(same approach as get_by_id_vec). Build that CASE dynamically using the existing
line_ids iteration (the params / query_str construction), keep binding ids to
the query as you already do, and replace the fixed "ORDER BY s.line_cd, s.e_sort
ASC, s.station_cd ASC" with the CASE-based ordering in get_by_line_id_vec.
🧹 Nitpick comments (2)
stationapi/src/domain/repository/station_repository.rs (1)

111-118: モックのフィルタは HashSet+ソートで安定化できます
テスト用途でも順序が不定だと将来の検証で不安定になるので、line_ids を集合化し、結果を決まったキーでソートすると安全です。

♻️ 参考修正案
-        let result: Vec<Station> = self
-            .stations
-            .values()
-            .filter(|station| line_ids.contains(&(station.line_cd as u32)))
-            .cloned()
-            .collect();
-        Ok(result)
+        let line_id_set: std::collections::HashSet<u32> = line_ids.iter().copied().collect();
+        let mut result: Vec<Station> = self
+            .stations
+            .values()
+            .filter(|station| line_id_set.contains(&(station.line_cd as u32)))
+            .cloned()
+            .collect();
+        result.sort_by_key(|s| (s.line_cd, s.station_cd));
+        Ok(result)
stationapi/src/use_case/interactor/query.rs (1)

195-212: 空の line_ids は早期リターンで無駄な処理を省けます
リポジトリ側でも空入力は扱えますが、属性付与まで走らないようにすると軽くなります。

♻️ 参考修正案
     async fn get_stations_by_line_id_vec(
         &self,
         line_ids: &[u32],
         transport_type: TransportTypeFilter,
     ) -> Result<Vec<Station>, UseCaseError> {
+        if line_ids.is_empty() {
+            return Ok(vec![]);
+        }
         let stations = self.station_repository.get_by_line_id_vec(line_ids).await?;

Comment thread stationapi/src/infrastructure/station_repository.rs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TinyKitten TinyKitten merged commit b5dc723 into dev Feb 8, 2026
10 checks passed
@TinyKitten TinyKitten deleted the feature/lines-batch branch February 8, 2026 04:41
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