Skip to content

Commit

Permalink
feat: PatchUserComplete usecase patching both cocktail_id and is_user…
Browse files Browse the repository at this point in the history
…_completed
  • Loading branch information
bblueberries committed Dec 26, 2023
1 parent 7b5a63a commit 1df2aa4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type CreateCheckinDTO struct {
}

type CreateUserCompletedDTO struct {
IsUserCompleted bool `json:"is_user_completed"`
IsUserCompleted bool `json:"is_user_completed" binding:"required"`
CocktailID uint `json:"cocktail_id" binding:"required"`
}
type CreateUserNameDTO struct {
UserName string `json:"user_name"`
UserName string `json:"user_name" binding:"required"`
}
15 changes: 6 additions & 9 deletions src/usecase/user_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,22 @@ func (usecase *UserUsecase) Post(CheckinDTO domain.CreateCheckinDTO) (domain.Che

func (usecase *UserUsecase) PatchUserComplete(id string,userDTO domain.CreateUserCompletedDTO ) (domain.User, error) {
user := domain.User{
UserID: id,
UserName: "",

UserID: id,
}
updatingMap := map[string]interface{}{
"is_user_completed": userDTO.IsUserCompleted,
"cocktail_id": userDTO.CocktailID,
}
err := usecase.UserRepository.UpdateColumn(&user,"is_user_completed",userDTO.IsUserCompleted)
// if(err != nil) {return user,err}
// err = usecase.UserRepository.GetById(&user, id)
err := usecase.UserRepository.UpdateMultipleColumns(&user,updatingMap)
return user, err

}

func (usecase *UserUsecase) PatchUserName(id string,userDTO domain.CreateUserNameDTO ) (domain.User, error) {
user := domain.User{
UserID: id,
IsUserCompleted : false,
}
err := usecase.UserRepository.UpdateColumn(&user,"user_name",userDTO.UserName)
// if(err != nil) {return user,err}
// err = usecase.UserRepository.GetById(&user, id)
return user, err

}
Expand Down

0 comments on commit 1df2aa4

Please sign in to comment.