Added completed user. Some fixes and more more more...

This commit is contained in:
KamilM1205 2026-01-02 22:56:25 +04:00
parent b96dd39795
commit ea8ab7c0ed
33 changed files with 576 additions and 212 deletions

View file

@ -1,6 +1,17 @@
package commands
import "time"
type CreateUserCommand struct {
Username string
Password string
Username string
Password string
Name string
Role string
Speciality string
Description string
Skills string
Avatar string
JoinDate time.Time
Projects string
Motto string
}

View file

@ -3,7 +3,15 @@ package commands
import "github.com/google/uuid"
type UpdateUserCommand struct {
Id uuid.UUID
Username string
Password string
Id uuid.UUID
Username string
Password string
Name string
Role string
Speciality string
Description string
Skills string
Avatar string
Projects string
Motto string
}

View file

@ -1,11 +1,24 @@
package common
import "github.com/google/uuid"
import (
"time"
"github.com/google/uuid"
)
type UserResult struct {
Id uuid.UUID
UserName string
Password string
Id uuid.UUID
UserName string
Password string
Name string
Role string
Speciality string
Description string
Skills string
Avatar string
JoinDate time.Time
Projects string
Motto string
}
type UserResultList struct {

View file

@ -8,9 +8,18 @@ import (
func CreateUserResultFromEntity(entity *entities.User) *common.UserResult {
return &common.UserResult{
Id: entity.Id,
UserName: entity.UserName,
Password: entity.Password,
Id: entity.Id,
UserName: entity.UserName,
Password: entity.Password,
Name: entity.Name,
Role: entity.Role,
Speciality: entity.Speciality,
Description: entity.Description,
Skills: entity.Skills,
Avatar: entity.Avatar,
JoinDate: entity.JoinDate,
Projects: entity.Projects,
Motto: entity.Motto,
}
}

View file

@ -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())