account

package
v0.0.0-...-cff5d44 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubjectTransferIncoming = "Account.TransferIncoming"
	SubjectTransferOutgoing = "Account.TransferOutgoing"
)

Variables

View Source
var (
	NotAvailable = rescode.New(4000, http.StatusForbidden, codes.Unavailable, "not_available", rescode.R{
		"isNotAvailable": true,
	})
	BalanceInsufficient = rescode.New(4001, http.StatusForbidden, codes.Unavailable, "balance_insufficient", rescode.R{
		"isBalanceInsufficient": true,
	})
	NotFound = rescode.New(4002, http.StatusNotFound, codes.NotFound, "not_found", rescode.R{
		"isNotFound": true,
	})
	ToAccNotAvailable = rescode.New(4003, http.StatusForbidden, codes.Unavailable, "to_acc_not_available", rescode.R{
		"isToAccNotAvailable": true,
	})
	TransferToSameAccount = rescode.New(4004, http.StatusForbidden, codes.Unavailable, "transfer_to_same_account", rescode.R{
		"isTransferToSameAccount": true,
	})
	CurrencyMismatch = rescode.New(4005, http.StatusForbidden, codes.Unavailable, "currency_mismatch", rescode.R{
		"isCurrencyMismatch": true,
	})
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID     uuid.UUID `json:"id"`
	UserId uuid.UUID `json:"user_id"`
	Name   string    `json:"name"`
	Owner  string    `json:"owner"`
	Iban   string    `json:"iban"`

	// ISO 4217 currency code
	Currency  string          `json:"currency" example:"EUR"`
	Status    Status          `json:"status"`
	Balance   decimal.Decimal `json:"balance"`
	CreatedAt time.Time       `json:"created_at"`
	UpdatedAt time.Time       `json:"updated_at"`
	DeletedAt time.Time       `json:"deleted_at"`
}

func New

func New(cnf Config) *Account

func (*Account) Activate

func (a *Account) Activate()

func (*Account) CanCredit

func (a *Account) CanCredit(amount decimal.Decimal) bool

func (*Account) Credit

func (a *Account) Credit(amount decimal.Decimal)

func (*Account) Debit

func (a *Account) Debit(amount decimal.Decimal)

func (*Account) Freeze

func (a *Account) Freeze()

func (*Account) IsAvailable

func (a *Account) IsAvailable() bool

func (*Account) Lock

func (a *Account) Lock()

func (*Account) Suspend

func (a *Account) Suspend()

type AccountListItem

type AccountListItem struct {
	ID       uuid.UUID `json:"id"`
	Name     string    `json:"name"`
	Owner    string    `json:"owner"`
	Iban     string    `json:"iban"`
	Currency string    `json:"currency"`
	Balance  string    `json:"balance"`
	Status   string    `json:"status"`
}

type Config

type Config struct {
	UserId   uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
	Name     string    `example:"My Account"`
	Owner    string    `example:"John Doe"`
	Currency string    `example:"EUR"` // ISO 4217 currency code
}

type EventTranfserIncoming

type EventTranfserIncoming struct {
	Email       string `json:"email"`
	Name        string `json:"name"`
	Amount      string `json:"amount"`
	Currency    string `json:"currency"`
	Account     string `json:"account"`
	Description string `json:"description"`
}

type EventTranfserOutgoing

type EventTranfserOutgoing struct {
	Email       string `json:"email"`
	Name        string `json:"name"`
	Amount      string `json:"amount"`
	Currency    string `json:"currency"`
	Account     string `json:"account"`
	Description string `json:"description"`
}

type FindByIbanAndOwnerOpts

type FindByIbanAndOwnerOpts struct {
	Iban  string `example:"TR0000000000000000000000"`
	Owner string `example:"John Doe"`
}

type FindByIdOpts

type FindByIdOpts struct {
	ID uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
}

type FindByUserIdAndIdOpts

type FindByUserIdAndIdOpts struct {
	UserId uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
	ID     uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
}

type ListByUserIdOpts

type ListByUserIdOpts struct {
	UserId uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
	Pagi   *list.PagiRequest
}

type Repo

