Documentation
¶
Index ¶
- Constants
- Variables
- func GetHash(s string) string
- func NewConfig() *config
- type AccrualService
- type Handlers
- func (h *Handlers) CreateOrder(c *fiber.Ctx) error
- func (h *Handlers) GetBalance(c *fiber.Ctx) error
- func (h *Handlers) GetOrders(c *fiber.Ctx) error
- func (h *Handlers) Login(c *fiber.Ctx) error
- func (h *Handlers) Register(c *fiber.Ctx) error
- func (h *Handlers) Withdraw(c *fiber.Ctx) error
- func (h *Handlers) WithdrawHistory(c *fiber.Ctx) error
- type IAccrual
- type IRepository
- type IService
- type Repository
- func (r Repository) CheckCredentials(ctx context.Context, login string, password string) (int, error)
- func (r Repository) GetBalanceByUserID(ctx context.Context, uid int) (model.BalanceWithdrawn, error)
- func (r Repository) GetOrderByNumber(ctx context.Context, orderNumber string) (model.Order, error)
- func (r Repository) GetOrders(ctx context.Context, uid int) ([]model.OrderOutput, error)
- func (r Repository) GetWithdrawHistory(ctx context.Context, uid int) ([]model.WithdrawOutput, error)
- func (r Repository) IsUserExist(ctx context.Context, login string) (bool, error)
- func (r Repository) MakeAccrual(ctx context.Context, uid int, status string, orderNumber string, ...) error
- func (r Repository) Register(ctx context.Context, login, password string) (int, error)
- func (r Repository) SendOrder(ctx context.Context, orderNumber string, userID int) error
- func (r Repository) UpdateOrderStatus(ctx context.Context, orderNumber string, status string) error
- func (r Repository) Withdraw(ctx context.Context, i model.WithdrawInput, bw model.BalanceWithdrawn, uid int) error
- type Service
- func (s Service) GetBalanceByUserID(ctx context.Context, uid int) (model.BalanceWithdrawn, error)
- func (s Service) GetJWTToken(uid string) (string, error)
- func (s Service) GetOrders(ctx context.Context, uid int) ([]model.OrderOutput, error)
- func (s Service) GetWithdrawHistory(ctx context.Context, uid int) ([]model.WithdrawOutput, error)
- func (s Service) Login(ctx context.Context, login, password string) (string, error)
- func (s Service) Register(ctx context.Context, login, password string) (string, error)
- func (s Service) SendOrder(ctx context.Context, orderNumber string, uid int) error
- func (s Service) Withdraw(ctx context.Context, i model.WithdrawInput, uid int) error
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 ¶
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 (*Handlers) GetBalance ¶
func (*Handlers) WithdrawHistory ¶
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 (Repository) GetBalanceByUserID ¶
func (r Repository) GetBalanceByUserID(ctx context.Context, uid int) (model.BalanceWithdrawn, error)
func (Repository) GetOrderByNumber ¶
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 (Repository) MakeAccrual ¶
func (Repository) UpdateOrderStatus ¶
func (Repository) Withdraw ¶
func (r Repository) Withdraw(ctx context.Context, i model.WithdrawInput, bw model.BalanceWithdrawn, uid int) error
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 (Service) GetWithdrawHistory ¶
Click to show internal directories.
Click to hide internal directories.