Skip to content

Conversation

@hikahana
Copy link
Collaborator

@hikahana hikahana commented May 1, 2025

対応Issue

resolve #0
なし

概要

  • 棟を一覧で表示し、各棟の募金額を取得するAPI
    • 棟に紐づいている教師の募金を合算する。
    • 棟ごとに合算した募金額を返す。
      image
      このデザインに沿って作成しました。
      おそらく年度ごとの取得になるため、年度ごとで取得できるようにしてます。
      sqlクエリ自体は以下の通りです。
SELECT
  buildings.id AS building_id,
  buildings.name AS building_name,
  fund_informations.price AS price,
  years.year AS year
FROM fund_informations
JOIN teachers ON fund_informations.teacher_id = teachers.id
JOIN users ON fund_informations.user_id = users.id
JOIN departments ON teachers.department_id = departments.id
JOIN room_teachers ON room_teachers.teacher_id = teachers.id
JOIN rooms ON room_teachers.room_id = rooms.id
JOIN floors ON rooms.floor_id = floors.id
JOIN building_units ON floors.building_unit_id = building_units.id
JOIN buildings ON building_units.building_id = buildings.id
JOIN year_periods ON fund_informations.created_at > year_periods.started_at AND fund_informations.created_at < year_periods.ended_at
JOIN years ON year_periods.year_id = years.id
WHERE years.year = 2025
ORDER BY fund_informations.updated_at DESC;

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

  • URL
    スクリーンショット
    image

テスト項目

  • 動作は多分ok。見ても見なくても
  • 要望通りになっているか
  • コードレビュー一応

備考

APIどこに生やせばいいか迷ってとりあえずでfund_informationsに生やしました。
ここら辺話してから作成に取り掛かればよかったです。

Copy link
Collaborator

@Kubosaka Kubosaka left a comment

Choose a reason for hiding this comment

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

フロントで収支管理がfund_informationsになってたからどうしよ

@hikahana hikahana changed the base branch from develop to fix/hikahana/er May 2, 2025 06:24
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented May 2, 2025

Deploying finansu with  Cloudflare Pages  Cloudflare Pages

Latest commit: a0cccf1
Status: ✅  Deploy successful!
Preview URL: https://d032a9db.finansu.pages.dev
Branch Preview URL: https://feat-hikahana-add-get-depart.finansu.pages.dev

View logs

@hikahana hikahana requested a review from Kubosaka May 4, 2025 23:06
@hikahana
Copy link
Collaborator Author

hikahana commented May 5, 2025

@Kubosaka
募金登録も収支管理に含めるなら、fund_informationsでもいい感ありますけどこれもMTで確認したいですね。

@hikahana
Copy link
Collaborator Author

hikahana commented May 9, 2025

APIのパスをcampus_donationに変更するためいったんdraftにします。
feat/hikahana/get-rooms-by-buildingのブランチ取り込んで作業します。

@hikahana hikahana marked this pull request as draft May 9, 2025 07:22
Base automatically changed from fix/hikahana/er to develop May 11, 2025 21:05
@hikahana hikahana marked this pull request as ready for review May 15, 2025 10:27
@hikahana hikahana changed the base branch from develop to fix/hikahana/change-table-name-campus-donations May 16, 2025 07:51
@hikahana hikahana changed the base branch from fix/hikahana/change-table-name-campus-donations to feat/hikahana/get-rooms-by-building May 16, 2025 07:56
Copy link
Collaborator

@Kubosaka Kubosaka left a comment

Choose a reason for hiding this comment

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

とりあえずコメ

Comment on lines +825 to +836
- name: building_id
in: path
required: true
schema:
type: integer
description: ID of the building
- name: floor_id
in: path
required: true
schema:
type: integer
description: ID of the floor
Copy link
Collaborator

Choose a reason for hiding this comment

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

こっちも年度かな!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

これ違うprの方だと思う!
からこれは一旦考慮しない


func (fir *campusDonationRepository) AllBuildingsByPeriod(c context.Context, year string) (*sql.Rows, error) {

db := goqu.Dialect("mysql")
Copy link
Collaborator

Choose a reason for hiding this comment

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

dialectはどっかで定義してると思う

Copy link
Collaborator

Choose a reason for hiding this comment

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

file名タイポってる
cmapus_donation_controller.go

@hikahana hikahana requested a review from Kubosaka May 25, 2025 10:34
Comment on lines 125 to 145
for rows.Next() {
var buildingTotal domain.CampusDonationBuilding
if err := rows.Scan(&buildingTotal.Id, &buildingTotal.Name, &buildingTotal.Price); err != nil {
return nil, err
}
if b, exists := aggregated[buildingTotal.Id]; exists {
if b.TotalPrice == nil {
b.TotalPrice = new(int)
}
*b.TotalPrice += buildingTotal.Price
} else {
id := buildingTotal.Id
name := buildingTotal.Name
price := buildingTotal.Price
aggregated[buildingTotal.Id] = &BuildingTotal{
Id: &id,
Name: &name,
TotalPrice: &price,
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[imo] nest深いからcontinueとか使ってあさくできたりする?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

296d728
一次対応

Comment on lines +86 to +88
goqu.I("buildings.id"),
goqu.I("buildings.name"),
goqu.I("campus_donations.price"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

sumとか集計関数つかったらusecaseの処理楽になるのかな、まあどっちでも

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

棟ごとに分けるの実装するのめんどみがあるからusecaseで処理させます

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.

3 participants