Skip to content

feat: 学内募金APIを追加#1085

Merged
hikahana merged 8 commits intodevelopfrom
feat/hikahana/campus-donation-building-floors-api
May 5, 2026
Merged

feat: 学内募金APIを追加#1085
hikahana merged 8 commits intodevelopfrom
feat/hikahana/campus-donation-building-floors-api

Conversation

@hikahana
Copy link
Copy Markdown
Collaborator

@hikahana hikahana commented Apr 20, 2026

対応Issue

resolve #0

概要

  • 指定年度・棟グループ・任意フロアに紐づく教員別の学内募金情報を取得するAPIを追加しました
  • APIパスを GET /campus_donations/years/{year}/group_keys/{group_key}/floors?floor_number={floor_number} に変更しました
  • POST /campus_donations で学内募金を登録できるようにしました
  • PUT /campus_donations/{id} で学内募金を更新できるようにしました
  • 登録/更新APIの項目はDBに合わせて userId, teacherId, yearId, price, receivedAt にしています
  • group_key はOpenAPI schemaのenumとして定義し、Go/フロントの生成コードから型安全に利用できるようにしました
  • 募金額がない教員は totalPrice: 0 で返すようにしています
  • make gen でGo/フロントの生成コードを更新しました

画面スクリーンショット等

image image

テスト項目

  • go test ./internals/usecase/...
  • go test ./...
  • git diff --check
  • make gen
  • Swagger UIから GET /campus_donations/years/{year}/group_keys/{group_key}/floors?floor_number={floor_number} を実行し、指定した group_key の棟だけ返ること
  • Swagger UIから floor_number なしで実行し、指定年度・指定棟グループの全フロアが返ること
  • Swagger UIから POST /campus_donations を実行し、登録結果が返ること
  • Swagger UIから PUT /campus_donations/{id} を実行し、更新結果が返ること
  • 募金データがない教員の totalPrice0 で返ること

備考

登録/更新API request例

{
  "userId": 1,
  "teacherId": 1,
  "yearId": 1,
  "price": 2000,
  "receivedAt": "2026-04-28"
}

動作確認用リクエスト例

curl 'http://localhost:1323/campus_donations/years/2025/group_keys/mechanical_civil_engineering/floors?floor_number=5'
curl 'http://localhost:1323/campus_donations/years/2025/group_keys/mechanical_civil_engineering/floors'

group_key

通常の棟グループは棟名の英語スネークケースで管理します。その他は other で管理します。

@hikahana hikahana self-assigned this Apr 20, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements a new API endpoint to retrieve campus donation information categorized by building and floor for a specific year. The changes span the entire stack, including OpenAPI specifications, frontend hooks, and backend layers (handler, usecase, repository), supported by new test fixtures and integration tests. Feedback focuses on optimizing the repository's SQL query for better performance on large datasets and addressing potential data integrity risks when joining building records by name.

Comment on lines +29 to +40
donationTotalsByTeacher := dialect.
Select(
goqu.I("campus_donations.teacher_id").As("teacher_id"),
goqu.SUM(goqu.I("campus_donations.price")).As("total_price"),
).
From(goqu.T("campus_donations")).
InnerJoin(
goqu.T("years"),
goqu.On(goqu.I("campus_donations.year_id").Eq(goqu.I("years.id"))),
).
Where(goqu.I("years.year").Eq(year)).
GroupBy(goqu.I("campus_donations.teacher_id"))
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.

medium

The subquery donationTotalsByTeacher filters by year but does not filter by building or floor. While this is logically correct because it's joined later on teacher_id, it might be more efficient to include building/floor filters in the subquery if the campus_donations table is very large, to reduce the number of rows processed in the aggregation.

InnerJoin(
goqu.T("buildings").As("selected_building"),
goqu.On(
goqu.I("buildings.name").Eq(goqu.I("selected_building.name")),
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.

medium

Joining on buildings.name to group units assumes that building names are unique identifiers for a group of units. If there's any risk of different buildings having the same name, this could lead to incorrect data aggregation. Consider if a more robust grouping mechanism (like a parent_building_id) is available or needed in the future.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 22, 2026

Deploying finansu with  Cloudflare Pages  Cloudflare Pages

Latest commit: d15d5b0
Status: ✅  Deploy successful!
Preview URL: https://b4d8e536.finansu.pages.dev
Branch Preview URL: https://feat-hikahana-campus-donatio.finansu.pages.dev

View logs

@hikahana hikahana changed the title feat: 各棟の各階の学内募金教員情報取得APIを追加 feat: 学内募金APIを追加 May 2, 2026
@Chikuwa0141 Chikuwa0141 self-requested a review May 3, 2026 07:11
Copy link
Copy Markdown
Collaborator

@Chikuwa0141 Chikuwa0141 left a comment

Choose a reason for hiding this comment

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

「回収済みと未回収をどう表すか」と「テストやってて気づいたこと」を書きましたー

goqu.I("rooms.room_name").As("room_name"),
goqu.I("teachers.id").As("teacher_id"),
goqu.I("teachers.name").As("teacher_name"),
goqu.COALESCE(goqu.I("donation_totals.total_price"), 0).As("total_price"),
Copy link
Copy Markdown
Collaborator

@Chikuwa0141 Chikuwa0141 May 3, 2026

Choose a reason for hiding this comment

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

仕様書

### 回収済み/未回収の判定
- 金額が登録済み(または募金レコードが存在)なら回収済み
- 未登録なら未回収

みたいに回収済みの0円なのか未回収なのかわかるようにしたいからnullのままはどう?
それともisDonatedとか追加する?

Comment thread api/test/sample_test.go
Comment on lines 69 to 76
fixtures, err = testfixtures.New(
testfixtures.Database(db), // You database connection
testfixtures.Dialect("mysql"), // Available: "postgresql", "timescaledb", "mysql", "mariadb", "sqlite" and "sqlserver"
testfixtures.Directory("fixtures"), // The directory containing the YAML files
)
if err != nil {
fmt.Printf("Error creating fixtures: %v\n", err)
return
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

今回の編集範囲じゃないけどテスト実行中に気づいたこと書いておきます

テストのためにmake run-testをするところ、間違えてローカルホスト側で go test ./... を実行した際に ok と表示された。しかし、go test -v ./test で確認すると fixture 作成に失敗していた。(finansu_test_db作って、マイグレーション当てたらmake run-testでちゃんと動いた)

fixture 作成時にエラーが起きても、ここで return して m.Run() が呼ばれないため、テスト未実行のまま go test が成功扱いになる問題を見つけた。

@Chikuwa0141 Chikuwa0141 self-requested a review May 4, 2026 02:50
Copy link
Copy Markdown
Collaborator

@Chikuwa0141 Chikuwa0141 left a comment

Choose a reason for hiding this comment

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

LGTM

@hikahana hikahana merged commit 74485d9 into develop May 5, 2026
1 check passed
@hikahana hikahana deleted the feat/hikahana/campus-donation-building-floors-api branch May 5, 2026 07:13
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