repository

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: 20 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 (
	ErrInvalidDBConfiguration = errors.New("invalid database configuration. It is nil")
	ErrInvalidMaxPingTimeout  = errors.New("invalid max ping timeout. It must be greater than 10 millisecond")
	ErrInvalidMaxQueryTimeout = errors.New("invalid max query timeout. It must be greater than 10 millisecond")
	ErrInvalidOTConfiguration = errors.New("invalid OpenTelemetry configuration. It is nil")

	ErrAtLeastOneFieldMustBeUpdated = errors.New("at least one field must be updated")
	ErrInputIsNil                   = errors.New("input is nil")

	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")
)
View Source
var (
	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")
)
View Source
var (
	// UserFilterFields is a list of valid fields for filtering users.
	UserFilterFields = []string{"id", "first_name", "last_name", "email", "disabled", "created_at", "updated_at"}

	// UserSortFields is a list of valid fields for sorting users.
	UserSortFields = []string{"id", "first_name", "last_name", "email", "disabled", "created_at", "updated_at"}

	// UserPartialFields is a list of valid fields for partial responses.
	UserPartialFields = []string{"id", "first_name", "last_name", "email", "disabled", "created_at", "updated_at"}
)

Functions

func Sanity

func Sanity(value string) string

Types

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 InsertUserInput

type InsertUserInput UserInput

InsertUserInput represents the input for the CreateUser method.

func (*InsertUserInput) Validate

func (ui *InsertUserInput) Validate() error

Validate validates the CreateUserInput.

type ListUserInput

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

ListUserInput represents the common input for the list user method.

func (*ListUserInput) Validate

func (ui *ListUserInput) Validate() error

Validate validates the ListUserInput.

type SelectUsersInput

type SelectUsersInput ListUserInput

SelectUsersInput represents the common input for the select user method.

func (*SelectUsersInput) Validate added in v0.0.11

func (ui *SelectUsersInput) Validate() error

Validate validates the SelectUsersInput.

type SelectUsersOutput

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

SelectUsersOutput represents the output for the list user method.

type UpdateUserInput

type UpdateUserInput struct {
	ID           uuid.UUID
	FirstName    *string
	LastName     *string
	Email        *string
	PasswordHash *string
	Disabled     *bool
	UpdatedAt    *time.Time
}

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
	SerialID     int64
}

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
	PasswordHash 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 added in v0.0.11

type UserRepository struct {
	// contains filtered or unexported fields
}

this implement repository.UserRepository UserRepository is a PostgreSQL store.

func NewUserRepository added in v0.0.11

func NewUserRepository(conf UserRepositoryConfig) (*UserRepository, error)

NewUserRepository creates a new UserRepository.

func (*UserRepository) Close added in v0.0.11

func (r *UserRepository) Close() error

Close closes the repository, releasing any open resources.

func (*UserRepository) Conn added in v0.0.11

func (r *UserRepository) Conn(ctx context.Context) (*sql.Conn, error)

Conn returns the connection to the repository.

func (*UserRepository) Delete added in v0.0.11

func (r *UserRepository) Delete(ctx context.Context, input *DeleteUserInput) error

Delete deletes the user with the specified ID.

func (*UserRepository) DriverName added in v0.0.11

func (r *UserRepository) DriverName() string

DriverName returns the name of the driver.

func (*UserRepository) Insert added in v0.0.11

func (r *UserRepository) Insert(ctx context.Context, input *InsertUserInput) error

Insert a new user into the database.

func (*UserRepository) PingContext added in v0.0.11

func (r *UserRepository) PingContext(ctx context.Context) error

PingContext verifies a connection to the repository is still alive, establishing a connection if necessary.

func (*UserRepository) Select added in v0.0.11

func (*UserRepository) SelectUserByEmail added in v0.0.11

func (r *UserRepository) SelectUserByEmail(ctx context.Context, email string) (*User, error)

SelectUserByEmail returns the user with the specified email.

func (*UserRepository) SelectUserByID added in v0.0.11

func (r *UserRepository) SelectUserByID(ctx context.Context, id uuid.UUID) (*User, error)

SelectUserByID returns the user with the specified ID.

func (*UserRepository) Update added in v0.0.11

func (r *UserRepository) Update(ctx context.Context, input *UpdateUserInput) error

Update updates the user with the specified ID.

type UserRepositoryConfig added in v0.0.11

type UserRepositoryConfig struct {
	DB              *sql.DB
	MaxPingTimeout  time.Duration
	MaxQueryTimeout time.Duration
	OT              *o11y.OpenTelemetry
	MetricsPrefix   string
}

Jump to

Keyboard shortcuts

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