Documentation ¶
Index ¶
- Constants
- Variables
- type Check
- type CreateUserInput
- type DeleteUserInput
- type Health
- type ListUserInput
- type ListUsersOutput
- type Status
- type TokenType
- type UpdateUserInput
- type User
- type UserInput
- type UserRepository
- type UserService
- func (s *UserService) CreateUser(ctx context.Context, input *CreateUserInput) error
- func (s *UserService) DeleteUser(ctx context.Context, input *DeleteUserInput) error
- func (s *UserService) GetUserByEmail(ctx context.Context, email string) (*User, error)
- func (s *UserService) GetUserByID(ctx context.Context, id uuid.UUID) (*User, error)
- func (s *UserService) ListUsers(ctx context.Context, input *ListUserInput) (*ListUsersOutput, error)
- func (s *UserService) UpdateUser(ctx context.Context, input *UpdateUserInput) error
- func (s *UserService) UserHealthCheck(ctx context.Context) (Health, error)
- type UserServiceConf
Constants ¶
const ( UsersFirstNameMinLength = 2 UsersFirstNameMaxLength = 255 UsersLastNameMinLength = 2 UsersLastNameMaxLength = 255 UsersEmailMinLength = 6 UsersEmailMaxLength = 255 UsersPasswordMinLength = 6 UsersPasswordMaxLength = 255 )
Variables ¶
var ( ErrInvalidRepository = errors.New("invalid repository") ErrInvalidOpenTelemetry = errors.New("invalid open telemetry") ErrGettingUserByID = errors.New("error getting user by ID") ErrGettingUserByEmail = errors.New("error getting user by email") ErrCreatingUser = errors.New("error creating user") ErrUpdatingUser = errors.New("error updating user") ErrDeletingUser = errors.New("error deleting user") ErrListingUsers = errors.New("error listing users") ErrInvalidID = errors.New("invalid ID") ErrInvalidFirstName = errors.New("invalid first name, the first name must be at least 2 characters long") ErrInvalidLastName = errors.New("invalid last name, the last name must be at least 2 characters long") ErrInvalidEmail = errors.New("invalid email") ErrInvalidFilter = errors.New("invalid filter field") ErrInvalidSort = errors.New("invalid sort field") ErrInvalidFields = errors.New("invalid fields field") ErrInvalidLimit = errors.New("invalid limit field") ErrInvalidNextToken = errors.New("invalid nextToken field") ErrInvalidPrevToken = errors.New("invalid prevToken field") ErrIdAlreadyExists = errors.New("id already exists") ErrInputIsNil = errors.New("input is nil") ErrAtLeastOneFieldMustBeUpdated = errors.New("at least one field must be updated") )
var ( ErrInvalidUser = errors.New("invalid user") ErrInvalidUserID = errors.New("invalid user ID. Must be a valid UUID") ErrInvalidUserFirstName = errors.New("invalid first name. Must be between " + fmt.Sprintf("%d and %d", UsersFirstNameMinLength, UsersFirstNameMaxLength) + " characters long") ErrInvalidUserLastName = errors.New("invalid last name. Must be between " + fmt.Sprintf("%d and %d", UsersLastNameMinLength, UsersLastNameMaxLength) + " characters long") ErrInvalidUserEmail = errors.New("invalid email. Must be between " + fmt.Sprintf("%d and %d", UsersEmailMinLength, UsersEmailMaxLength) + " characters long") ErrInvalidUserPassword = errors.New("invalid password. Must be between " + fmt.Sprintf("%d and %d", UsersPasswordMinLength, UsersPasswordMaxLength) + " characters long") ErrUserNotFound = errors.New("user not found") ErrUserIDAlreadyExists = errors.New("user ID already exists") ErrUserEmailAlreadyExists = errors.New("user email already exists") )
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check struct { Name string `json:"name"` Kind string `json:"kind"` Status Status `json:"status"` Data map[string]interface{} `json:"data,omitempty"` }
Check represents a health check.
type CreateUserInput ¶
type CreateUserInput UserInput
CreateUserInput represents the input for the CreateUser method.
func (*CreateUserInput) Validate ¶
func (ui *CreateUserInput) Validate() error
Validate validates the CreateUserInput.
type DeleteUserInput ¶
DeleteUserInput represents the input for the DeleteUser method.
func (*DeleteUserInput) Validate ¶
func (ui *DeleteUserInput) Validate() error
Validate validates the DeleteUserInput.
type ListUserInput ¶
type ListUserInput struct { Sort string Filter string Fields []string Paginator paginator.Paginator }
ListUserInput represents the input for the ListUser method.
type ListUsersOutput ¶
ListUsersOutput represents the output for the ListUser method.
type Status ¶
type Status bool
------------------------------------------------------------ Status is an enumeration of health statuses.
func (Status) MarshalJSON ¶
MarshalJSON marshals the status to JSON.
func (*Status) UnmarshalJSON ¶
UnmarshalJSON unmarshals the status from JSON.
type TokenType ¶ added in v0.0.11
type TokenType string
TokenType represents the type of token. It can be either an access token, a refresh token, an email verification token or a password reset token.
type UpdateUserInput ¶
type UpdateUserInput struct { ID uuid.UUID FirstName *string LastName *string Email *string Password *string Disabled *bool }
UpdateUserInput represents the input for the UpdateUser method.
func (*UpdateUserInput) Validate ¶
func (ui *UpdateUserInput) Validate() error
Validate validates the UpdateUserInput.
type User ¶
type User struct { ID uuid.UUID FirstName string LastName string Email string PasswordHash string Disabled bool CreatedAt time.Time UpdatedAt time.Time }
User represents a user entity used to model the data stored in the database.
type UserInput ¶
type UserInput struct { ID uuid.UUID FirstName string LastName string Email string Password string Disabled bool }
UserInput represents the common input for the user entity.
type UserRepository ¶
type UserRepository interface { DriverName() string Close() error PingContext(ctx context.Context) error Conn(ctx context.Context) (*sql.Conn, error) Insert(ctx context.Context, input *repository.InsertUserInput) error Update(ctx context.Context, input *repository.UpdateUserInput) error Delete(ctx context.Context, input *repository.DeleteUserInput) error SelectUserByID(ctx context.Context, id uuid.UUID) (*repository.User, error) SelectUserByEmail(ctx context.Context, email string) (*repository.User, error) Select(ctx context.Context, input *repository.SelectUsersInput) (*repository.SelectUsersOutput, error) }
UserRepository is the interface for the user repository methods.
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
func NewUserService ¶
func NewUserService(conf UserServiceConf) (*UserService, error)
NewUserService creates a new UserService.
func (*UserService) CreateUser ¶
func (s *UserService) CreateUser(ctx context.Context, input *CreateUserInput) error
CreateUser inserts a new user into the database.
func (*UserService) DeleteUser ¶
func (s *UserService) DeleteUser(ctx context.Context, input *DeleteUserInput) error
DeleteUser deletes the user with the specified ID.
func (*UserService) GetUserByEmail ¶ added in v0.0.11
GetUserByEmail returns the user with the specified email.
func (*UserService) GetUserByID ¶
GetUserByID returns the user with the specified ID.
func (*UserService) ListUsers ¶
func (s *UserService) ListUsers(ctx context.Context, input *ListUserInput) (*ListUsersOutput, error)
ListUsers returns a list of users.
func (*UserService) UpdateUser ¶
func (s *UserService) UpdateUser(ctx context.Context, input *UpdateUserInput) error
UpdateUser updates the user with the specified ID.
func (*UserService) UserHealthCheck ¶
func (s *UserService) UserHealthCheck(ctx context.Context) (Health, error)
UserHealthCheck verifies a connection to the repository is still alive.
type UserServiceConf ¶
type UserServiceConf struct { Repository UserRepository OT *o11y.OpenTelemetry MetricsPrefix string }