Files
mtusi2026lab7/internal/application/users.go
T
d1frend cc41f601e3
Skeleton contracts / contracts (pull_request) Canceled after 0s
на оценку 4
2026-11-22 23:33:11 +03:00

30 lines
761 B
Go

package application
import (
"context"
"fmt"
"mtusi2026lab7/internal/domain"
"mtusi2026lab7/internal/security"
)
func (s *Service) CreateUser(ctx context.Context, command CreateUserCommand) (domain.User, error) {
if err := domain.ValidateUser(command.Username, command.DisplayName); err != nil {
return domain.User{}, fmt.Errorf("%w: %v", ErrInvalidInput, err)
}
if err := security.ValidatePassword(command.Password); err != nil {
return domain.User{}, fmt.Errorf("%w: %v", ErrInvalidInput, err)
}
passwordHash, err := security.HashPassword(command.Password)
if err != nil {
return domain.User{}, fmt.Errorf("hash password: %w", err)
}
return s.repository.CreateUser(
ctx,
command.Username,
command.DisplayName,
passwordHash,
)
}