userbalance

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

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorForbidden     = Response{Code: http.StatusForbidden, Message: "Forbidden"}
	ErrorUnauthorized  = Response{Code: http.StatusUnauthorized, Message: "Unauthorized"}
	ErrorRequiredField = Response{Code: http.StatusBadRequest, Message: "Required field"}
	ErrorInternal      = Response{Code: http.StatusInternalServerError, Message: "Internal Server Error"}
	ErrorBadRequest    = Response{Code: http.StatusBadRequest, Message: "Bad Request"}
	ErrorNoRecords     = Response{Code: http.StatusOK, Message: "No records found"}
	ErrorNotFound      = Response{Code: http.StatusNotFound, Message: "No records found"}

	ErrNotEnoughBalance         = errors.New("not enough balance")
	ErrNoCurrencyOrUserRecorded = errors.New("no user or balance with requested currency")
)
View Source
var (
	SuccessCreateBalance     = Response{Code: 200, Message: "Balance added successfully"}
	SuccessCreateTransaction = Response{Code: 200, Message: "Transaction successful"}
	Success                  = Response{Code: 200, Message: "success"}
)

Functions

This section is empty.

Types

type CreateTransactionPayload

type CreateTransactionPayload struct {
	RecipientBankAccountNumber string `json:"recipientBankAccountNumber"`
	RecipientBankName          string `json:"recipientBankName"`
	Balances                   int    `json:"balances"`
	FromCurrency               string `json:"fromCurrency"`
	UserID                     string
}

func (CreateTransactionPayload) Validate

func (p CreateTransactionPayload) Validate() error

type CreateUserBalancePayload

type CreateUserBalancePayload struct {
	SenderBankAccountNumber string `json:"senderBankAccountNumber"`
	SenderBankName          string `json:"senderBankName"`
	AddedBalance            int    `json:"addedBalance"`
	Currency                string `json:"currency"`
	TransferProofImg        string `json:"transferProofImg"`
	UserID                  string
}

func (CreateUserBalancePayload) Validate

func (p CreateUserBalancePayload) Validate() error

type Handler

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

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) Create

func (h *Handler) Create(w http.ResponseWriter, r *http.Request)

func (*Handler) List

func (h *Handler) List(w http.ResponseWriter, r *http.Request)

func (*Handler) ListTransaction

func (h *Handler) ListTransaction(w http.ResponseWriter, r *http.Request)

func (*Handler) Transaction

func (h *Handler) Transaction(w http.ResponseWriter, r *http.Request)

type ListUserBalancePayload

type ListUserBalancePayload struct {
	UserID string
}

type ListUserTransactionPayload

type ListUserTransactionPayload struct {
	UserID string
	Limit  int
	Offset int
}

type Repository

type Repository interface {
	RecordBalance(ctx context.Context, payload CreateUserBalancePayload) error
	RecordTransaction(ctx context.Context, payload CreateTransactionPayload) error
	FindByUserID(ctx context.Context, userID string) ([]UserBalanceResponse, error)
	ListTransactions(ctx context.Context, payload ListUserTransactionPayload) ([]UserTransaction, *response.Pagination, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Response

type Response struct {
	Code    int
	Message string
	Data    any
	Meta    *response.Pagination
	Error   string
}

type Service

type Service interface {
	Create(ctx context.Context, req CreateUserBalancePayload) Response
	CreateTransaction(ctx context.Context, req CreateTransactionPayload) Response
	List(ctx context.Context, req ListUserBalancePayload) Response
	ListTransaction(ctx context.Context, req ListUserTransactionPayload) Response
}

func NewService

func NewService(repository Repository) Service

type UserBalance

type UserBalance struct {
	ID        uint64     `json:"-"`
	Balance   int        `json:"balance"`
	Currency  string     `json:"currency"`
	UserID    uint64     `json:"user_id"`
	CreatedAt *time.Time `json:"created_at"`
}

type UserBalanceResponse

type UserBalanceResponse struct {
	Balance  int    `json:"balance"`
	Currency string `json:"currency"`
}

type UserTransaction

type UserTransaction struct {
	TransactionID     string
	UserID            string
	Amount            int
	Currency          string
	BankAccountNumber string
	BankName          string
	ImageURL          *string
	CreatedAt         time.Time
}

type UserTransactionResponse

type UserTransactionResponse struct {
	TransactionID    string `json:"transactionId"`
	Balance          int    `json:"balance"`
	Currency         string `json:"currency"`
	TransferProofImg string `json:"transferProofImg"`
	CreatedAt        int64  `json:"createdAt"`
	Source           struct {
		BankAccountNumber string `json:"bankAccountNumber"`
		BankName          string `json:"bankName"`
	} `json:"source"`
}

Jump to

Keyboard shortcuts

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