diff --git a/internal/delivery/http/user.go b/internal/delivery/http/user.go index 4a572974..d886c251 100644 --- a/internal/delivery/http/user.go +++ b/internal/delivery/http/user.go @@ -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 @@ -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, "", "")) diff --git a/internal/repository/user.go b/internal/repository/user.go index 72a129df..0d8f200a 100644 --- a/internal/repository/user.go +++ b/internal/repository/user.go @@ -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, diff --git a/pkg/domain/user.go b/pkg/domain/user.go index 1258f1f4..030c64fd 100644 --- a/pkg/domain/user.go +++ b/pkg/domain/user.go @@ -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 {