113 lines
3.6 KiB
Go
113 lines
3.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"time"
|
|
"math/big"
|
|
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
type DirectDepositStatus string
|
|
|
|
const (
|
|
DepositStatusPending DirectDepositStatus = "pending"
|
|
DepositStatusCompleted DirectDepositStatus = "completed"
|
|
DepositStatusRejected DirectDepositStatus = "rejected"
|
|
)
|
|
|
|
type DirectDeposit struct {
|
|
ID int64 `json:"id"`
|
|
CustomerID int64 `json:"customer_id"`
|
|
WalletID int64 `json:"wallet_id"`
|
|
Wallet Wallet `json:"wallet"`
|
|
Amount Currency `json:"amount"`
|
|
BankReference string `json:"bank_reference"`
|
|
SenderAccount string `json:"sender_account"`
|
|
Status DirectDepositStatus `json:"status"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
VerifiedBy *int64 `json:"verified_by"`
|
|
VerificationNotes string `json:"verification_notes"`
|
|
VerifiedAt *time.Time `json:"verified_at"`
|
|
}
|
|
|
|
type CreateDirectDeposit struct {
|
|
CustomerID int64
|
|
WalletID int64
|
|
Amount Currency
|
|
BankReference string
|
|
SenderAccount string
|
|
Status DirectDepositStatus
|
|
}
|
|
|
|
type UpdateDirectDeposit struct {
|
|
ID int64
|
|
Status DirectDepositStatus
|
|
VerifiedBy int64
|
|
VerificationNotes string
|
|
VerifiedAt time.Time
|
|
}
|
|
|
|
type DirectDepositRequest struct {
|
|
CustomerID int64 `json:"customer_id" binding:"required"`
|
|
Amount Currency `json:"amount" binding:"required,gt=0"`
|
|
BankReference string `json:"bank_reference" binding:"required"`
|
|
SenderAccount string `json:"sender_account" binding:"required"`
|
|
}
|
|
|
|
type VerifyDirectDepositRequest struct {
|
|
DepositID int64 `json:"deposit_id" binding:"required"`
|
|
IsVerified bool `json:"is_verified" binding:"required"`
|
|
Notes string `json:"notes"`
|
|
}
|
|
|
|
|
|
func ConvertDBDirectDeposit(deposit dbgen.DirectDeposit) DirectDeposit {
|
|
return DirectDeposit{
|
|
ID: deposit.ID,
|
|
CustomerID: deposit.CustomerID,
|
|
WalletID: deposit.WalletID,
|
|
Amount: Currency(deposit.Amount.Int.Int64()),
|
|
BankReference: deposit.BankReference,
|
|
SenderAccount: deposit.SenderAccount,
|
|
Status: DirectDepositStatus(deposit.Status),
|
|
CreatedAt: deposit.CreatedAt.Time,
|
|
VerifiedBy: convertPgInt64ToPtr(deposit.VerifiedBy),
|
|
VerificationNotes: deposit.VerificationNotes.String,
|
|
VerifiedAt: convertPgTimeToPtr(deposit.VerifiedAt),
|
|
}
|
|
}
|
|
|
|
func ConvertCreateDirectDeposit(deposit CreateDirectDeposit) dbgen.CreateDirectDepositParams {
|
|
return dbgen.CreateDirectDepositParams{
|
|
CustomerID: deposit.CustomerID,
|
|
WalletID: deposit.WalletID,
|
|
Amount: pgtype.Numeric{Int: big.NewInt(int64(deposit.Amount)), Valid: true},
|
|
BankReference: deposit.BankReference,
|
|
SenderAccount: deposit.SenderAccount,
|
|
Status: string(deposit.Status),
|
|
}
|
|
}
|
|
|
|
func ConvertUpdateDirectDeposit(deposit UpdateDirectDeposit) dbgen.UpdateDirectDepositParams {
|
|
return dbgen.UpdateDirectDepositParams{
|
|
ID: deposit.ID,
|
|
Status: string(deposit.Status),
|
|
VerifiedBy: pgtype.Int8{Int64: deposit.VerifiedBy, Valid: true},
|
|
VerificationNotes: pgtype.Text{String: deposit.VerificationNotes, Valid: deposit.VerificationNotes != ""},
|
|
VerifiedAt: pgtype.Timestamp{Time: deposit.VerifiedAt, Valid: true},
|
|
}
|
|
}
|
|
|
|
func convertPgInt64ToPtr(i pgtype.Int8) *int64 {
|
|
if i.Valid {
|
|
return &i.Int64
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func convertPgTimeToPtr(t pgtype.Timestamp) *time.Time {
|
|
if t.Valid {
|
|
return &t.Time
|
|
}
|
|
return nil
|
|
} |