From 8f98157251246fb8dbb626128fda6a5086b8f69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=B2=E6=8D=97=E3=82=BC=E3=83=9F?= <47470998+wolfmagnate@users.noreply.github.com> Date: Sun, 5 Nov 2023 13:34:27 +0900 Subject: [PATCH] add emoji --- back/domain/item.go | 6 ++++-- back/handler/moneypool.go | 6 ++++-- back/usecase/moneypool.go | 33 +++++++++++++++++++++------------ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/back/domain/item.go b/back/domain/item.go index 2020d08..cff2f26 100644 --- a/back/domain/item.go +++ b/back/domain/item.go @@ -42,8 +42,10 @@ func (d *dbImpl) GetItemsByUserID(userID string) ([]Item, error) { // UpdateItem updates an existing item. func (d *dbImpl) UpdateItem(item Item) error { - query := `UPDATE item SET name = :name, creator_id = :creator_id WHERE id = :id` - _, err := d.db.Exec(query, item) + // Use positional parameters with $1, $2, etc. + query := `UPDATE item SET name = $1, creator_id = $2 WHERE id = $3` + // Use the Exec function with the struct's fields passed in the order of the parameters. + _, err := d.db.Exec(query, item.Name, item.CreatorID, item.ID) if err != nil { return fmt.Errorf("error updating item: %v", err) } diff --git a/back/handler/moneypool.go b/back/handler/moneypool.go index 9ceb5c3..3236e52 100644 --- a/back/handler/moneypool.go +++ b/back/handler/moneypool.go @@ -120,6 +120,7 @@ func createMoneyPool(c *gin.Context) { Name string `json:"name"` Description string `json:"description"` Type string `json:"type"` + Emoji string `json:"emoji"` } if err := c.BindJSON(&request); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -129,7 +130,7 @@ func createMoneyPool(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"error": "request type does not match any options"}) return } - response, err := uc.AddMoneyPool(userID, request.Name, request.Description, request.Type) + response, err := uc.AddMoneyPool(userID, request.Name, request.Description, request.Type, request.Emoji) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return @@ -157,6 +158,7 @@ func updateMoneyPool(c *gin.Context) { Name string `json:"name"` Description string `json:"description"` Type string `json:"type"` + Emoji string `json:"emoji"` } if err := c.BindJSON(&request); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) @@ -166,7 +168,7 @@ func updateMoneyPool(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"error": "request type does not match any options"}) return } - response, err := uc.UpdateMoneyPool(userID, moneyPoolID, request.Name, request.Description, request.Type) + response, err := uc.UpdateMoneyPool(userID, moneyPoolID, request.Name, request.Description, request.Type, request.Emoji) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return diff --git a/back/usecase/moneypool.go b/back/usecase/moneypool.go index 570a036..5901533 100644 --- a/back/usecase/moneypool.go +++ b/back/usecase/moneypool.go @@ -13,8 +13,9 @@ type MoneyPoolSummary struct { ID string `json:"id"` Name string `json:"name"` // このIDのMoneyPoolに紐づくPlanではない実際の支払いの総額 - Sum float64 `json:"sum"` - Type string `json:"type"` + Sum float64 `json:"sum"` + Type string `json:"type"` + Emoji string `json:"emoji"` } // MoneyPoolsSummaryResponse @@ -40,10 +41,11 @@ func (u *Usecase) GetMoneyPoolsSummary(userID string, loginUserID string) (Money return MoneyPoolsSummaryResponse{}, balanceErr } pools = append(pools, MoneyPoolSummary{ - ID: pool.ID, - Name: pool.Name, - Sum: sum, - Type: pool.Type, + ID: pool.ID, + Name: pool.Name, + Sum: sum, + Type: pool.Type, + Emoji: pool.Emoji, }) } else if loginUserID != "" { shared, shareErr := u.db.IsMoneyPoolSharedWithUser(pool.ID, loginUserID) @@ -58,10 +60,11 @@ func (u *Usecase) GetMoneyPoolsSummary(userID string, loginUserID string) (Money return MoneyPoolsSummaryResponse{}, balanceErr } pools = append(pools, MoneyPoolSummary{ - ID: pool.ID, - Name: pool.Name, - Sum: sum, - Type: pool.Type, + ID: pool.ID, + Name: pool.Name, + Sum: sum, + Type: pool.Type, + Emoji: pool.Emoji, }) } } @@ -84,6 +87,7 @@ type MoneyPoolResponse struct { Name string `json:"name"` Description string `json:"description"` Type string `json:"type"` + Emoji string `json:"emoji"` Payments []PaymentSummary `json:"payments"` } @@ -144,11 +148,12 @@ func (u Usecase) GetMoneyPool(userID string, loginUserID string, moneyPoolID str Description: moneyPool.Description, Type: string(moneyPool.Type), Payments: paymentSummaries, + Emoji: moneyPool.Emoji, }, nil } // AddMoneyPool adds a new money pool to the database and logs the process in Japanese. -func (u Usecase) AddMoneyPool(userID string, name string, description string, publicType string) (MoneyPoolResponse, error) { +func (u Usecase) AddMoneyPool(userID string, name string, description string, publicType string, emoji string) (MoneyPoolResponse, error) { log.Printf("ユーザーID: %sによる新しいマネープールの作成を開始します。名前: %s", userID, name) newMoneyPool := domain.MoneyPool{ @@ -156,6 +161,7 @@ func (u Usecase) AddMoneyPool(userID string, name string, description string, pu Description: description, Type: publicType, OwnerID: userID, + Emoji: emoji, } createdMoneyPool, err := u.db.NewMoneyPool(newMoneyPool) @@ -171,11 +177,12 @@ func (u Usecase) AddMoneyPool(userID string, name string, description string, pu Description: createdMoneyPool.Description, Type: string(createdMoneyPool.Type), Payments: []PaymentSummary{}, // No payments right after creation + Emoji: createdMoneyPool.Emoji, }, nil } // UpdateMoneyPool updates an existing money pool and logs the process in Japanese. -func (u Usecase) UpdateMoneyPool(userID string, moneyPoolID string, name string, description string, publicationType string) (MoneyPoolResponse, error) { +func (u Usecase) UpdateMoneyPool(userID string, moneyPoolID string, name string, description string, publicationType string, emoji string) (MoneyPoolResponse, error) { log.Printf("ユーザーID: %sがマネープールID: %sを更新しようとしています。", userID, moneyPoolID) existingMoneyPool, err := u.db.GetMoneyPool(moneyPoolID) @@ -195,6 +202,7 @@ func (u Usecase) UpdateMoneyPool(userID string, moneyPoolID string, name string, Description: description, Type: publicationType, OwnerID: userID, + Emoji: emoji, } err = u.db.UpdateMoneyPool(updatedMoneyPool) @@ -209,6 +217,7 @@ func (u Usecase) UpdateMoneyPool(userID string, moneyPoolID string, name string, Name: updatedMoneyPool.Name, Description: updatedMoneyPool.Description, Type: string(updatedMoneyPool.Type), + Emoji: updatedMoneyPool.Emoji, }, nil }