user

package
v0.0.0-...-6375eca Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound        = errors.NotFound("user not found")
	ErrUserAlreadyExists   = errors.Conflict("user already exists")
	ErrUserIDRequired      = errors.BadRequest("user id required")
	ErrInvalidCredentials  = errors.Unauthorized("invalid credentials")
	ErrUserBalanceNotFound = errors.NotFound("user balance not found")
)

Functions

func RegisterProviders

func RegisterProviders(container *dig.Container) error

Types

type CreateUserRequest

type CreateUserRequest struct {
	UserName string `json:"username" validate:"required,email"`
	Password string `json:"password" validate:"required,min=8,max=32"`
}

type DeleteUserRequest

type DeleteUserRequest struct {
	UserID uint `json:"username" validate:"required,email"`
}

type Repository

type Repository interface {
	FindByID(id uint) (*User, error)
	FindByUserName(userName string) (*User, error)
	Create(user *User) error
	Update(user *User) error
	Delete(user *User) error
}

type Service

type Service interface {
	Get(id uint) (*UserResponse, error)
	GetByUserName(username string) (*UserResponse, error)
	Create(request CreateUserRequest) error
	Delete(request DeleteUserRequest) error
	GetBalance(userId uint) (*UserBalanceResponse, error)
	VerifyCredentials(username string, password string) (*UserResponse, error)
}

func NewService

func NewService(options UserServiceParams) Service

type User

type User struct {
	ID       uint
	UserName string `validate:"required,email"`
	Password string `validate:"required"`
	Balance  *UserBalance
}

func (*User) ComparePassword

func (u *User) ComparePassword(password string) error

type UserBalance

type UserBalance struct {
	ID             uint
	Amount         float64
	AmountInFlight float64
}

type UserBalanceResponse

type UserBalanceResponse struct {
	Amount         float64 `json:"amount"`
	AmountInFlight float64 `json:"amountInFlight"`
}

type UserFactory

type UserFactory = func(userName, password string) (*User, error)

func NewUserFactory

func NewUserFactory(validator *validator.Validator) UserFactory

type UserResponse

type UserResponse struct {
	ID       uint                `json:"id"`
	UserName string              `json:"username"`
	Balance  UserBalanceResponse `json:"balance"`
}

type UserServiceParams

type UserServiceParams struct {
	dig.In
	Repository        Repository
	CreateUserFactory UserFactory
}

Jump to

Keyboard shortcuts

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