Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
add emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfmagnate committed Nov 5, 2023
1 parent f38fc6d commit 8f98157
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
6 changes: 4 additions & 2 deletions back/domain/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions back/handler/moneypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
Expand All @@ -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
Expand Down Expand Up @@ -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()})
Expand All @@ -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
Expand Down
33 changes: 21 additions & 12 deletions back/usecase/moneypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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,
})
}
}
Expand All @@ -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"`
}

Expand Down Expand Up @@ -144,18 +148,20 @@ 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{
Name: name,
Description: description,
Type: publicType,
OwnerID: userID,
Emoji: emoji,
}

createdMoneyPool, err := u.db.NewMoneyPool(newMoneyPool)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
}

Expand Down

0 comments on commit 8f98157

Please sign in to comment.