Skip to content
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

Merged
merged 10 commits into from
Feb 3, 2025

Conversation

Kubosaka
Copy link
Collaborator

@Kubosaka Kubosaka commented Jan 31, 2025

resolve #914

概要

  • ここの一覧表示のAPIです
    スクリーンショット 2025-01-31 11 28 32
  • usecaseの処理が長くなったので、1つだけで出します
  • GET /festival_items/details/{user_id}
    • userが属する部門(division)の予算・支出をなどを返します
    • クエリパラメータでyearを渡すと、年度のものを返します
[
  {
    "divisionTotal": {
      "budget": 100000,
      "expense": 10000,
      "balance": 90000
    },
    "financialRecordName": "企画局",
    "divisionName": "ビンゴ部門",
    "festivalItems": [
      {
        "festivalItemTotal": {
          "budget": 100000,
          "expense": 10000,
          "balance": 90000
        },
        "festivalItemName": "ビンゴ景品",
        "buyReports": [
          {
            "id": 1,
            "buyReportName": "段ボール",
            "amount": 1000,
            "reportDate": "2024-01-01",
            "status": "確認中"
          }
        ]
      }
    ]
  }
]

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

  • URL
    スクリーンショット

テスト項目

備考

  • 動作確認のためにテーブルにデータ追加する必要があります
    • financial_records
    • divisions
    • user_groups
    • festival_items
    • item_budgets
    • buy_reports
    • buy_status

@Kubosaka Kubosaka changed the base branch from develop to feat/kubosaka/intro-minio-client-go January 31, 2025 02:37
@Kubosaka Kubosaka self-assigned this Jan 31, 2025
Comment on lines 237 to 261
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())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

これで必要なデータとってくる

Comment on lines +16 to +31
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
}
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

この関数内でdbから取得したデータを整形

Copy link
Collaborator

Choose a reason for hiding this comment

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

これコード内にもコメント残しておいて欲しいかも
半年後とか忘れてそう。

例:ColumnsをDetailsListの型に合わせてマッピングする。値が無い場合は初期化し、ゼロ値を挿入。

Base automatically changed from feat/kubosaka/intro-minio-client-go to develop January 31, 2025 07:17
Copy link
Collaborator

@hikahana hikahana left a comment

Choose a reason for hiding this comment

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

コードレビューしました!
この動作確認ってuserにdvisionID持たせないとできないですか?

ps.備考欄見落としてました。動作確認良さげでした!

api/internals/usecase/festival_item_usecase.go Outdated Show resolved Hide resolved
api/internals/usecase/festival_item_usecase.go Outdated Show resolved Hide resolved
festivalItemForMyPageColumns = append(festivalItemForMyPageColumns, festivalItemForMyPageColumn)
}

festivalItemDetailsList = convertColumnToGenerated(festivalItemForMyPageColumns)
Copy link
Collaborator

Choose a reason for hiding this comment

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

これコード内にもコメント残しておいて欲しいかも
半年後とか忘れてそう。

例:ColumnsをDetailsListの型に合わせてマッピングする。値が無い場合は初期化し、ゼロ値を挿入。

api/externals/repository/festival_item_repository.go Outdated Show resolved Hide resolved
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"),
Copy link
Collaborator

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"

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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)
}

Copy link
Collaborator Author

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
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[imo]
slice定義しなくてもいいかも

Suggested change
}
buyReports = &[]generated.BuyReportInformation{}

Copy link
Collaborator Author

@Kubosaka Kubosaka Feb 2, 2025

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[imo]
switchの方がかっこいい!

Suggested change
if festivalItemForMyPageColumn.IsSettled {
switch {
case festivalItemForMyPageColumn.IsSettled:
buyReport.Status = &isSettled
case festivalItemForMyPageColumn.IsPacked:
buyReport.Status = &isPacked
default:
buyReport.Status = &empty
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

個人的にはifの方が直感的な気もして、可読性は高そう
でもswitchの方が簡潔に書けるのでそっちにしました
条件分岐をifに変更

@Kubosaka Kubosaka requested a review from hikahana February 2, 2025 10:58
Copy link
Collaborator

@hikahana hikahana left a comment

Choose a reason for hiding this comment

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

LGTM

@Kubosaka Kubosaka merged commit ab57691 into develop Feb 3, 2025
2 checks passed
@Kubosaka Kubosaka deleted the feat/kuboska/create_buy-_report_api branch February 3, 2025 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

マイページAPIの作成
2 participants