type Repo interface {
	txadapter.Repo
	Save(ctx context.Context, t trace.Tracer, opts SaveOpts) error
	ListByUserId(ctx context.Context, t trace.Tracer, opts ListByUserIdOpts) (*list.PagiResponse[*Account], error)
	FindByIbanAndOwner(ctx context.Context, t trace.Tracer, opts FindByIbanAndOwnerOpts) (*Account, error)
	FindByUserIdAndId(ctx context.Context, t trace.Tracer, opts FindByUserIdAndIdOpts) (*Account, error)
	FindById(ctx context.Context, t trace.Tracer, opts FindByIdOpts) (*Account, error)
}

type SaveOpts

type SaveOpts struct {
	Acount *Account `example:"{}"`
}

type Status

type Status string
const (
	StatusActive    Status = "active"
	StatusLocked    Status = "locked"
	StatusFrozen    Status = "frozen"
	StatusSuspended Status = "suspended"
)

func (Status) String

func (s Status) String() string

type Transaction

type Transaction struct {
	ID          uuid.UUID       `json:"id"`
	SenderId    uuid.UUID       `json:"sender_id"`
	ReceiverId  uuid.UUID       `json:"receiver_id"`
	Amount      decimal.Decimal `json:"amount"`
	Description string          `json:"description"`
	Kind        TransactionKind `json:"kind"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	DeletedAt time.Time `json:"deleted_at"`
}

func NewTransaction

func NewTransaction(cnf TransactionConfig) *Transaction

func (*Transaction) IsItself

func (t *Transaction) IsItself() bool

func (*Transaction) IsUserReceiver

func (t *Transaction) IsUserReceiver(userId uuid.UUID) bool

func (*Transaction) IsUserSender

func (t *Transaction) IsUserSender(userId uuid.UUID) bool

type TransactionConfig

type TransactionConfig struct {
	SenderId    uuid.UUID       `example:"00000000-0000-0000-0000-000000000000"`
	ReceiverId  uuid.UUID       `example:"00000000-0000-0000-0000-000000000000"`
	Amount      decimal.Decimal `example:"100.00"`
	Description string          `example:"Transfer"`
	Kind        TransactionKind `example:"withdrawal"`
}

type TransactionDirection

type TransactionDirection string
const (
	TransactionDirectionIncoming TransactionDirection = "incoming"
	TransactionDirectionOutgoing TransactionDirection = "outgoing"
	TransactionDirectionInternal TransactionDirection = "internal"
)

func (TransactionDirection) String

func (td TransactionDirection) String() string

type TransactionFilterOpts

type TransactionFilterOpts struct {
	AccountId uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
	Pagi      *list.PagiRequest
	Filters   *TransactionFilters
}

type TransactionFilters

type TransactionFilters struct {
	StartDate string `json:"start_date" query:"start_date" validate:"omitempty,datetime=2006-01-02"`
	EndDate   string `json:"end_date" query:"end_date" validate:"omitempty,datetime=2006-01-02"`
	Kind      string `json:"kind" query:"kind" validate:"omitempty,oneof=withdrawal deposit transfer fee"`
}

type TransactionKind

type TransactionKind string
const (
	TransactionKindWithdrawal TransactionKind = "withdrawal"
	TransactionKindDeposit    TransactionKind = "deposit"
	TransactionKindTransfer   TransactionKind = "transfer"
	TransactionKindFee        TransactionKind = "fee"
)

func (TransactionKind) String

func (tk TransactionKind) String() string

type TransactionListItem

type TransactionListItem struct {
	ID          uuid.UUID  `json:"id"`
	AccountId   *uuid.UUID `json:"account_id,omitempty"`
	AccountName *string    `json:"account_name,omitempty"`
	Amount      string     `json:"amount"`
	Description string     `json:"description"`
	Kind        string     `json:"kind"`
	Direction   string     `json:"direction"`
	CreatedAt   string     `json:"created_at"`
}

type TransactionRepo

type TransactionRepo interface {
	txadapter.Repo
	Save(ctx context.Context, t trace.Tracer, opts TransactionSaveOpts) error
	Filter(ctx context.Context, t trace.Tracer, opts TransactionFilterOpts) (*list.PagiResponse[*Transaction], error)
}

type TransactionSaveOpts

type TransactionSaveOpts struct {
	Transaction *Transaction `example:"{}"`
}

Jump to

Keyboard shortcuts

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