Documentation
¶
Index ¶
- Variables
- func CreateParamsFromRequest(req gen.CreateUserRequest) (username, password, role string)
- func ToResponse(u *User) gen.User
- func ToResponseList(users []*User) []gen.User
- type Handler
- type PostgresRepository
- func (r *PostgresRepository) Create(ctx context.Context, u *User) (*User, error)
- func (r *PostgresRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (r *PostgresRepository) GetByID(ctx context.Context, id uuid.UUID) (*User, error)
- func (r *PostgresRepository) GetByUsername(ctx context.Context, username string) (*User, error)
- func (r *PostgresRepository) List(ctx context.Context) ([]*User, error)
- type Repository
- type Service
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidRole = errors.New("role must be one of: admin, viewer")
Functions ¶
func CreateParamsFromRequest ¶
func CreateParamsFromRequest(req gen.CreateUserRequest) (username, password, role string)
CreateParamsFromRequest translates a generated CreateUserRequest into the primitive parameters Service.Create expects. This is not a pure 1:1 mapper — it also applies the API-level default role ("viewer") when the client omits it.
func ToResponse ¶
ToResponse converts a domain User into the generated API model. Callers must guarantee u != nil — a nil User means "not found", which callers are expected to translate into 404 before calling ToResponse. This function panics on nil rather than silently returning an empty User, so a caller bug surfaces immediately instead of leaking as `{}` in a response.
PasswordHash is intentionally never mapped — gen.User has no such field.
func ToResponseList ¶
ToResponseList converts a slice of domain Users into generated API models.
Types ¶
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
func NewPostgresRepository ¶
func NewPostgresRepository(db *pgxpool.Pool) *PostgresRepository
func (*PostgresRepository) GetByUsername ¶
type Repository ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo Repository) *Service