Skip to content

Conversation

@hikahana
Copy link
Collaborator

@hikahana hikahana commented May 3, 2025

対応Issue

resolve #0

概要

  • クリックされた棟にある部屋を取得するAPI
    • 画像のように1号棟、2号棟も一緒に表示を行う
    • 何号棟か、居室(部屋番号)、教員名、募金金額、ブラックリストかどうかを取得
    • 画像右上にあるような感じで階ごとに選べるようにしたいけどこれはフロントとバックどっちで対応するのがいいんだろ?→バックエンド側で階層もパスクエリに含めて取得を書けるように
      image

sqlクエリ
SELECT buildings.name, building_units.unit_number, floors.floor_number, rooms.room_name, teachers.id, teachers.name, teachers.is_black, COALESCE(SUM(fund_informations.price), 0) FROM buildings INNER JOIN building_units ON (building_units.building_id = buildings.id) INNER JOIN floors ON (floors.building_unit_id = building_units.id) INNER JOIN rooms ON (rooms.floor_id = floors.id) INNER JOIN room_teachers ON (room_teachers.room_id = rooms.id) INNER JOIN teachers ON (teachers.id = room_teachers.teacher_id) LEFT JOIN fund_informations ON (fund_informations.teacher_id = teachers.id) WHERE ((buildings.id = '1') AND (floors.id = '1')) GROUP BY buildings.name, building_units.unit_number, floors.floor_number, rooms.room_name, teachers.id, teachers.name, teachers.is_black ORDER BY building_units.unit_number ASC, floors.floor_number ASC, rooms.room_name ASC, teachers.name ASC

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

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

テスト項目

  • 要望通りか
  • コードレビュー

備考

@hikahana hikahana changed the title 各棟の教員情報を取得するAPI 各棟の各階の教員情報を取得するAPI May 3, 2025
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 3506 to 3534
campusDonationByFloor:
type: object
properties:
teacher_id:
type: integer
building_name:
type: string
unit_number:
type: string
floor_number:
type: string
room_name:
type: string
teacher_name:
type: string
price:
type: integer
is_black:
type: boolean
required:
- teacher_id
- building_name
- unit_number
- floor_number
- room_name
- teacher_name
- price
- is_black

Copy link
Collaborator

Choose a reason for hiding this comment

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

[ask]全部まとめて配列で返してるけど、棟ごとにまとめたりするのはフロントですか?
結構しんどそうだなって思って

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

絶賛作業中なんですけど以下みたいな感じでまとめたいって話で合ってますよね?それは確かにバックエンドで対応したいですね

type CampusDonation struct {
	IsBlack     *bool  `json:"is_black,omitempty"`
	Price       int    `json:"price"`
	RoomName    string `json:"room_name"`
	TeacherId   int    `json:"teacher_id"`
	TeacherName string `json:"teacher_name"`
}

// CampusDonationByFloorAndBuilding 棟ごと
type CampusDonationByFloorAndBuilding struct {
	BuildingId   int          `json:"building_id"`
	BuildingName *string      `json:"building_name,omitempty"`
	Floors       []FloorGroup `json:"floors"`
}

type FloorGroup struct {
	Donations   []CampusDonation `json:"donations"`
	FloorId     *int             `json:"floor_id,omitempty"`
	FloorNumber string           `json:"floor_number"`
}

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.

テストデータないからわかりづらいけど、棟と階でまとめてみた

image

Comment on lines 66 to 74
GroupBy(
goqu.I("buildings.name"),
goqu.I("building_units.unit_number"),
goqu.I("floors.floor_number"),
goqu.I("rooms.room_name"),
goqu.I("teachers.id"),
goqu.I("teachers.name"),
goqu.I("teachers.is_black"),
).
Copy link
Collaborator

Choose a reason for hiding this comment

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

[ask] このGroup Byってどういう意味で使ってる?
棟の名前とか階層とか同じだと一緒になっちゃわないっけ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

なりましたね。priceをsumで返してたのでgroupByが必要になってたです。
そもそもpriceをsumにする必要がなかったので消しました!

Base automatically changed from fix/hikahana/er to develop May 11, 2025 21:05
@cloudflare-workers-and-pages
Copy link

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

Deploying finansu with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5d859d4
Status: ✅  Deploy successful!
Preview URL: https://aeb657a3.finansu.pages.dev
Branch Preview URL: https://feat-hikahana-get-rooms-by-b.finansu.pages.dev

View logs

@Kubosaka
Copy link
Collaborator

あ、ごめん、push先間違えた、リセットします

@hikahana hikahana changed the base branch from develop to fix/hikahana/change-table-name-campus-donations May 16, 2025 07:55
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 +824 to +836
parameters:
- 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.

[imo]
dbでもコメントしたけどyear_idも指定できたほうが良さそう

Comment on lines 58 to 59
groupMap := make(map[int]*generated.CampusDonationByFloorAndBuilding)
for _, r := range campusDonationRecords {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[imo] 型の変換処置関数に切り分けても良さそう
時間あればやってもろて

Copy link
Collaborator

Choose a reason for hiding this comment

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

slackで特定の棟をまとめるみたいなのあったけど、ああいうロジック周りを構造体に持たせてメソッドにするといい感じにドメインロジックを集約できそうだなって思った

IsBlack: r.IsBlack,
})
}
// map→slice
Copy link
Collaborator

Choose a reason for hiding this comment

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

このパッケージ使ってもいいかも
配列の処理とかいい感じに書ける
https://github.com/samber/lo?tab=readme-ov-file#maptoslice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

5d859d4

こんな感じなの??なんかうまく使えてない感じする

Copy link
Collaborator

Choose a reason for hiding this comment

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

良さそう

@hikahana hikahana requested a review from Kubosaka May 25, 2025 10:33
goqu.I("teachers.id").As("teacher_id"),
goqu.I("teachers.name").As("teacher_name"),
goqu.I("rooms.room_name").As("room_name"),
goqu.I("campus_donations.price").As("price"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

[ask] これって値入ってない時エラーならない?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

あ、確かになるかも
collapseみたいなのも一緒に消しちゃってた

Base automatically changed from fix/hikahana/change-table-name-campus-donations to develop September 22, 2025 06:00
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