domain

package
v0.0.0-...-47d3968 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TYPE_TRANSFER = "transfer"
	TYPE_TOPUP    = "topup"
)

Variables

View Source
var (
	ErrInternalServerError = errors.New("internal server error")
	ErrEmailUsed           = errors.New("email already in use")
	ErrEmailNotFound       = errors.New("email not found")
	ErrWalletNotFound      = errors.New("wallet not found")
	ErrWrongEmailPass      = errors.New("incorrect email or password")
	ErrParameterValidation = errors.New("parameter validation failed")
	ErrInvalidToken        = errors.New("jwt authentication token invalid")
	ErrInsufficientBalance = errors.New("wallet balance insufficient")
	ErrSendToOwn           = errors.New("cannot send money to your own wallet")
)

Functions

This section is empty.

Types

type CustomJwtClaim

type CustomJwtClaim struct {
	jwt.StandardClaims
	WalletID string
}

type Transaction

type Transaction struct {
	ID              string    `gorm:"primarykey" json:"id"`
	TransactionTime time.Time `json:"transaction_time"`
	TransactionType string    `json:"transaction_type"`
	CreditedWallet  string    `json:"credited_wallet"`
	DebitedWallet   string    `json:"debited_wallet,omitempty"`
	Notes           string    `json:"notes"`
	Amount          uint64    `json:"amount"`
}

type User

type User struct {
	gorm.Model
	FullName       string `gorm:"not null"`
	Email          string `gorm:"index:idx_users_email,unique;not null"`
	HashedPassword string `gorm:"not null"`
	IsVerified     bool   `gorm:"not null"`
}

type UserRepository

type UserRepository interface {
	Insert(fullname, email, hashedPassword string, isVerified bool) error
	GetByEmail(email string) (User, Wallet, error)
}

type UserUsecase

type UserUsecase interface {
	Register(fullname, email, plainPassword string) error
	Login(email, plainPassword string) (User, Wallet, string, error)
}

type Wallet

type Wallet struct {
	ID      string `gorm:"primarykey"`
	UserID  uint
	User    User
	Balance uint64 `gorm:"not null;default:0"`
}

type WalletRepository

type WalletRepository interface {
	GetBalance(walletId string) (uint64, error)
	Transaction(transactionId string, transactionTime time.Time, transactionType string, creditedWallet string, debitedWallet string, notes string, amount uint32) (Transaction, error)
}

type WalletUsecase

type WalletUsecase interface {
	GetBalance(walletId string) (uint64, error)
	TopUp(walletId string, amount uint32) (Transaction, error)
	Transfer(senderId string, receiverId string, notes string, amount uint32) (Transaction, error)
}

Jump to

Keyboard shortcuts

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