user

package
v0.0.0-...-3ca1276 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// list of errors for full name validation
	ErrFullNameEmpty = &UserError{"full name cannot be empty"}
	// list of errors for email validation
	ErrEmailEmpty            = &UserError{"email cannot be empty"}
	ErrEmailExceedsMaxLength = &UserError{fmt.Sprintf("email cannot exceed %d characters", emailMaxLength)}
	ErrEmailInvalid          = &UserError{"email must be a valid email address"}
	// list of errors for password validation
	ErrPasswordEmpty    = &UserError{"password cannot be empty"}
	ErrPasswordTooShort = &UserError{fmt.Sprintf("password cannot be less than %d characters long", passwordMinLength)}
	ErrPasswordTooLong  = &UserError{fmt.Sprintf("password cannot exceed %d characters", passwordMaxLength)}
	ErrPasswordInvalid  = &UserError{"password must contain only alphanumeric characters and symbols"}
	ErrPasswordMismatch = &UserError{"passwords do not match"}
	// list of errors for phone number validation
	ErrPhoneEmpty   = &UserError{"phone number cannot be empty"}
	ErrPhoneInvalid = &UserError{"phone number must contain only numbers"}
	// list of errors for role validation
	ErrRoleInvalid = &UserError{"account role must be either \"admin\" or \"customer\""}
	// list of errors for user repository
	ErrAccountInvalid  = &UserError{"account data is invalid"}
	ErrAccountExists   = &UserError{"account already exists"}
	ErrAccountNotFound = &UserError{"account not found"}
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID          uuid.UUID
	FullName    string
	Email       string
	Password    string
	PhoneNumber string
	Role        string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Account represents a user for the application.

func NewAccount

func NewAccount(
	fullName FullName,
	phoneNumber PhoneNumber,
	email Email,
	password Password,
	accountRole AccountRole,
) (*Account, error)

NewAccount creates a new user account.

type AccountRole

type AccountRole string

AccountRole is an enum for user account roles.

const (
	Admin    AccountRole = "admin"
	Customer AccountRole = "customer"
)

func NewAccountRole

func NewAccountRole(role string) (AccountRole, error)

NewAccountRole validates and creates a new user account role.

func (AccountRole) String

func (r AccountRole) String() string

String returns the string representation of the user account role.

type Email

type Email string

Email represents an email address.

func NewEmail

func NewEmail(email string) (Email, error)

NewEmail valiates and creates a new email address.

func (Email) String

func (e Email) String() string

String returns the string representation of the email address.

type FullName

type FullName string

FullName represents a user's full name.

func NewFullName

func NewFullName(name string) (FullName, error)

NewFullName validates and creates a new full name.

func (FullName) String

func (n FullName) String() string

String returns the string representation of the full name.

type Password

type Password string

func NewPassword

func NewPassword(password string) (Password, error)

NewPassword validates and creates a new password.

func (Password) Compare

func (p Password) Compare(hash string) bool

Compare returns true if the password matches the hash.

func (Password) Hash

func (p Password) Hash() (Password, error)

Hash returns the hashed password with bcrypt typed as Password.

func (Password) String

func (p Password) String() string

String returns the string representation of the password.

type PhoneNumber

type PhoneNumber string

func NewPhoneNumber

func NewPhoneNumber(number string) (PhoneNumber, error)

NewPhoneNumber validates and creates a new phone number.

func (PhoneNumber) String

func (p PhoneNumber) String() string

String returns the string representation of the phone number.

type ReadWriter

type ReadWriter interface {
	Reader
	Writer
}

ReadWriter is the interface that combines Reader and Writer interfaces for user data.

type Reader

type Reader interface {
	GetAccountByID(ctx context.Context, id uuid.UUID) (*Account, error)
	GetAccountByEmail(ctx context.Context, email string) (*Account, error)
	ListAccounts(ctx context.Context, limit, offset int) ([]*Account, error)
}

Reader is the interface that provides methods to read user data from the storage.

type Service

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

Service provides user business logic and operations.

func NewService

func NewService(repo ReadWriter) *Service

NewService creates a new user service instance.

func (*Service) CreateAccount

func (s *Service) CreateAccount(
	ctx context.Context,
	fullName, phoneNumber, email, password, confirmPassword string,
) (*Account, error)

CreateAccount validates, creates, and stores a new user account.

func (*Service) GetAccountByEmail

func (s *Service) GetAccountByEmail(ctx context.Context, email, password string) (*Account, error)

GetAccountByEmail validates and retrieves a user account by provided email and password.

type UserError

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

UserError is a custom error for user domain logic.

func (*UserError) Error

func (ue *UserError) Error() string

Error returns the error message for the UserError type.

type Writer

type Writer interface {
	AddAccount(ctx context.Context, u *Account) error
	UpdateAccount(ctx context.Context, u *Account) error
	DeleteAccount(ctx context.Context, id uuid.UUID) error
}

Writer is the interface that provides methods to write user data to the storage.

Jump to

Keyboard shortcuts

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