Skip to content

Commit

Permalink
feat: Update first fetches the user instead of building a new entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Knoblauchpilze committed Mar 28, 2024
1 parent e305ea6 commit 013e2b6
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/server/controllers/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,19 @@ func updateUser(c echo.Context, repo repositories.UserRepository) error {
return c.JSON(http.StatusBadRequest, "Invalid user syntax")
}

user := communication.FromUserDtoRequest(userDtoRequest)
user.Id = id
user, err := repo.Get(c.Request().Context(), id)
if err != nil {
if errors.IsErrorWithCode(err, db.NoMatchingSqlRows) {
return c.JSON(http.StatusNotFound, "No such user")
}

return c.JSON(http.StatusInternalServerError, err)
}

c.Logger().Infof("fetched %+v", user)

user.Email = userDtoRequest.Email
user.Password = userDtoRequest.Password

user, err = repo.Update(c.Request().Context(), user)
if err != nil {
Expand Down

0 comments on commit 013e2b6

Please sign in to comment.