-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[マイページ]部門予算・詳細取得 #915
[マイページ]部門予算・詳細取得 #915
Conversation
var selectFestivalItemForMypageQuery = dialect.Select( | ||
goqu.I("users.name").As("userName"), | ||
goqu.I("financial_records.name").As("financialRecordName"), | ||
goqu.I("divisions.id").As("divisionId"), | ||
goqu.I("divisions.name").As("divisionName"), | ||
goqu.I("festival_items.id").As("festivalItemId"), | ||
goqu.I("festival_items.name").As("festivalItemName"), | ||
goqu.I("years.year"), | ||
goqu.COALESCE(goqu.I("item_budgets.amount"), 0).As("budgetAmount"), | ||
goqu.COALESCE(goqu.I("buy_reports.id"), 0).As("buyReportId"), | ||
goqu.COALESCE(goqu.I("buy_reports.paid_by"), "").As("paidBy"), | ||
goqu.COALESCE(goqu.I("buy_reports.amount"), 0).As("reportAmount"), | ||
goqu.COALESCE(goqu.I("buy_reports.created_at"), "2025-01-29 20:53:44").As("reportDate"), | ||
goqu.COALESCE(goqu.I("buy_statuses.is_packed"), 0).As("isPacked"), | ||
goqu.COALESCE(goqu.I("buy_statuses.is_settled"), 0).As("isSettled")). | ||
From("festival_items"). | ||
InnerJoin(goqu.I("divisions"), goqu.On(goqu.I("festival_items.division_id").Eq(goqu.I("divisions.id")))). | ||
InnerJoin(goqu.I("financial_records"), goqu.On(goqu.I("divisions.financial_record_id").Eq(goqu.I("financial_records.id")))). | ||
InnerJoin(goqu.I("user_groups"), goqu.On(goqu.I("divisions.id").Eq(goqu.I("user_groups.group_id")))). | ||
InnerJoin(goqu.I("users"), goqu.On(goqu.I("users.id").Eq(goqu.I("user_groups.user_id")))). | ||
InnerJoin(goqu.I("years"), goqu.On(goqu.I("financial_records.year_id").Eq(goqu.I("years.id")))). | ||
LeftJoin(goqu.I("item_budgets"), goqu.On(goqu.I("festival_items.id").Eq(goqu.I("item_budgets.festival_item_id")))). | ||
LeftJoin(goqu.I("buy_reports"), goqu.On(goqu.I("festival_items.id").Eq(goqu.I("buy_reports.festival_item_id")))). | ||
LeftJoin(goqu.I("buy_statuses"), goqu.On(goqu.I("buy_reports.id").Eq(goqu.I("buy_statuses.buy_report_id")))). | ||
Order(goqu.I("festival_items.id").Desc()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これで必要なデータとってくる
type FestivalItemForMyPageColumn struct { | ||
UserName string | ||
FinancialRecordName string | ||
DivisionId int | ||
DivisionName string | ||
FestivalItemId int | ||
FestivalItemName string | ||
Year int | ||
BudgetAmount int | ||
BuyReportId int | ||
PaidBy string | ||
ReportAmount int | ||
ReportDate string | ||
IsPacked bool | ||
IsSettled bool | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
取得したdbのデータを入れる用の型
festivalItemForMyPageColumns = append(festivalItemForMyPageColumns, festivalItemForMyPageColumn) | ||
} | ||
|
||
festivalItemDetailsList = convertColumnToGenerated(festivalItemForMyPageColumns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この関数内でdbから取得したデータを整形
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これコード内にもコメント残しておいて欲しいかも
半年後とか忘れてそう。
例:ColumnsをDetailsListの型に合わせてマッピングする。値が無い場合は初期化し、ゼロ値を挿入。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
コードレビューしました!
この動作確認ってuserにdvisionID持たせないとできないですか?
ps.備考欄見落としてました。動作確認良さげでした!
festivalItemForMyPageColumns = append(festivalItemForMyPageColumns, festivalItemForMyPageColumn) | ||
} | ||
|
||
festivalItemDetailsList = convertColumnToGenerated(festivalItemForMyPageColumns) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これコード内にもコメント残しておいて欲しいかも
半年後とか忘れてそう。
例:ColumnsをDetailsListの型に合わせてマッピングする。値が無い場合は初期化し、ゼロ値を挿入。
goqu.COALESCE(goqu.I("buy_reports.id"), 0).As("buyReportId"), | ||
goqu.COALESCE(goqu.I("buy_reports.paid_by"), "").As("paidBy"), | ||
goqu.COALESCE(goqu.I("buy_reports.amount"), 0).As("reportAmount"), | ||
goqu.COALESCE(goqu.I("buy_reports.created_at"), "2025-01-29 20:53:44").As("reportDate"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[imo]
ここありえない数値とかの方いいかも
したとか?
"2000-01-01 00:00:00"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// 予算と支出データ集計 | ||
festivalItemMap := festivalItemMaps[festivalItemForMyPageColumn.DivisionName] | ||
if festivalItemMap == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[imo]
下みたいな方がスッキリしそう。変わんないか?
festivalItemMap, ok := festivalItemMaps[festivalItemForMyPageColumn.DivisionName]
if !ok {
festivalItemMap = make(map[string]FestivalItemWithReport)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
キーの有無判定に使えるならこっち使ったほうが綺麗なので修正しマスタ
mapのキー判定を2つ目の変数で行う
if buyReports == nil { | ||
var buyReportSlice []generated.BuyReportInformation | ||
buyReports = &buyReportSlice | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[imo]
slice定義しなくてもいいかも
} | |
buyReports = &[]generated.BuyReportInformation{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ポインタでの変数代入するには、変数あらかじめ定義しないけないと思ってた!
ありがとう!だいぶスッキリできた🙌
構造体定義部分リファクタリング
buyReport.Amount = &festivalItemForMyPageColumn.ReportAmount | ||
buyReport.ReportDate = &festivalItemForMyPageColumn.ReportDate | ||
|
||
if festivalItemForMyPageColumn.IsSettled { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[imo]
switchの方がかっこいい!
if festivalItemForMyPageColumn.IsSettled { | |
switch { | |
case festivalItemForMyPageColumn.IsSettled: | |
buyReport.Status = &isSettled | |
case festivalItemForMyPageColumn.IsPacked: | |
buyReport.Status = &isPacked | |
default: | |
buyReport.Status = &empty | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
個人的にはifの方が直感的な気もして、可読性は高そう
でもswitchの方が簡潔に書けるのでそっちにしました
条件分岐をifに変更
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolve #914
概要
/festival_items/details/{user_id}
画面スクリーンショット等
URL
スクリーンショット
テスト項目
備考