-
Notifications
You must be signed in to change notification settings - Fork 2
購入報告CSVダウンロード機能追加 #1019
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
購入報告CSVダウンロード機能追加 #1019
Conversation
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.
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ダウンロード機能のコントローラー実装 |
| 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`); | ||
| }; |
Copilot
AI
Sep 16, 2025
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.
エラーハンドリングがないよ〜😅 fetchでAPIコールする時は、レスポンスステータスのチェックとエラー処理を入れないとダメだよ〜💦 バチボコ大事なポイントだから忘れちゃダメだよ!response.okとかでチェックして、エラーの時はユーザーに分かりやすくエラー表示してね〜✨
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.
| // データ書き込み | ||
| 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), | ||
| } |
Copilot
AI
Sep 16, 2025
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.
CSVのデータにnilチェックが足りないよ〜😱 DivisionNameとかの文字列フィールドがnilだったらヤバたにえんことになるよ💦 しっかりnil チェック入れて安全にCSV出力できるようにしてね!それな〜✨
| strconv.FormatBool(detail.IsPacked), | ||
| strconv.FormatBool(detail.IsSettled), |
Copilot
AI
Sep 16, 2025
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.
bool値をCSVに出力する時に「true/false」だと日本語のCSVとしてはちょっと微妙じゃない?🤔 「はい/いいえ」とか「済/未」みたいな日本語表記にした方がユーザーフレンドリーだと思うよ〜!わかりみが深い改善ポイントだよ✨
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.
|
各項目の並べ方は 年度 | 日付 | 局名 | 部門 | 物品 | 立替者 | 金額 | 封詰め | 清算完了 でお願いします。(購入報告一覧の表示に「年度」を追加した形) 文字コードは現在のUTF-8でいい気がしてますが、財務に確認とってから判断したいと思います。 |
|
@Chikuwa0141 |
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.
Pull Request Overview
Copilot reviewed 4 out of 8 changed files in this pull request and generated 3 comments.
| 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); |
Copilot
AI
Sep 17, 2025
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.
やばたにえん!😅 コンソールだけのエラーログじゃユーザーがわからないよ〜!エラー処理でユーザーに分かりやすいメッセージ表示するか、トースト通知とか入れた方がよくない?💦「CSVダウンロードに失敗しました」みたいな感じで!
| reportDateStr := detail.ReportDate | ||
| t, err := time.Parse(time.RFC3339, reportDateStr) | ||
| if err == nil { | ||
| reportDateStr = t.Format("2006年1月2日") |
Copilot
AI
Sep 17, 2025
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.
えっと〜!🤔 time.Parseでエラーハンドリングがちょっとやばい感じ!err != nilの場合、元のreportDateStrがそのまま使われちゃうから、RFC3339形式のままCSVに出力されちゃうよ〜💦 デフォルト値設定するか、エラー時の処理をちゃんと決めた方がいいかも!
| reportDateStr = t.Format("2006年1月2日") | |
| reportDateStr = t.Format("2006年1月2日") | |
| } else { | |
| reportDateStr = "不明" |
| // GetBuyReportsCsvDownload | ||
| func (s *buyReportController) GetBuyReportsCsvDownload(c echo.Context) error { | ||
| ctx := c.Request().Context() | ||
| year := c.QueryParam("year") |
Copilot
AI
Sep 17, 2025
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.
あれ〜?🤨 yearパラメータのバリデーションがないよ〜!空文字列や無効な値が来たらどうするの?せめて空チェックか数値チェックしよう!if year == "" { return c.String(http.StatusBadRequest, "year parameter is required") }みたいな感じで!💪
| 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") | |
| } |
|
カラム等の修正確認しました! |
| } | ||
|
|
||
| func makeBuyReportCSV(writer http.ResponseWriter, records [][]string) error { | ||
| // Shift_JISエンコーディング用の変換を設定 |
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.
文字コード対応ありがとうございます!
動作いい感じなのでこれでマージしましょう
Summary
・購入報告一覧画面にCSVダウンロード機能を追加
・バックエンドAPIで購入報告データをCSV形式で出力する機能を実装
・フロントエンドでCSVダウンロードボタンを実装
Test plan
🤖 Generated with Claude Code