service

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UsersFirstNameMinLength = 2
	UsersFirstNameMaxLength = 255
	UsersLastNameMinLength  = 2
	UsersLastNameMaxLength  = 255
	UsersEmailMinLength     = 6
	UsersEmailMaxLength     = 255
	UsersPasswordMinLength  = 6
	UsersPasswordMaxLength  = 255
)

Variables

View Source
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")
)
View Source
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

type DeleteUserInput struct {
	ID uuid.UUID
}

DeleteUserInput represents the input for the DeleteUser method.

func (*DeleteUserInput) Validate

func (ui *DeleteUserInput) Validate() error

Validate validates the DeleteUserInput.

type Health

type Health struct {
	Status Status  `json:"status"`
	Checks []Check `json:"checks"`
}

Check represents a health check.

type ListUserInput

type ListUserInput struct {
	Sort      string
	Filter    string
	Fields    []string
	Paginator paginator.Paginator
}

ListUserInput represents the input for the ListUser method.

type ListUsersOutput

type ListUsersOutput struct {
	Items     []*User
	Paginator paginator.Paginator
}

ListUsersOutput represents the output for the ListUser method.

type Status

type Status bool

------------------------------------------------------------ Status is an enumeration of health statuses.

const (
	StatusUp   Status = true
	StatusDown Status = false
)

Health statuses enumeration.

func (Status) MarshalJSON

func (s Status) MarshalJSON() ([]byte, error)

MarshalJSON marshals the status to JSON.

func (Status) String

func (s Status) String() string

String returns the string representation of the status.

func (*Status) UnmarshalJSON

func (s *Status) UnmarshalJSON(data []byte) error

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.

const (
	TypeAccessToken            TokenType = "access"
	TypeRefreshToken           TokenType = "refresh"
	TypeEmailVerificationToken TokenType = "email_verification"
	TypePasswordResetToken     TokenType = "password_reset"
)

func (TokenType) IsValid added in v0.0.11

func (tt TokenType) IsValid() bool

IsValid checks if the token type is valid.

func (TokenType) String added in v0.0.11

func (tt TokenType) String() string

String returns the string representation of the token type.

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.

func (*UserInput) Validate

func (ui *UserInput) Validate() error

Validate validates the user input.

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

func (s *UserService) GetUserByEmail(ctx context.Context, email string) (*User, error)

GetUserByEmail returns the user with the specified email.

func (*UserService) GetUserByID

func (s *UserService) GetUserByID(ctx context.Context, id uuid.UUID) (*User, error)

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL