transaction

package
v0.0.0-...-b62d7c7 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TransactionStatus_Created    = 1
	TransactionStatus_Progress   = 10
	TransactionStatus_InDelivery = 15
	TransactionStatus_Completed  = 20

	TRX_CREATED     = "CREATED"
	TRX_PROGRESS    = "PROGRESS"
	TRX_IN_DELIVERY = "IN DELIVERY"
	TRX_COMPLETED   = "COMPLETED"
	TRX_UNKNOWN     = "UNKNOWN STATUS"
)

Variables

Functions

This section is empty.

Types

type CreateTransactionRequestPayload

type CreateTransactionRequestPayload struct {
	ProductSKU   string `json:"product_sku"`
	Amount       uint8  `json:"amount"`
	UserPublicId string `json:"-"`
}

type Product

type Product struct {
	Id    int    `db:"id" json:"id"`
	SKU   string `db:"sku" json:"sku"`
	Name  string `db:"name" json:"name"`
	Stock int    `db:"stock" json:"stock"`
	Price int    `db:"price" json:"price"`
}

func (Product) IsExists

func (p Product) IsExists() bool

func (*Product) UpdateStockProduct

func (p *Product) UpdateStockProduct(amount uint8) (err error)

type ProductRepository

type ProductRepository interface {
	GetProductBySKU(ctx context.Context, productSKU string) (model Product, err error)
	UpdateProductStockWithTx(ctx context.Context, tx *sqlx.Tx, product Product) (err error)
}

type Transaction

type Transaction struct {
	Id           int               `db:"id"`
	UserPublicId string            `db:"user_public_id"`
	ProductId    uint              `db:"product_id"`
	ProductPrice uint              `db:"product_price"`
	Amount       uint8             `db:"amount"`
	SubTotal     uint              `db:"sub_total"`
	PlatformFee  uint              `db:"platform_fee"`
	GrandTotal   uint              `db:"grand_total"`
	Status       TransactionStatus `db:"status"`
	ProductJSON  json.RawMessage   `db:"product_snapshot"`
	CreatedAt    time.Time         `db:"created_at"`
	UpdatedAt    time.Time         `db:"updated_at"`
}

func NewTransaction

func NewTransaction(userPublicId string) Transaction

func NewTransactionFromCreateRequest

func NewTransactionFromCreateRequest(req CreateTransactionRequestPayload) Transaction

func (*Transaction) FromProduct

func (t *Transaction) FromProduct(product Product) *Transaction

set productId, price, and json

func (Transaction) GetProduct

func (t Transaction) GetProduct() (product Product, err error)

func (Transaction) GetStatus

func (t Transaction) GetStatus() string

func (*Transaction) SetGrandTotal

func (t *Transaction) SetGrandTotal() *Transaction

set subtotal and grandtotal

func (*Transaction) SetPlatformFee

func (t *Transaction) SetPlatformFee(platformFee uint) *Transaction

func (*Transaction) SetProductJSON

func (t *Transaction) SetProductJSON(product Product) (err error)

func (*Transaction) SetSubTotal

func (t *Transaction) SetSubTotal()

func (Transaction) Validate

func (t Transaction) Validate() (err error)

func (Transaction) ValidateStock

func (t Transaction) ValidateStock(productStock uint8) (err error)

type TransactionDBRepository

type TransactionDBRepository interface {
	Begin(ctx context.Context) (tx *sqlx.Tx, err error)
	Commit(ctx context.Context, tx *sqlx.Tx) (err error)
	Rollback(ctx context.Context, tx *sqlx.Tx) (err error)
}

type TransactionRepository

type TransactionRepository interface {
	CreateTransactionWithTx(ctx context.Context, tx *sqlx.Tx, trx Transaction) (err error)
}

type TransactionStatus

type TransactionStatus uint8

Jump to

Keyboard shortcuts

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