Skip to content

Commit

Permalink
delete getting user form repository and creating new user
Browse files Browse the repository at this point in the history
  • Loading branch information
Hueter57 committed Nov 8, 2024
1 parent adee1a7 commit 0f76080
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions router/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,8 @@ func (h Handlers) GetMe(c echo.Context) error {

user, err := h.Repository.GetUserByID(c.Request().Context(), userInSession.ID)
if err != nil {
users, err := h.Repository.GetUsers(c.Request().Context())
for _, user := range users {
if user.ID == userInSession.ID {
return c.JSON(http.StatusOK, user)
}
}
if err != nil {
h.Logger.Error("failed to get users from repository", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
// if user not found, create new user
newUser, err := h.Repository.CreateUser(c.Request().Context(), userInSession.Name,
userInSession.DisplayName, userInSession.Admin)
if err != nil {
h.Logger.Error("failed to create user", zap.Error(err))
return echo.NewHTTPError(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, newUser)
h.Logger.Error("failed to get user by ID")
return c.JSON(http.StatusInternalServerError, err)
}
return c.JSON(http.StatusOK, user)
}

0 comments on commit 0f76080

Please sign in to comment.