internal

package
v0.0.0-...-3143a31 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RunAddress           = "RUN_ADDRESS"
	DatabaseURI          = "DATABASE_URI"
	AccrualSystemAddress = "ACCRUAL_SYSTEM_ADDRESS"
	JWTSecret            = "JWT_Secret"
)

Variables

View Source
var (
	ErrLoginIsAlreadyTaken           = errors.New("login is already taken")
	ErrInvalidCredentials            = errors.New("invalid credentials")
	ErrOrderIsAlreadySent            = errors.New("order is already sent")
	ErrOrderIsAlreadySentByOtherUser = errors.New("order is already sent by other user")
	ErrNoRecords                     = errors.New("no records")
	ErrLuhnInvalid                   = errors.New("number invalid by luhn")
	ErrInsufficientFunds             = errors.New("insufficient funds")
	ErrTooManyRequests               = errors.New("too many requests")
)

Functions

func GetHash

func GetHash(s string) string

func NewConfig

func NewConfig() *config

Types

type AccrualService

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

func (AccrualService) ProcessAccrual

func (s AccrualService) ProcessAccrual(ctx context.Context, uid int, orderNumber string)

func (AccrualService) Run

func (s AccrualService) Run()

func (AccrualService) SendToQueue

func (s AccrualService) SendToQueue(ctx context.Context, uid int, orderNumber string)

type Handlers

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

func NewHandlers

func NewHandlers(Service IService, secret string, logger *zap.SugaredLogger) *Handlers

func (*Handlers) CreateOrder

func (h *Handlers) CreateOrder(c *fiber.Ctx) error

func (*Handlers) GetBalance

func (h *Handlers) GetBalance(c *fiber.Ctx) error

func (*Handlers) GetOrders

func (h *Handlers) GetOrders(c *fiber.Ctx) error

func (*Handlers) Login

func (h *Handlers) Login(c *fiber.Ctx) error

func (*Handlers) Register

func (h *Handlers) Register(c *fiber.Ctx) error

func (*Handlers) Withdraw

func (h *Handlers) Withdraw(c *fiber.Ctx) error

func (*Handlers) WithdrawHistory

func (h *Handlers) WithdrawHistory(c *fiber.Ctx) error

type IAccrual

type IAccrual interface {
	Run()
	SendToQueue(context.Context, int, string)
	ProcessAccrual(context.Context, int, string)
}

func NewAccrualService

func NewAccrualService(repo IRepository, url string, ctx context.Context, logger *zap.SugaredLogger) IAccrual

type IRepository

type IRepository interface {
	Register(context.Context, string, string) (int, error)
	IsUserExist(context.Context, string) (bool, error)
	CheckCredentials(context.Context, string, string) (int, error)
	GetOrderByNumber(context.Context, string) (model.Order, error)
	SendOrder(context.Context, string, int) error
	GetOrders(context.Context, int) ([]model.OrderOutput, error)
	GetBalanceByUserID(context.Context, int) (model.BalanceWithdrawn, error)
	Withdraw(context.Context, model.WithdrawInput, model.BalanceWithdrawn, int) error
	GetWithdrawHistory(context.Context, int) ([]model.WithdrawOutput, error)
	UpdateOrderStatus(context.Context, string, string) error
	MakeAccrual(context.Context, int, string, string, decimal.Decimal, decimal.Decimal) error
}

type IService

type IService interface {
	Register(context.Context, string, string) (string, error)
	Login(context.Context, string, string) (string, error)
	GetJWTToken(string) (string, error)
	SendOrder(context.Context, string, int) error
	GetOrders(context.Context, int) ([]model.OrderOutput, error)
	GetBalanceByUserID(context.Context, int) (model.BalanceWithdrawn, error)
	Withdraw(context.Context, model.WithdrawInput, int) error
	GetWithdrawHistory(context.Context, int) ([]model.WithdrawOutput, error)
}

type Repository

type Repository struct {
	Conn   *sql.DB
	Logger *zap.SugaredLogger
}

func NewRepository

func NewRepository(connString string, embedMigrations embed.FS, logger *zap.SugaredLogger) (*Repository, error)

func (Repository) CheckCredentials

func (r Repository) CheckCredentials(ctx context.Context, login string, password string) (int, error)

func (Repository) GetBalanceByUserID

func (r Repository) GetBalanceByUserID(ctx context.Context, uid int) (model.BalanceWithdrawn, error)

func (Repository) GetOrderByNumber

func (r Repository) GetOrderByNumber(ctx context.Context, orderNumber string) (model.Order, error)

func (Repository) GetOrders

func (r Repository) GetOrders(ctx context.Context, uid int) ([]model.OrderOutput, error)

func (Repository) GetWithdrawHistory

func (r Repository) GetWithdrawHistory(ctx context.Context, uid int) ([]model.WithdrawOutput, error)

func (Repository) IsUserExist

func (r Repository) IsUserExist(ctx context.Context, login string) (bool, error)

func (Repository) MakeAccrual

func (r Repository) MakeAccrual(ctx context.Context, uid int, status string, orderNumber string, accrual decimal.Decimal, balance decimal.Decimal) error

func (Repository) Register

func (r Repository) Register(ctx context.Context, login, password string) (int, error)

func (Repository) SendOrder

func (r Repository) SendOrder(ctx context.Context, orderNumber string, userID int) error

func (Repository) UpdateOrderStatus

func (r Repository) UpdateOrderStatus(ctx context.Context, orderNumber string, status string) error

func (Repository) Withdraw

type Service

type Service struct {
	Repository     IRepository
	AccrualService IAccrual
	// contains filtered or unexported fields
}

func NewService

func NewService(Repository IRepository, AccrualService IAccrual, secret string, logger *zap.SugaredLogger) *Service

func (Service) GetBalanceByUserID

func (s Service) GetBalanceByUserID(ctx context.Context, uid int) (model.BalanceWithdrawn, error)

func (Service) GetJWTToken

func (s Service) GetJWTToken(uid string) (string, error)

func (Service) GetOrders

func (s Service) GetOrders(ctx context.Context, uid int) ([]model.OrderOutput, error)

func (Service) GetWithdrawHistory

func (s Service) GetWithdrawHistory(ctx context.Context, uid int) ([]model.WithdrawOutput, error)

func (Service) Login

func (s Service) Login(ctx context.Context, login, password string) (string, error)

func (Service) Register

func (s Service) Register(ctx context.Context, login, password string) (string, error)

func (Service) SendOrder

func (s Service) SendOrder(ctx context.Context, orderNumber string, uid int) error

func (Service) Withdraw

func (s Service) Withdraw(ctx context.Context, i model.WithdrawInput, uid int) error

Directories

Path Synopsis
Package mock_internal is a generated GoMock package.
Package mock_internal is a generated GoMock package.

Jump to

Keyboard shortcuts

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