package repository import ( "context" "fmt" "github.com/google/uuid" "code.icb4dc0.de/prskr/searcherside/core/cq" "code.icb4dc0.de/prskr/searcherside/core/domain" "code.icb4dc0.de/prskr/searcherside/core/ports" "code.icb4dc0.de/prskr/searcherside/internal/ent" "code.icb4dc0.de/prskr/searcherside/internal/shred" ) var _ ports.UserRepository = (*EntUserRepository)(nil) func NewEntUserRepository(client *ent.Client, hashAlgorithm ports.PasswordHashAlgorithm) *EntUserRepository { return &EntUserRepository{ client: client, hashAlgorithm: hashAlgorithm, } } type EntUserRepository struct { client *ent.Client hashAlgorithm ports.PasswordHashAlgorithm } func (e EntUserRepository) Close() error { return e.client.Close() } func (e EntUserRepository) CreateUser(ctx context.Context, user cq.CreateUserRequest) (*cq.CreateUserResponse, error) { defer func() { shred.Bytes(user.Password) }() hashedPassword, err := e.hashAlgorithm.Hash(user.Password) if err != nil { return nil, fmt.Errorf("failed to hash password: %w", err) } _, err = e.client.User.Create(). SetEmail(user.Email). SetPassword(hashedPassword). SetIsAdmin(user.Admin). Save(ctx) if err != nil { return nil, fmt.Errorf("failed to create user: %w", err) } return new(cq.CreateUserResponse), nil } func (e EntUserRepository) UserByID(ctx context.Context, id uuid.UUID) (*domain.User, error) { //TODO implement me panic("implement me") } func (e EntUserRepository) UserByEmail(ctx context.Context, email string) (*domain.User, error) { //TODO implement me panic("implement me") }