Added completed user. Some fixes and more more more...
This commit is contained in:
parent
b96dd39795
commit
ea8ab7c0ed
33 changed files with 576 additions and 212 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"58team_blog/internal/application/queries"
|
||||
"58team_blog/internal/domain/entities"
|
||||
"58team_blog/internal/domain/repository"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type UserService struct {
|
||||
|
|
@ -29,12 +30,15 @@ func (s *UserService) Create(cmd commands.CreateUserCommand) (*common.UserResult
|
|||
}
|
||||
|
||||
if user != nil {
|
||||
return nil, errors.NewAlreadyExistsError("user: " + cmd.Username)
|
||||
fmt.Println(user)
|
||||
return nil, errors.NewAlreadyExistsError("user: " + user.UserName)
|
||||
}
|
||||
}
|
||||
|
||||
// Create new user
|
||||
user, err := entities.CreateUser(cmd.Username, cmd.Password)
|
||||
user, err := entities.CreateUser(cmd.Username, cmd.Password,
|
||||
cmd.Name, cmd.Role, cmd.Speciality, cmd.Description,
|
||||
cmd.Skills, cmd.Avatar, cmd.JoinDate, cmd.Projects, cmd.Motto)
|
||||
if err != nil {
|
||||
return nil, errors.NewValidationError(err.Error())
|
||||
}
|
||||
|
|
@ -70,6 +74,10 @@ func (s *UserService) FindByName(query queries.UserFindByNameQuery) (*queries.Us
|
|||
return nil, errors.NewDBError(err.Error())
|
||||
}
|
||||
|
||||
if entity == nil {
|
||||
return nil, errors.NewNotFoundError("User not found.")
|
||||
}
|
||||
|
||||
if err := entity.Validate(); err != nil {
|
||||
return nil, errors.NewValidationError(err.Error())
|
||||
}
|
||||
|
|
@ -109,6 +117,14 @@ func (s *UserService) Update(cmd commands.UpdateUserCommand) (*common.UserResult
|
|||
}
|
||||
|
||||
entity.Password = cmd.Password
|
||||
entity.Name = cmd.Name
|
||||
entity.Role = cmd.Role
|
||||
entity.Speciality = cmd.Speciality
|
||||
entity.Description = cmd.Description
|
||||
entity.Skills = cmd.Skills
|
||||
entity.Avatar = cmd.Avatar
|
||||
entity.Projects = cmd.Projects
|
||||
entity.Motto = cmd.Motto
|
||||
|
||||
if err := entity.Validate(); err != nil {
|
||||
return nil, errors.NewValidationError(err.Error())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue