Skip to content

Conversation

@Kubosaka
Copy link
Collaborator

Summary

・購入報告一覧画面にCSVダウンロード機能を追加
・バックエンドAPIで購入報告データをCSV形式で出力する機能を実装
・フロントエンドでCSVダウンロードボタンを実装

Test plan

  • 購入報告一覧画面でCSVダウンロードボタンが表示されること
  • CSVダウンロードボタンをクリックして正しくCSVファイルがダウンロードされること
  • 年度を選択して該当年度のデータがCSVに含まれること
  • CSVのヘッダーとデータが正しい形式で出力されること

🤖 Generated with Claude Code

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

購入報告一覧画面にCSVダウンロード機能を追加するPRです。バックエンドで購入報告データをCSV形式で出力するAPIエンドポイントを実装し、フロントエンドでCSVダウンロードボタンに機能を追加しています。

  • 購入報告データをCSV形式でダウンロードするAPIエンドポイント /buy_reports/csv/download を追加
  • フロントエンドでCSVダウンロードボタンにクリックイベントを実装
  • OpenAPIスキーマにCSVダウンロードエンドポイントの定義を追加

Reviewed Changes

Copilot reviewed 4 out of 8 changed files in this pull request and generated 3 comments.

File Description
view/next-project/src/pages/purchase_report_list/index.tsx CSVダウンロード機能の実装とボタンへのクリックイベント追加
openapi/openapi.yaml CSVダウンロードAPIエンドポイントのOpenAPI定義追加
api/router/router.go CSVダウンロードエンドポイントのルート追加
api/externals/controller/buy_report_controller.go CSVダウンロード機能のコントローラー実装

Comment on lines 143 to 148
const downloadCSV = async () => {
const url = `${process.env.CSR_API_URI}/buy_reports/csv/download?year=${selectedYear}`;
const response = await fetch(url);
const blob = await response.blob();
saveAs(blob, `購入報告_${selectedYear}.csv`);
};
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

エラーハンドリングがないよ〜😅 fetchでAPIコールする時は、レスポンスステータスのチェックとエラー処理を入れないとダメだよ〜💦 バチボコ大事なポイントだから忘れちゃダメだよ!response.okとかでチェックして、エラーの時はユーザーに分かりやすくエラー表示してね〜✨

Copilot generated this review using guidance from repository custom instructions.
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 166 to 184
// データ書き込み
for _, detail := range buyReportDetails {
yearStr := ""
if detail.Year != nil {
yearStr = strconv.Itoa(*detail.Year)
}

record := []string{
strconv.Itoa(detail.Id),
strconv.Itoa(detail.Amount),
detail.DivisionName,
detail.FestivalItemName,
detail.FinancialRecordName,
detail.PaidBy,
detail.ReportDate,
yearStr,
strconv.FormatBool(detail.IsPacked),
strconv.FormatBool(detail.IsSettled),
}
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

CSVのデータにnilチェックが足りないよ〜😱 DivisionNameとかの文字列フィールドがnilだったらヤバたにえんことになるよ💦 しっかりnil チェック入れて安全にCSV出力できるようにしてね!それな〜✨

Copilot generated this review using guidance from repository custom instructions.
Comment on lines 182 to 183
strconv.FormatBool(detail.IsPacked),
strconv.FormatBool(detail.IsSettled),
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

bool値をCSVに出力する時に「true/false」だと日本語のCSVとしてはちょっと微妙じゃない?🤔 「はい/いいえ」とか「済/未」みたいな日本語表記にした方がユーザーフレンドリーだと思うよ〜!わかりみが深い改善ポイントだよ✨

Copilot generated this review using guidance from repository custom instructions.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Chikuwa0141
Copy link
Collaborator

各項目の並べ方は

年度 | 日付 | 局名 | 部門 | 物品 | 立替者 | 金額 | 封詰め | 清算完了

でお願いします。(購入報告一覧の表示に「年度」を追加した形)
「封詰め」と「清算完了」は「未」「済」で出力するようにお願いします。

文字コードは現在のUTF-8でいい気がしてますが、財務に確認とってから判断したいと思います。

@Kubosaka
Copy link
Collaborator Author

@Chikuwa0141
修正しました!!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 8 changed files in this pull request and generated 3 comments.

Comment on lines +144 to +150
const url = `${process.env.CSR_API_URI}/buy_reports/csv/download?year=${selectedYear}`;
try {
const response = await fetch(url);
const blob = await response.blob();
saveAs(blob, `購入報告_${selectedYear}.csv`);
} catch (error) {
console.error('Failed to download CSV:', error);
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

やばたにえん!😅 コンソールだけのエラーログじゃユーザーがわからないよ〜!エラー処理でユーザーに分かりやすいメッセージ表示するか、トースト通知とか入れた方がよくない?💦「CSVダウンロードに失敗しました」みたいな感じで!

Copilot uses AI. Check for mistakes.
reportDateStr := detail.ReportDate
t, err := time.Parse(time.RFC3339, reportDateStr)
if err == nil {
reportDateStr = t.Format("2006年1月2日")
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

えっと〜!🤔 time.Parseでエラーハンドリングがちょっとやばい感じ!err != nilの場合、元のreportDateStrがそのまま使われちゃうから、RFC3339形式のままCSVに出力されちゃうよ〜💦 デフォルト値設定するか、エラー時の処理をちゃんと決めた方がいいかも!

Suggested change
reportDateStr = t.Format("2006年1月2日")
reportDateStr = t.Format("2006年1月2日")
} else {
reportDateStr = "不明"

Copilot uses AI. Check for mistakes.
// GetBuyReportsCsvDownload
func (s *buyReportController) GetBuyReportsCsvDownload(c echo.Context) error {
ctx := c.Request().Context()
year := c.QueryParam("year")
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

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

あれ〜?🤨 yearパラメータのバリデーションがないよ〜!空文字列や無効な値が来たらどうするの?せめて空チェックか数値チェックしよう!if year == "" { return c.String(http.StatusBadRequest, "year parameter is required") }みたいな感じで!💪

Suggested change
year := c.QueryParam("year")
year := c.QueryParam("year")
if year == "" {
return c.String(http.StatusBadRequest, "year parameter is required")
}
if _, err := strconv.Atoi(year); err != nil {
return c.String(http.StatusBadRequest, "year parameter must be a valid integer")
}

Copilot uses AI. Check for mistakes.
@Chikuwa0141
Copy link
Collaborator

カラム等の修正確認しました!
文字コードは予算管理と同じくShift-JISでお願いします!

}

func makeBuyReportCSV(writer http.ResponseWriter, records [][]string) error {
// Shift_JISエンコーディング用の変換を設定
Copy link
Collaborator

Choose a reason for hiding this comment

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

文字コード対応ありがとうございます!
動作いい感じなのでこれでマージしましょう

@Chikuwa0141 Chikuwa0141 merged commit 722a6eb into develop Sep 17, 2025
3 checks passed
@Chikuwa0141 Chikuwa0141 deleted the feat/kubosaka/add-buy-report-csv branch September 17, 2025 06:28
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