setting up the wallet service

This commit is contained in:
Samuel Tariku 2025-04-03 23:57:59 +03:00
parent 5cc125d450
commit 7405023336
16 changed files with 836 additions and 16 deletions

View File

@ -74,6 +74,9 @@ DROP TYPE IF EXISTS ua_status;
DROP TYPE IF EXISTS ua_registaration_type; DROP TYPE IF EXISTS ua_registaration_type;
-- Drop FortuneBet -- Drop FortuneBet
DROP TABLE IF EXIST tickets; DROP TABLE IF EXISTS tickets;
DROP TABLE IF EXIST bets; DROP TABLE IF EXISTS bets;
DROP TABLE IF EXISTS wallets;
DROP TABLE IF EXISTS transactions;
DROP TABLE IF EXISTS customer_wallets;

View File

@ -47,8 +47,8 @@ CREATE TABLE IF NOT EXISTS bets (
branch_id BIGINT, branch_id BIGINT,
user_id BIGINT, user_id BIGINT,
cashed_out BOOLEAN DEFAULT FALSE, cashed_out BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
is_shop_bet BOOLEAN NOT NULL, is_shop_bet BOOLEAN NOT NULL,
CHECK (user_id IS NOT NULL OR branch_id IS NOT NULL) CHECK (user_id IS NOT NULL OR branch_id IS NOT NULL)
); );
@ -57,11 +57,10 @@ CREATE TABLE IF NOT EXISTS tickets (
id BIGSERIAL PRIMARY KEY, id BIGSERIAL PRIMARY KEY,
amount BIGINT NULL, amount BIGINT NULL,
total_odds REAL NOT NULL, total_odds REAL NOT NULL,
created_at TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
-- CREATE TABLE IF NOT EXISTS bet_outcomes ( -- CREATE TABLE IF NOT EXISTS bet_outcomes (
-- id BIGSERIAL PRIMARY KEY, -- id BIGSERIAL PRIMARY KEY,
-- bet_id BIGINT NOT NULL, -- bet_id BIGINT NOT NULL,
@ -74,6 +73,40 @@ CREATE TABLE IF NOT EXISTS tickets (
-- outcome_id BIGINT NOT NULL, -- outcome_id BIGINT NOT NULL,
-- ); -- );
CREATE TABLE IF NOT EXISTS wallets (
id BIGSERIAL PRIMARY KEY,
balance BIGINT NOT NULL,
is_withdraw BOOLEAN NOT NULL,
is_bettable BOOLEAN NOT NULL,
user_id BIGINT NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS customer_wallets (
id BIGSERIAL PRIMARY KEY,
customer_id BIGINT NOT NULL,
company_id BIGINT NOT NULL,
regular_wallet_id BIGINT NOT NULL,
static_wallet_id BIGINT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
UNIQUE (customer_id, company_id)
);
CREATE TABLE IF NOT EXISTS transactions (
id BIGSERIAL PRIMARY KEY,
amount BIGINT NOT NULL,
transaction_type VARCHAR(255) NOT NULL,
wallet_id BIGINT NOT NULL,
verified BOOLEAN NOT NULL DEFAULT false,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
----------------------------------------------seed data------------------------------------------------------------- ----------------------------------------------seed data-------------------------------------------------------------
-------------------------------------- DO NOT USE IN PRODUCTION------------------------------------------------- -------------------------------------- DO NOT USE IN PRODUCTION-------------------------------------------------

14
db/query/transactions.sql Normal file
View File

@ -0,0 +1,14 @@
-- name: CreateTransaction :one
INSERT INTO transactions (amount, transaction_type, wallet_id) VALUES ($1, $2, $3) RETURNING *;
-- name: GetAllTransactions :many
SELECT * FROM transactions;
-- name: GetTransactionsByWallet :many
SELECT * FROM transactions WHERE wallet_id = $1;
-- name: GetTransactionByID :one
SELECT * FROM transactions WHERE id = $1;
-- name: UpdateTransferVerification :exec
UPDATE transactions SET verified = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2;

34
db/query/wallet.sql Normal file
View File

@ -0,0 +1,34 @@
-- name: CreateWallet :one
INSERT INTO wallets (balance, is_withdraw, is_bettable, user_id) VALUES ($1, $2, $3, $4) RETURNING *;
-- name: CreateCustomerWallet :one
INSERT INTO customer_wallets (customer_id, company_id, regular_wallet_id, static_wallet_id) VALUES ($1, $2, $3, $4) RETURNING *;
-- name: GetAllWallets :many
SELECT * FROM wallets;
-- name: GetWalletByID :one
SELECT * FROM wallets WHERE id = $1;
-- name: GetCustomerWallet :one
SELECT
cw.id,
cw.customer_id,
cw.company_id,
rw.id AS regular_id,
rw.balance AS regular_balance,
sw.id AS static_id,
sw.balance AS static_balance
FROM customer_wallets cw
JOIN wallets rw ON cw.regular_wallet_id = rw.id
JOIN wallets sw ON cw.static_wallet_id = sw.id
WHERE cw.customer_id = $1 AND cw.company_id = $2;
-- name: UpdateBalance :exec
UPDATE wallets SET balance = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2;
-- name: UpdateWalletActive :exec
UPDATE wallets SET is_active = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2;

View File

@ -23,6 +23,16 @@ type Bet struct {
IsShopBet bool IsShopBet bool
} }
type CustomerWallet struct {
ID int64
CustomerID int64
CompanyID int64
RegularWalletID int64
StaticWalletID int64
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
}
type Notification struct { type Notification struct {
ID string ID string
RecipientID string RecipientID string
@ -69,6 +79,16 @@ type Ticket struct {
UpdatedAt pgtype.Timestamp UpdatedAt pgtype.Timestamp
} }
type Transaction struct {
ID int64
Amount int64
TransactionType string
WalletID int64
Verified bool
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
}
type User struct { type User struct {
ID int64 ID int64
FirstName string FirstName string
@ -84,3 +104,14 @@ type User struct {
SuspendedAt pgtype.Timestamptz SuspendedAt pgtype.Timestamptz
Suspended bool Suspended bool
} }
type Wallet struct {
ID int64
Balance int64
IsWithdraw bool
IsBettable bool
UserID int64
IsActive bool
CreatedAt pgtype.Timestamp
UpdatedAt pgtype.Timestamp
}

132
gen/db/transactions.sql.go Normal file
View File

@ -0,0 +1,132 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: transactions.sql
package dbgen
import (
"context"
)
const CreateTransaction = `-- name: CreateTransaction :one
INSERT INTO transactions (amount, transaction_type, wallet_id) VALUES ($1, $2, $3) RETURNING id, amount, transaction_type, wallet_id, verified, created_at, updated_at
`
type CreateTransactionParams struct {
Amount int64
TransactionType string
WalletID int64
}
func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionParams) (Transaction, error) {
row := q.db.QueryRow(ctx, CreateTransaction, arg.Amount, arg.TransactionType, arg.WalletID)
var i Transaction
err := row.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const GetAllTransactions = `-- name: GetAllTransactions :many
SELECT id, amount, transaction_type, wallet_id, verified, created_at, updated_at FROM transactions
`
func (q *Queries) GetAllTransactions(ctx context.Context) ([]Transaction, error) {
rows, err := q.db.Query(ctx, GetAllTransactions)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Transaction
for rows.Next() {
var i Transaction
if err := rows.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetTransactionByID = `-- name: GetTransactionByID :one
SELECT id, amount, transaction_type, wallet_id, verified, created_at, updated_at FROM transactions WHERE id = $1
`
func (q *Queries) GetTransactionByID(ctx context.Context, id int64) (Transaction, error) {
row := q.db.QueryRow(ctx, GetTransactionByID, id)
var i Transaction
err := row.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const GetTransactionsByWallet = `-- name: GetTransactionsByWallet :many
SELECT id, amount, transaction_type, wallet_id, verified, created_at, updated_at FROM transactions WHERE wallet_id = $1
`
func (q *Queries) GetTransactionsByWallet(ctx context.Context, walletID int64) ([]Transaction, error) {
rows, err := q.db.Query(ctx, GetTransactionsByWallet, walletID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Transaction
for rows.Next() {
var i Transaction
if err := rows.Scan(
&i.ID,
&i.Amount,
&i.TransactionType,
&i.WalletID,
&i.Verified,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const UpdateTransferVerification = `-- name: UpdateTransferVerification :exec
UPDATE transactions SET verified = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2
`
type UpdateTransferVerificationParams struct {
Verified bool
ID int64
}
func (q *Queries) UpdateTransferVerification(ctx context.Context, arg UpdateTransferVerificationParams) error {
_, err := q.db.Exec(ctx, UpdateTransferVerification, arg.Verified, arg.ID)
return err
}

199
gen/db/wallet.sql.go Normal file
View File

@ -0,0 +1,199 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.28.0
// source: wallet.sql
package dbgen
import (
"context"
)
const CreateCustomerWallet = `-- name: CreateCustomerWallet :one
INSERT INTO customer_wallets (customer_id, company_id, regular_wallet_id, static_wallet_id) VALUES ($1, $2, $3, $4) RETURNING id, customer_id, company_id, regular_wallet_id, static_wallet_id, created_at, updated_at
`
type CreateCustomerWalletParams struct {
CustomerID int64
CompanyID int64
RegularWalletID int64
StaticWalletID int64
}
func (q *Queries) CreateCustomerWallet(ctx context.Context, arg CreateCustomerWalletParams) (CustomerWallet, error) {
row := q.db.QueryRow(ctx, CreateCustomerWallet,
arg.CustomerID,
arg.CompanyID,
arg.RegularWalletID,
arg.StaticWalletID,
)
var i CustomerWallet
err := row.Scan(
&i.ID,
&i.CustomerID,
&i.CompanyID,
&i.RegularWalletID,
&i.StaticWalletID,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const CreateWallet = `-- name: CreateWallet :one
INSERT INTO wallets (balance, is_withdraw, is_bettable, user_id) VALUES ($1, $2, $3, $4) RETURNING id, balance, is_withdraw, is_bettable, user_id, is_active, created_at, updated_at
`
type CreateWalletParams struct {
Balance int64
IsWithdraw bool
IsBettable bool
UserID int64
}
func (q *Queries) CreateWallet(ctx context.Context, arg CreateWalletParams) (Wallet, error) {
row := q.db.QueryRow(ctx, CreateWallet,
arg.Balance,
arg.IsWithdraw,
arg.IsBettable,
arg.UserID,
)
var i Wallet
err := row.Scan(
&i.ID,
&i.Balance,
&i.IsWithdraw,
&i.IsBettable,
&i.UserID,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const GetAllWallets = `-- name: GetAllWallets :many
SELECT id, balance, is_withdraw, is_bettable, user_id, is_active, created_at, updated_at FROM wallets
`
func (q *Queries) GetAllWallets(ctx context.Context) ([]Wallet, error) {
rows, err := q.db.Query(ctx, GetAllWallets)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Wallet
for rows.Next() {
var i Wallet
if err := rows.Scan(
&i.ID,
&i.Balance,
&i.IsWithdraw,
&i.IsBettable,
&i.UserID,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetCustomerWallet = `-- name: GetCustomerWallet :one
SELECT
cw.id,
cw.customer_id,
cw.company_id,
rw.id AS regular_id,
rw.balance AS regular_balance,
sw.id AS static_id,
sw.balance AS static_balance
FROM customer_wallets cw
JOIN wallets rw ON cw.regular_wallet_id = rw.id
JOIN wallets sw ON cw.static_wallet_id = sw.id
WHERE cw.customer_id = $1 AND cw.company_id = $2
`
type GetCustomerWalletParams struct {
CustomerID int64
CompanyID int64
}
type GetCustomerWalletRow struct {
ID int64
CustomerID int64
CompanyID int64
RegularID int64
RegularBalance int64
StaticID int64
StaticBalance int64
}
func (q *Queries) GetCustomerWallet(ctx context.Context, arg GetCustomerWalletParams) (GetCustomerWalletRow, error) {
row := q.db.QueryRow(ctx, GetCustomerWallet, arg.CustomerID, arg.CompanyID)
var i GetCustomerWalletRow
err := row.Scan(
&i.ID,
&i.CustomerID,
&i.CompanyID,
&i.RegularID,
&i.RegularBalance,
&i.StaticID,
&i.StaticBalance,
)
return i, err
}
const GetWalletByID = `-- name: GetWalletByID :one
SELECT id, balance, is_withdraw, is_bettable, user_id, is_active, created_at, updated_at FROM wallets WHERE id = $1
`
func (q *Queries) GetWalletByID(ctx context.Context, id int64) (Wallet, error) {
row := q.db.QueryRow(ctx, GetWalletByID, id)
var i Wallet
err := row.Scan(
&i.ID,
&i.Balance,
&i.IsWithdraw,
&i.IsBettable,
&i.UserID,
&i.IsActive,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const UpdateBalance = `-- name: UpdateBalance :exec
UPDATE wallets SET balance = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2
`
type UpdateBalanceParams struct {
Balance int64
ID int64
}
func (q *Queries) UpdateBalance(ctx context.Context, arg UpdateBalanceParams) error {
_, err := q.db.Exec(ctx, UpdateBalance, arg.Balance, arg.ID)
return err
}
const UpdateWalletActive = `-- name: UpdateWalletActive :exec
UPDATE wallets SET is_active = $1, updated_at = CURRENT_TIMESTAMP WHERE id = $2
`
type UpdateWalletActiveParams struct {
IsActive bool
ID int64
}
func (q *Queries) UpdateWalletActive(ctx context.Context, arg UpdateWalletActiveParams) error {
_, err := q.db.Exec(ctx, UpdateWalletActive, arg.IsActive, arg.ID)
return err
}

View File

@ -1,13 +1,14 @@
package domain package domain
type Branch struct { type Branch struct {
ID int64 ID int64
Name string Name string
Location string Location string
BranchManagerID int64 WalletID int64
IsSelfOwned bool BranchManagerID int64
IsSelfOwned bool
IsSupportingSportBook bool IsSupportingSportBook bool
IsSupportingVirtual bool IsSupportingVirtual bool
IsSupportingGameZone bool IsSupportingGameZone bool
} }

View File

@ -0,0 +1,22 @@
package domain
type TransactionType string
const (
DEPOSIT TransactionType = "deposit"
WITHDRAW TransactionType = "withdraw"
)
type Transaction struct {
ID int64
Amount Currency
Type TransactionType
Verified bool
WalletID int64
}
type CreateTransaction struct {
Amount Currency
Type TransactionType
WalletID int64
}

41
internal/domain/wallet.go Normal file
View File

@ -0,0 +1,41 @@
package domain
type Wallet struct {
ID int64
Balance Currency
IsWithdraw bool
IsBettable bool
IsActive bool
UserID int64
}
type CustomerWallet struct {
ID int64
RegularID int64
StaticID int64
CustomerID int64
CompanyID int64
}
type GetCustomerWallet struct {
ID int64
RegularID int64
RegularBalance Currency
StaticID int64
StaticBalance Currency
CustomerID int64
CompanyID int64
}
type CreateWallet struct {
Balance Currency
IsWithdraw bool
IsBettable bool
UserID int64
}
type CreateCustomerWallet struct {
CustomerID int64
CompanyID int64
RegularWalletID int64
StaticWalletID int64
}

View File

@ -0,0 +1,76 @@
package repository
import (
"context"
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
func convertDBTransaction(transaction dbgen.Transaction) domain.Transaction {
return domain.Transaction{
ID: transaction.ID,
Amount: domain.Currency(transaction.Amount),
Type: domain.TransactionType(transaction.TransactionType),
Verified: transaction.Verified,
WalletID: transaction.WalletID,
}
}
func convertCreateTransaction(transaction domain.CreateTransaction) dbgen.CreateTransactionParams {
return dbgen.CreateTransactionParams{
Amount: int64(transaction.Amount),
TransactionType: string(transaction.Type),
WalletID: transaction.WalletID,
}
}
func (s *Store) CreateTransaction(ctx context.Context, transaction domain.CreateTransaction) (domain.Transaction, error) {
newTransaction, err := s.queries.CreateTransaction(ctx, convertCreateTransaction(transaction))
if err != nil {
return domain.Transaction{}, err
}
return convertDBTransaction(newTransaction), nil
}
func (s *Store) GetAllTransactions(ctx context.Context) ([]domain.Transaction, error) {
transactions, err := s.queries.GetAllTransactions(ctx)
if err != nil {
return nil, err
}
var result []domain.Transaction
for _, transaction := range transactions {
result = append(result, convertDBTransaction(transaction))
}
return result, nil
}
func (s *Store) GetTransactionsByWallet(ctx context.Context, walletID int64) ([]domain.Transaction, error) {
transactions, err := s.queries.GetTransactionsByWallet(ctx, walletID)
if err != nil {
return nil, err
}
var result []domain.Transaction
for _, transaction := range transactions {
result = append(result, convertDBTransaction(transaction))
}
return result, nil
}
func (s *Store) GetTransactionByID(ctx context.Context, id int64) (domain.Transaction, error){
transaction, err := s.queries.GetTransactionByID(ctx, id);
if err != nil {
return domain.Transaction{}, nil
}
return convertDBTransaction(transaction), nil
}
func (s *Store) UpdateTransferVerification(ctx context.Context, id int64, verified bool) error{
err := s.queries.UpdateTransferVerification(ctx, dbgen.UpdateTransferVerificationParams{
ID: id,
Verified: verified,
})
return err
}

View File

@ -0,0 +1,124 @@
package repository
import (
"context"
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
func convertDBWallet(wallet dbgen.Wallet) domain.Wallet {
return domain.Wallet{
ID: wallet.ID,
Balance: domain.Currency(wallet.Balance),
IsWithdraw: wallet.IsWithdraw,
IsBettable: wallet.IsBettable,
IsActive: wallet.IsActive,
UserID: wallet.UserID,
}
}
func convertCreateWallet(wallet domain.CreateWallet) dbgen.CreateWalletParams {
return dbgen.CreateWalletParams{
Balance: int64(wallet.Balance),
IsWithdraw: wallet.IsWithdraw,
IsBettable: wallet.IsBettable,
UserID: wallet.UserID,
}
}
func convertDBCustomerWallet(customerWallet dbgen.CustomerWallet) domain.CustomerWallet {
return domain.CustomerWallet{
ID: customerWallet.ID,
RegularID: customerWallet.RegularWalletID,
StaticID: customerWallet.StaticWalletID,
CustomerID: customerWallet.CustomerID,
CompanyID: customerWallet.CompanyID,
}
}
func convertCreateCustomerWallet(customerWallet domain.CreateCustomerWallet) dbgen.CreateCustomerWalletParams {
return dbgen.CreateCustomerWalletParams{
CustomerID: customerWallet.CustomerID,
CompanyID: customerWallet.CompanyID,
RegularWalletID: customerWallet.RegularWalletID,
StaticWalletID: customerWallet.StaticWalletID,
}
}
func convertDBGetCustomerWallet(customerWallet dbgen.GetCustomerWalletRow) domain.GetCustomerWallet {
return domain.GetCustomerWallet{
ID: customerWallet.ID,
RegularID: customerWallet.RegularID,
RegularBalance: domain.Currency(customerWallet.RegularBalance),
StaticID: customerWallet.StaticID,
StaticBalance: domain.Currency(customerWallet.StaticBalance),
CustomerID: customerWallet.CustomerID,
CompanyID: customerWallet.CompanyID,
}
}
func (s *Store) CreateWallet(ctx context.Context, wallet domain.CreateWallet) (domain.Wallet, error) {
newWallet, err := s.queries.CreateWallet(ctx, convertCreateWallet(wallet))
if err != nil {
return domain.Wallet{}, err
}
return convertDBWallet(newWallet), nil
}
func (s *Store) CreateCustomerWallet(ctx context.Context, customerWallet domain.CreateCustomerWallet) (domain.CustomerWallet, error) {
newCustomerWallet, err := s.queries.CreateCustomerWallet(ctx, convertCreateCustomerWallet(customerWallet))
if err != nil {
return domain.CustomerWallet{}, err
}
return convertDBCustomerWallet(newCustomerWallet), nil
}
func (s *Store) GetWalletByID(ctx context.Context, id int64) (domain.Wallet, error) {
wallet, err := s.queries.GetWalletByID(ctx, id)
if err != nil {
return domain.Wallet{}, err
}
return convertDBWallet(wallet), nil
}
func (s *Store) GetAllWallets(ctx context.Context) ([]domain.Wallet, error) {
wallets, err := s.queries.GetAllWallets(ctx)
if err != nil {
return nil, err
}
var result []domain.Wallet
for _, wallet := range wallets {
result = append(result, convertDBWallet(wallet))
}
return result, nil
}
func (s *Store) GetCustomerWallet(ctx context.Context, customerID int64, companyID int64) (domain.GetCustomerWallet, error) {
customerWallet, err := s.queries.GetCustomerWallet(ctx, dbgen.GetCustomerWalletParams{
CustomerID: customerID,
CompanyID: companyID,
})
if err != nil {
return domain.GetCustomerWallet{}, err
}
return convertDBGetCustomerWallet(customerWallet), nil
}
func (s *Store) UpdateBalance(ctx context.Context, id int64, balance domain.Currency) error {
err := s.queries.UpdateBalance(ctx, dbgen.UpdateBalanceParams{
ID: id,
Balance: int64(balance),
})
return err
}
func (s *Store) UpdateWalletActive(ctx context.Context, id int64, isActive bool) error {
err := s.queries.UpdateWalletActive(ctx, dbgen.UpdateWalletActiveParams{
ID: id,
IsActive: isActive,
})
return err
}

View File

@ -0,0 +1,15 @@
package transaction
import (
"context"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
type TransactionStore interface {
CreateTransaction(ctx context.Context, transaction domain.CreateTransaction) (domain.Transaction, error)
GetAllTransactions(ctx context.Context) ([]domain.Transaction, error)
GetTransactionsByWallet(ctx context.Context, walletID int64) ([]domain.Transaction, error)
GetTransactionByID(ctx context.Context, id int64) (domain.Transaction, error)
UpdateTransferVerification(ctx context.Context, id int64, verified bool) error
}

View File

@ -0,0 +1,33 @@
package transaction
import (
"context"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
type Service struct {
transactionStore TransactionStore
}
func NewService(transactionStore TransactionStore) *Service {
return &Service{
transactionStore: transactionStore,
}
}
func (s *Service) CreateTransaction(ctx context.Context, transaction domain.CreateTransaction) (domain.Transaction, error) {
return s.transactionStore.CreateTransaction(ctx, transaction)
}
func (s *Service) GetAllTransactions(ctx context.Context) ([]domain.Transaction, error) {
return s.transactionStore.GetAllTransactions(ctx)
}
func (s *Service) GetTransactionByID(ctx context.Context, id int64) (domain.Transaction, error) {
return s.transactionStore.GetTransactionByID(ctx, id)
}
func (s *Service) UpdateTransferVerification(ctx context.Context, id int64, verified bool) error {
return s.transactionStore.UpdateTransferVerification(ctx, id, verified)
}

View File

@ -0,0 +1,17 @@
package wallet
import (
"context"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
type WalletStore interface {
CreateWallet(ctx context.Context, wallet domain.CreateWallet) (domain.Wallet, error)
CreateCustomerWallet(ctx context.Context, customerWallet domain.CreateCustomerWallet) (domain.CustomerWallet, error)
GetWalletByID(ctx context.Context, id int64) (domain.Wallet, error)
GetAllWallets(ctx context.Context) ([]domain.Wallet, error)
GetCustomerWallet(ctx context.Context, customerID int64, companyID int64) (domain.GetCustomerWallet, error)
UpdateBalance(ctx context.Context, id int64, balance domain.Currency) error
UpdateWalletActive(ctx context.Context, id int64, isActive bool) error
}

View File

@ -0,0 +1,45 @@
package wallet
import (
"context"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
)
type Service struct {
walletStore WalletStore
}
func NewService(walletStore WalletStore) *Service {
return &Service{
walletStore: walletStore,
}
}
func (s *Service) CreateWallet(ctx context.Context, wallet domain.CreateWallet) (domain.Wallet, error) {
return s.walletStore.CreateWallet(ctx, wallet)
}
func (s *Service) CreateCustomerWallet(ctx context.Context, customerWallet domain.CreateCustomerWallet) (domain.CustomerWallet, error) {
return s.walletStore.CreateCustomerWallet(ctx, customerWallet)
}
func (s *Service) GetWalletByID(ctx context.Context, id int64) (domain.Wallet, error) {
return s.walletStore.GetWalletByID(ctx, id)
}
func (s *Service) GetAllWallets(ctx context.Context) ([]domain.Wallet, error) {
return s.walletStore.GetAllWallets(ctx)
}
func (s *Service) GetCustomerWallet(ctx context.Context, customerID int64, companyID int64) (domain.GetCustomerWallet, error) {
return s.walletStore.GetCustomerWallet(ctx, customerID, companyID)
}
func (s *Service) UpdateBalance(ctx context.Context, id int64, balance domain.Currency) error {
return s.walletStore.UpdateBalance(ctx, id, balance)
}
func (s *Service) UpdateWalletActive(ctx context.Context, id int64, isActive bool) error {
return s.walletStore.UpdateWalletActive(ctx, id, isActive)
}