Chore: Add user service method Update (#53300)
* Chore: Add user service method Update * Remove UpdateUser from store interface
This commit is contained in:
@@ -66,6 +66,15 @@ type GetUserByEmailQuery struct {
|
||||
Email string
|
||||
}
|
||||
|
||||
type UpdateUserCommand struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Login string `json:"login"`
|
||||
Theme string `json:"theme"`
|
||||
|
||||
UserID int64 `json:"-"`
|
||||
}
|
||||
|
||||
func (u *User) NameOrFallback() string {
|
||||
if u.Name != "" {
|
||||
return u.Name
|
||||
|
||||
@@ -10,4 +10,5 @@ type Service interface {
|
||||
GetByID(context.Context, *GetUserByIDQuery) (*User, error)
|
||||
GetByLogin(context.Context, *GetUserByLoginQuery) (*User, error)
|
||||
GetByEmail(context.Context, *GetUserByEmailQuery) (*User, error)
|
||||
Update(context.Context, *UpdateUserCommand) error
|
||||
}
|
||||
|
||||
@@ -267,3 +267,15 @@ func (s *Service) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuer
|
||||
}
|
||||
return q.Result, nil
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) Update(ctx context.Context, cmd *user.UpdateUserCommand) error {
|
||||
q := &models.UpdateUserCommand{
|
||||
Name: cmd.Name,
|
||||
Email: cmd.Email,
|
||||
Login: cmd.Login,
|
||||
Theme: cmd.Theme,
|
||||
UserId: cmd.UserID,
|
||||
}
|
||||
return s.sqlStore.UpdateUser(ctx, q)
|
||||
}
|
||||
|
||||
@@ -34,3 +34,7 @@ func (f *FakeUserService) GetByLogin(ctx context.Context, query *user.GetUserByL
|
||||
func (f *FakeUserService) GetByEmail(ctx context.Context, query *user.GetUserByEmailQuery) (*user.User, error) {
|
||||
return f.ExpectedUser, f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeUserService) Update(ctx context.Context, cmd *user.UpdateUserCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user