Skip to content

Commit

Permalink
Add date field to payment request and use it in
Browse files Browse the repository at this point in the history
AddNewPayment function
  • Loading branch information
walnuts1018 committed Nov 6, 2023
1 parent 782b75e commit 1d8db9e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion back/handler/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions back/usecase/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions front/src/app/mypage/AddButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function AddButton({
amount: Number(transactionAmount),
description: "",
is_planned: false,
date: transactionDate,
}),
});
if (res.ok) {
Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 1d8db9e

Please sign in to comment.