Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
type FullName ¶
type FullName string
FullName represents a user's full name.
func NewFullName ¶
NewFullName validates and creates a new full name.
type Password ¶
type Password string
func NewPassword ¶
NewPassword validates and creates a new 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 ¶
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.