package user import ( "context" "tercul/internal/domain" ) // UserCommands contains the command handlers for the user aggregate. type UserCommands struct { repo domain.UserRepository } // NewUserCommands creates a new UserCommands handler. func NewUserCommands(repo domain.UserRepository) *UserCommands { return &UserCommands{repo: repo} } // CreateUserInput represents the input for creating a new user. type CreateUserInput struct { Username string Email string Password string FirstName string LastName string Role domain.UserRole } // CreateUser creates a new user. func (c *UserCommands) CreateUser(ctx context.Context, input CreateUserInput) (*domain.User, error) { user := &domain.User{ Username: input.Username, Email: input.Email, Password: input.Password, FirstName: input.FirstName, LastName: input.LastName, Role: input.Role, } err := c.repo.Create(ctx, user) if err != nil { return nil, err } return user, nil } // UpdateUserInput represents the input for updating an existing user. type UpdateUserInput struct { ID uint Username string Email string FirstName string LastName string Role domain.UserRole } // UpdateUser updates an existing user. func (c *UserCommands) UpdateUser(ctx context.Context, input UpdateUserInput) (*domain.User, error) { user, err := c.repo.GetByID(ctx, input.ID) if err != nil { return nil, err } user.Username = input.Username user.Email = input.Email user.FirstName = input.FirstName user.LastName = input.LastName user.Role = input.Role err = c.repo.Update(ctx, user) if err != nil { return nil, err } return user, nil } // DeleteUser deletes a user by ID. func (c *UserCommands) DeleteUser(ctx context.Context, id uint) error { return c.repo.Delete(ctx, id) }