Skip to content

Commit

Permalink
Merge pull request #411 from cho4036/develop
Browse files Browse the repository at this point in the history
bugfix. fix update-my-profile
  • Loading branch information
ktkfree authored Apr 22, 2024
2 parents 1b7a16d + 922ce3e commit f02321d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
14 changes: 7 additions & 7 deletions internal/delivery/http/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func (u UserHandler) GetMyProfile(w http.ResponseWriter, r *http.Request) {
// @Security JWT
func (u UserHandler) UpdateMyProfile(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
_, ok := vars["organizationId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("organizationId not found in path"), "C_INVALID_ORGANIZATION_ID", ""))
return
Expand Down Expand Up @@ -535,16 +535,16 @@ func (u UserHandler) UpdateMyProfile(w http.ResponseWriter, r *http.Request) {
}

ctx := r.Context()
var user model.User
if err = serializer.Map(r.Context(), input, &user); err != nil {
log.Error(r.Context(), err)
user, err := u.usecase.Get(r.Context(), requestUserInfo.GetUserId())
if err != nil {
ErrorJSON(w, r, err)
return
}
user.Name = input.Name
user.Email = input.Email
user.Department = input.Department

user.ID = requestUserInfo.GetUserId()
user.OrganizationId = organizationId
resUser, err := u.usecase.Update(ctx, &user)
resUser, err := u.usecase.Update(ctx, user)
if err != nil {
if _, status := httpErrors.ErrorResponse(err); status == http.StatusNotFound {
ErrorJSON(w, r, httpErrors.NewBadRequestError(err, "", ""))
Expand Down
3 changes: 2 additions & 1 deletion internal/repository/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ func (r *UserRepository) ListUsersByRole(ctx context.Context, organizationId str
}

func (r *UserRepository) Update(ctx context.Context, user *model.User) (*model.User, error) {
res := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", user.ID).Updates(model.User{
res := r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", user.ID).
Select("Name", "Email", "Department", "Description").Updates(model.User{
Name: user.Name,
Email: user.Email,
Department: user.Department,
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type UpdateMyProfileRequest struct {
Password string `json:"password" validate:"required"`
Name string `json:"name" validate:"required,min=1,max=30"`
Email string `json:"email" validate:"required,email"`
Department string `json:"department" validate:"required,min=0,max=50"`
Department string `json:"department" validate:"min=0,max=50"`
}

type UpdateMyProfileResponse struct {
Expand Down

0 comments on commit f02321d

Please sign in to comment.