Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix. fix update-my-profile #411

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading