From 1d8db9efbbe5bb93e74206b0f05200d29f9bee35 Mon Sep 17 00:00:00 2001 From: Walnuts Date: Mon, 6 Nov 2023 12:23:37 +0900 Subject: [PATCH] Add date field to payment request and use it in AddNewPayment function --- back/handler/payment.go | 9 ++++++++- back/usecase/payment.go | 4 ++-- front/src/app/mypage/AddButton.tsx | 1 + go.work.sum | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/back/handler/payment.go b/back/handler/payment.go index e4094a6..e73c604 100644 --- a/back/handler/payment.go +++ b/back/handler/payment.go @@ -61,13 +61,20 @@ func postPayment(c *gin.Context) { Amount float64 `json:"amount"` Description string `json:"description"` IsPlanned bool `json:"is_planned"` + Date string `json:"date"` } if err := c.BindJSON(&paymentRequest); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request"}) return } - err := uc.AddNewPayment(userID, moneyPoolID, paymentRequest.Title, paymentRequest.Amount, paymentRequest.Description, paymentRequest.IsPlanned) + date, err := time.Parse("2006-01-02", paymentRequest.Date) + if err != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "invalid date format, should be YYYY-MM-DD"}) + return + } + + err = uc.AddNewPayment(userID, moneyPoolID, date, paymentRequest.Title, paymentRequest.Amount, paymentRequest.Description, paymentRequest.IsPlanned) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return diff --git a/back/usecase/payment.go b/back/usecase/payment.go index 9d9d440..5b26a6b 100644 --- a/back/usecase/payment.go +++ b/back/usecase/payment.go @@ -9,7 +9,7 @@ import ( ) // AddNewPayment adds a new payment to the specified MoneyPool for a given user. -func (u *Usecase) AddNewPayment(userID string, moneyPoolID string, title string, amount float64, description string, isPlanned bool) error { +func (u *Usecase) AddNewPayment(userID string, moneyPoolID string, Date time.Time, title string, amount float64, description string, isPlanned bool) error { log.Printf("ユーザーID %s のための新規支払い追加を開始します。マネープールID: %s, タイトル: %s", userID, moneyPoolID, title) // Retrieve the MoneyPool to ensure it exists and belongs to the user moneyPool, err := u.db.GetMoneyPool(moneyPoolID) @@ -26,7 +26,7 @@ func (u *Usecase) AddNewPayment(userID string, moneyPoolID string, title string, payment := domain.Payment{ ID: "", MoneyPoolID: moneyPoolID, - Date: time.Now(), // Use current time for payment date + Date: Date, Title: title, Amount: amount, Description: description, diff --git a/front/src/app/mypage/AddButton.tsx b/front/src/app/mypage/AddButton.tsx index dfdf6d9..6e9a7f1 100644 --- a/front/src/app/mypage/AddButton.tsx +++ b/front/src/app/mypage/AddButton.tsx @@ -39,6 +39,7 @@ export function AddButton({ amount: Number(transactionAmount), description: "", is_planned: false, + date: transactionDate, }), }); if (res.ok) { diff --git a/go.work.sum b/go.work.sum index 7343b25..ddd238f 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1,3 +1,4 @@ +cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=