fix veli orchestration error

This commit is contained in:
Samuel Tariku 2025-09-12 20:56:07 +03:00
parent c49e191657
commit ab6c1acdc6
8 changed files with 450 additions and 171 deletions

View File

@ -153,7 +153,7 @@ func main() {
virtualGameSvc := virtualgameservice.New(vitualGameRepo, *walletSvc, store, cfg, logger) virtualGameSvc := virtualgameservice.New(vitualGameRepo, *walletSvc, store, cfg, logger)
aleaService := alea.NewAleaPlayService(vitualGameRepo, *walletSvc, cfg, logger) aleaService := alea.NewAleaPlayService(vitualGameRepo, *walletSvc, cfg, logger)
veliCLient := veli.NewClient(cfg, walletSvc) veliCLient := veli.NewClient(cfg, walletSvc)
veliVirtualGameService := veli.New(virtualGameSvc, vitualGameRepo, veliCLient, walletSvc, wallet.TransferStore(store), cfg) veliVirtualGameService := veli.New(virtualGameSvc, vitualGameRepo, veliCLient, walletSvc, wallet.TransferStore(store), domain.MongoDBLogger, cfg)
atlasClient := atlas.NewClient(cfg, walletSvc) atlasClient := atlas.NewClient(cfg, walletSvc)
atlasVirtualGameService := atlas.New(virtualGameSvc, vitualGameRepo, atlasClient, walletSvc, wallet.TransferStore(store), cfg) atlasVirtualGameService := atlas.New(virtualGameSvc, vitualGameRepo, atlasClient, walletSvc, wallet.TransferStore(store), cfg)
recommendationSvc := recommendation.NewService(recommendationRepo) recommendationSvc := recommendation.NewService(recommendationRepo)

View File

@ -93,7 +93,7 @@ VALUES ('sms_provider', 'afro_message'),
('send_sms_on_bet_finish', 'false'), ('send_sms_on_bet_finish', 'false'),
('welcome_bonus_active', 'false'), ('welcome_bonus_active', 'false'),
('welcome_bonus_multiplier', '1.5'), ('welcome_bonus_multiplier', '1.5'),
('welcome_bonus_multiplier', '100000'), ('welcome_bonus_cap', '100000'),
('welcome_bonus_count', '3'), ('welcome_bonus_count', '3'),
('welcome_bonus_expiry', '10') ON CONFLICT (key) DO NOTHING; ('welcome_bonus_expiry', '10') ON CONFLICT (key) DO NOTHING;
-- Users -- Users

View File

@ -1,59 +1,127 @@
-- name: CreateVirtualGameProvider :one -- name: CreateVirtualGameProvider :one
INSERT INTO virtual_game_providers ( INSERT INTO virtual_game_providers (
provider_id, provider_name, logo_dark, logo_light, enabled provider_id,
) VALUES ( provider_name,
$1, $2, $3, $4, $5 logo_dark,
) RETURNING id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at; logo_light,
enabled
)
VALUES ($1, $2, $3, $4, $5)
RETURNING id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at;
-- name: DeleteVirtualGameProvider :exec -- name: DeleteVirtualGameProvider :exec
DELETE FROM virtual_game_providers DELETE FROM virtual_game_providers
WHERE provider_id = $1; WHERE provider_id = $1;
-- name: DeleteAllVirtualGameProviders :exec -- name: DeleteAllVirtualGameProviders :exec
DELETE FROM virtual_game_providers; DELETE FROM virtual_game_providers;
-- name: GetVirtualGameProviderByID :one -- name: GetVirtualGameProviderByID :one
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at SELECT id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at
FROM virtual_game_providers FROM virtual_game_providers
WHERE provider_id = $1; WHERE provider_id = $1;
-- name: ListVirtualGameProviders :many -- name: ListVirtualGameProviders :many
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at SELECT id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at
FROM virtual_game_providers FROM virtual_game_providers
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT $1 OFFSET $2; LIMIT $1 OFFSET $2;
-- name: CountVirtualGameProviders :one -- name: CountVirtualGameProviders :one
SELECT COUNT(*) AS total SELECT COUNT(*) AS total
FROM virtual_game_providers; FROM virtual_game_providers;
-- name: UpdateVirtualGameProviderEnabled :one -- name: UpdateVirtualGameProviderEnabled :one
UPDATE virtual_game_providers UPDATE virtual_game_providers
SET enabled = $2, SET enabled = $2,
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE provider_id = $1 WHERE provider_id = $1
RETURNING id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at; RETURNING id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at;
-- name: CreateVirtualGameSession :one -- name: CreateVirtualGameSession :one
INSERT INTO virtual_game_sessions ( INSERT INTO virtual_game_sessions (
user_id, game_id, session_token, currency, status, expires_at user_id,
) VALUES ( game_id,
$1, $2, $3, $4, $5, $6 session_token,
) RETURNING id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at; currency,
status,
expires_at
)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id,
user_id,
game_id,
session_token,
currency,
status,
created_at,
updated_at,
expires_at;
-- name: GetVirtualGameSessionByToken :one -- name: GetVirtualGameSessionByToken :one
SELECT id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at SELECT id,
user_id,
game_id,
session_token,
currency,
status,
created_at,
updated_at,
expires_at
FROM virtual_game_sessions FROM virtual_game_sessions
WHERE session_token = $1; WHERE session_token = $1;
-- name: UpdateVirtualGameSessionStatus :exec -- name: UpdateVirtualGameSessionStatus :exec
UPDATE virtual_game_sessions UPDATE virtual_game_sessions
SET status = $2, updated_at = CURRENT_TIMESTAMP SET status = $2,
updated_at = CURRENT_TIMESTAMP
WHERE id = $1; WHERE id = $1;
-- name: CreateVirtualGameTransaction :one -- name: CreateVirtualGameTransaction :one
INSERT INTO virtual_game_transactions ( INSERT INTO virtual_game_transactions (
session_id, user_id, company_id, provider, wallet_id, transaction_type, amount, currency, external_transaction_id, status session_id,
) VALUES ( user_id,
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10 company_id,
) RETURNING id, session_id, user_id, company_id, provider, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at; provider,
wallet_id,
transaction_type,
amount,
currency,
external_transaction_id,
status
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING id,
session_id,
user_id,
company_id,
provider,
wallet_id,
transaction_type,
amount,
currency,
external_transaction_id,
status,
created_at,
updated_at;
-- name: CreateVirtualGameHistory :one -- name: CreateVirtualGameHistory :one
INSERT INTO virtual_game_histories ( INSERT INTO virtual_game_histories (
session_id, session_id,
@ -68,10 +136,22 @@ INSERT INTO virtual_game_histories (
external_transaction_id, external_transaction_id,
reference_transaction_id, reference_transaction_id,
status status
) VALUES ( )
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 VALUES (
) RETURNING $1,
id, $2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12
)
RETURNING id,
session_id, session_id,
user_id, user_id,
company_id, company_id,
@ -87,41 +167,48 @@ INSERT INTO virtual_game_histories (
created_at, created_at,
updated_at; updated_at;
-- name: GetVirtualGameTransactionByExternalID :one -- name: GetVirtualGameTransactionByExternalID :one
SELECT id, session_id, user_id, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at SELECT id,
session_id,
user_id,
wallet_id,
transaction_type,
amount,
currency,
external_transaction_id,
status,
created_at,
updated_at
FROM virtual_game_transactions FROM virtual_game_transactions
WHERE external_transaction_id = $1; WHERE external_transaction_id = $1;
-- name: UpdateVirtualGameTransactionStatus :exec -- name: UpdateVirtualGameTransactionStatus :exec
UPDATE virtual_game_transactions UPDATE virtual_game_transactions
SET status = $2, updated_at = CURRENT_TIMESTAMP SET status = $2,
updated_at = CURRENT_TIMESTAMP
WHERE id = $1; WHERE id = $1;
-- name: GetVirtualGameSummaryInRange :many -- name: GetVirtualGameSummaryInRange :many
SELECT SELECT c.name AS company_name,
c.name AS company_name,
vg.name AS game_name, vg.name AS game_name,
COUNT(vgt.id) AS number_of_bets, COUNT(vgt.id) AS number_of_bets,
COALESCE(SUM(vgt.amount), 0) AS total_transaction_sum COALESCE(SUM(vgt.amount), 0) AS total_transaction_sum
FROM virtual_game_transactions vgt FROM virtual_game_transactions vgt
JOIN virtual_game_sessions vgs ON vgt.session_id = vgs.id JOIN virtual_game_sessions vgs ON vgt.session_id = vgs.id
JOIN virtual_games vg ON vgs.game_id = vg.id JOIN virtual_games vg ON vgs.game_id = vg.id
JOIN companies c ON vgt.company_id = c.id JOIN companies c ON vgt.company_id = c.id
WHERE vgt.transaction_type = 'BET' WHERE vgt.transaction_type = 'BET'
AND vgt.created_at BETWEEN $1 AND $2 AND vgt.created_at BETWEEN $1 AND $2
GROUP BY c.name, vg.name; GROUP BY c.name,
vg.name;
-- name: AddFavoriteGame :exec -- name: AddFavoriteGame :exec
INSERT INTO favorite_games ( INSERT INTO favorite_games (user_id, game_id, created_at)
user_id, VALUES ($1, $2, NOW()) ON CONFLICT (user_id, game_id) DO NOTHING;
game_id,
created_at
) VALUES ($1, $2, NOW())
ON CONFLICT (user_id, game_id) DO NOTHING;
-- name: RemoveFavoriteGame :exec -- name: RemoveFavoriteGame :exec
DELETE FROM favorite_games DELETE FROM favorite_games
WHERE user_id = $1 AND game_id = $2; WHERE user_id = $1
AND game_id = $2;
-- name: ListFavoriteGames :many -- name: ListFavoriteGames :many
SELECT game_id SELECT game_id
FROM favorite_games FROM favorite_games
WHERE user_id = $1; WHERE user_id = $1;
-- name: CreateVirtualGame :one -- name: CreateVirtualGame :one
INSERT INTO virtual_games ( INSERT INTO virtual_games (
game_id, game_id,
@ -136,11 +223,22 @@ INSERT INTO virtual_games (
bets, bets,
thumbnail, thumbnail,
status status
) VALUES ( )
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 VALUES (
) $1,
RETURNING $2,
id, $3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12
)
RETURNING id,
game_id, game_id,
provider_id, provider_id,
name, name,
@ -155,10 +253,8 @@ RETURNING
status, status,
created_at, created_at,
updated_at; updated_at;
-- name: GetAllVirtualGames :many -- name: GetAllVirtualGames :many
SELECT SELECT vg.id,
vg.id,
vg.game_id, vg.game_id,
vg.provider_id, vg.provider_id,
vp.provider_name, vp.provider_name,
@ -175,14 +271,20 @@ SELECT
vg.created_at, vg.created_at,
vg.updated_at vg.updated_at
FROM virtual_games vg FROM virtual_games vg
JOIN virtual_game_providers vp ON vg.provider_id = vp.provider_id JOIN virtual_game_providers vp ON vg.provider_id = vp.provider_id
WHERE WHERE (
($1::text IS NULL OR vg.category = $1) -- category filter (optional) vg.category = sqlc.narg('category')
AND ($2::text IS NULL OR vg.name ILIKE '%' || $2 || '%') -- search by name (optional) OR sqlc.narg('category') IS NULL
)
AND (
name ILIKE '%' || sqlc.narg('name') || '%'
OR sqlc.narg('name') IS NULL
)
AND (
vg.provider_id = sqlc.narg('provider_id')
OR sqlc.narg('provider_id') IS NULL
)
ORDER BY vg.created_at DESC ORDER BY vg.created_at DESC
LIMIT $3 OFFSET $4; LIMIT sqlc.narg('limit') OFFSET sqlc.narg('offset');
-- name: DeleteAllVirtualGames :exec -- name: DeleteAllVirtualGames :exec
DELETE FROM virtual_games; DELETE FROM virtual_games;

View File

@ -12,12 +12,8 @@ import (
) )
const AddFavoriteGame = `-- name: AddFavoriteGame :exec const AddFavoriteGame = `-- name: AddFavoriteGame :exec
INSERT INTO favorite_games ( INSERT INTO favorite_games (user_id, game_id, created_at)
user_id, VALUES ($1, $2, NOW()) ON CONFLICT (user_id, game_id) DO NOTHING
game_id,
created_at
) VALUES ($1, $2, NOW())
ON CONFLICT (user_id, game_id) DO NOTHING
` `
type AddFavoriteGameParams struct { type AddFavoriteGameParams struct {
@ -56,11 +52,22 @@ INSERT INTO virtual_games (
bets, bets,
thumbnail, thumbnail,
status status
) VALUES ( )
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 VALUES (
) $1,
RETURNING $2,
id, $3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12
)
RETURNING id,
game_id, game_id,
provider_id, provider_id,
name, name,
@ -142,10 +149,22 @@ INSERT INTO virtual_game_histories (
external_transaction_id, external_transaction_id,
reference_transaction_id, reference_transaction_id,
status status
) VALUES ( )
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 VALUES (
) RETURNING $1,
id, $2,
$3,
$4,
$5,
$6,
$7,
$8,
$9,
$10,
$11,
$12
)
RETURNING id,
session_id, session_id,
user_id, user_id,
company_id, company_id,
@ -215,10 +234,21 @@ func (q *Queries) CreateVirtualGameHistory(ctx context.Context, arg CreateVirtua
const CreateVirtualGameProvider = `-- name: CreateVirtualGameProvider :one const CreateVirtualGameProvider = `-- name: CreateVirtualGameProvider :one
INSERT INTO virtual_game_providers ( INSERT INTO virtual_game_providers (
provider_id, provider_name, logo_dark, logo_light, enabled provider_id,
) VALUES ( provider_name,
$1, $2, $3, $4, $5 logo_dark,
) RETURNING id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at logo_light,
enabled
)
VALUES ($1, $2, $3, $4, $5)
RETURNING id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at
` `
type CreateVirtualGameProviderParams struct { type CreateVirtualGameProviderParams struct {
@ -253,10 +283,23 @@ func (q *Queries) CreateVirtualGameProvider(ctx context.Context, arg CreateVirtu
const CreateVirtualGameSession = `-- name: CreateVirtualGameSession :one const CreateVirtualGameSession = `-- name: CreateVirtualGameSession :one
INSERT INTO virtual_game_sessions ( INSERT INTO virtual_game_sessions (
user_id, game_id, session_token, currency, status, expires_at user_id,
) VALUES ( game_id,
$1, $2, $3, $4, $5, $6 session_token,
) RETURNING id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at currency,
status,
expires_at
)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id,
user_id,
game_id,
session_token,
currency,
status,
created_at,
updated_at,
expires_at
` `
type CreateVirtualGameSessionParams struct { type CreateVirtualGameSessionParams struct {
@ -294,10 +337,31 @@ func (q *Queries) CreateVirtualGameSession(ctx context.Context, arg CreateVirtua
const CreateVirtualGameTransaction = `-- name: CreateVirtualGameTransaction :one const CreateVirtualGameTransaction = `-- name: CreateVirtualGameTransaction :one
INSERT INTO virtual_game_transactions ( INSERT INTO virtual_game_transactions (
session_id, user_id, company_id, provider, wallet_id, transaction_type, amount, currency, external_transaction_id, status session_id,
) VALUES ( user_id,
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10 company_id,
) RETURNING id, session_id, user_id, company_id, provider, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at provider,
wallet_id,
transaction_type,
amount,
currency,
external_transaction_id,
status
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING id,
session_id,
user_id,
company_id,
provider,
wallet_id,
transaction_type,
amount,
currency,
external_transaction_id,
status,
created_at,
updated_at
` `
type CreateVirtualGameTransactionParams struct { type CreateVirtualGameTransactionParams struct {
@ -390,8 +454,7 @@ func (q *Queries) DeleteVirtualGameProvider(ctx context.Context, providerID stri
} }
const GetAllVirtualGames = `-- name: GetAllVirtualGames :many const GetAllVirtualGames = `-- name: GetAllVirtualGames :many
SELECT SELECT vg.id,
vg.id,
vg.game_id, vg.game_id,
vg.provider_id, vg.provider_id,
vp.provider_name, vp.provider_name,
@ -408,19 +471,29 @@ SELECT
vg.created_at, vg.created_at,
vg.updated_at vg.updated_at
FROM virtual_games vg FROM virtual_games vg
JOIN virtual_game_providers vp ON vg.provider_id = vp.provider_id JOIN virtual_game_providers vp ON vg.provider_id = vp.provider_id
WHERE WHERE (
($1::text IS NULL OR vg.category = $1) -- category filter (optional) vg.category = $1
AND ($2::text IS NULL OR vg.name ILIKE '%' || $2 || '%') -- search by name (optional) OR $1 IS NULL
)
AND (
name ILIKE '%' || $2 || '%'
OR $2 IS NULL
)
AND (
vg.provider_id = $3
OR $3 IS NULL
)
ORDER BY vg.created_at DESC ORDER BY vg.created_at DESC
LIMIT $3 OFFSET $4 LIMIT $5 OFFSET $4
` `
type GetAllVirtualGamesParams struct { type GetAllVirtualGamesParams struct {
Column1 string `json:"column_1"` Category pgtype.Text `json:"category"`
Column2 string `json:"column_2"` Name pgtype.Text `json:"name"`
Limit int32 `json:"limit"` ProviderID pgtype.Text `json:"provider_id"`
Offset int32 `json:"offset"` Offset pgtype.Int4 `json:"offset"`
Limit pgtype.Int4 `json:"limit"`
} }
type GetAllVirtualGamesRow struct { type GetAllVirtualGamesRow struct {
@ -444,10 +517,11 @@ type GetAllVirtualGamesRow struct {
func (q *Queries) GetAllVirtualGames(ctx context.Context, arg GetAllVirtualGamesParams) ([]GetAllVirtualGamesRow, error) { func (q *Queries) GetAllVirtualGames(ctx context.Context, arg GetAllVirtualGamesParams) ([]GetAllVirtualGamesRow, error) {
rows, err := q.db.Query(ctx, GetAllVirtualGames, rows, err := q.db.Query(ctx, GetAllVirtualGames,
arg.Column1, arg.Category,
arg.Column2, arg.Name,
arg.Limit, arg.ProviderID,
arg.Offset, arg.Offset,
arg.Limit,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -485,7 +559,14 @@ func (q *Queries) GetAllVirtualGames(ctx context.Context, arg GetAllVirtualGames
} }
const GetVirtualGameProviderByID = `-- name: GetVirtualGameProviderByID :one const GetVirtualGameProviderByID = `-- name: GetVirtualGameProviderByID :one
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at SELECT id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at
FROM virtual_game_providers FROM virtual_game_providers
WHERE provider_id = $1 WHERE provider_id = $1
` `
@ -507,7 +588,15 @@ func (q *Queries) GetVirtualGameProviderByID(ctx context.Context, providerID str
} }
const GetVirtualGameSessionByToken = `-- name: GetVirtualGameSessionByToken :one const GetVirtualGameSessionByToken = `-- name: GetVirtualGameSessionByToken :one
SELECT id, user_id, game_id, session_token, currency, status, created_at, updated_at, expires_at SELECT id,
user_id,
game_id,
session_token,
currency,
status,
created_at,
updated_at,
expires_at
FROM virtual_game_sessions FROM virtual_game_sessions
WHERE session_token = $1 WHERE session_token = $1
` `
@ -530,18 +619,18 @@ func (q *Queries) GetVirtualGameSessionByToken(ctx context.Context, sessionToken
} }
const GetVirtualGameSummaryInRange = `-- name: GetVirtualGameSummaryInRange :many const GetVirtualGameSummaryInRange = `-- name: GetVirtualGameSummaryInRange :many
SELECT SELECT c.name AS company_name,
c.name AS company_name,
vg.name AS game_name, vg.name AS game_name,
COUNT(vgt.id) AS number_of_bets, COUNT(vgt.id) AS number_of_bets,
COALESCE(SUM(vgt.amount), 0) AS total_transaction_sum COALESCE(SUM(vgt.amount), 0) AS total_transaction_sum
FROM virtual_game_transactions vgt FROM virtual_game_transactions vgt
JOIN virtual_game_sessions vgs ON vgt.session_id = vgs.id JOIN virtual_game_sessions vgs ON vgt.session_id = vgs.id
JOIN virtual_games vg ON vgs.game_id = vg.id JOIN virtual_games vg ON vgs.game_id = vg.id
JOIN companies c ON vgt.company_id = c.id JOIN companies c ON vgt.company_id = c.id
WHERE vgt.transaction_type = 'BET' WHERE vgt.transaction_type = 'BET'
AND vgt.created_at BETWEEN $1 AND $2 AND vgt.created_at BETWEEN $1 AND $2
GROUP BY c.name, vg.name GROUP BY c.name,
vg.name
` `
type GetVirtualGameSummaryInRangeParams struct { type GetVirtualGameSummaryInRangeParams struct {
@ -582,7 +671,17 @@ func (q *Queries) GetVirtualGameSummaryInRange(ctx context.Context, arg GetVirtu
} }
const GetVirtualGameTransactionByExternalID = `-- name: GetVirtualGameTransactionByExternalID :one const GetVirtualGameTransactionByExternalID = `-- name: GetVirtualGameTransactionByExternalID :one
SELECT id, session_id, user_id, wallet_id, transaction_type, amount, currency, external_transaction_id, status, created_at, updated_at SELECT id,
session_id,
user_id,
wallet_id,
transaction_type,
amount,
currency,
external_transaction_id,
status,
created_at,
updated_at
FROM virtual_game_transactions FROM virtual_game_transactions
WHERE external_transaction_id = $1 WHERE external_transaction_id = $1
` `
@ -647,7 +746,14 @@ func (q *Queries) ListFavoriteGames(ctx context.Context, userID int64) ([]int64,
} }
const ListVirtualGameProviders = `-- name: ListVirtualGameProviders :many const ListVirtualGameProviders = `-- name: ListVirtualGameProviders :many
SELECT id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at SELECT id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at
FROM virtual_game_providers FROM virtual_game_providers
ORDER BY created_at DESC ORDER BY created_at DESC
LIMIT $1 OFFSET $2 LIMIT $1 OFFSET $2
@ -689,7 +795,8 @@ func (q *Queries) ListVirtualGameProviders(ctx context.Context, arg ListVirtualG
const RemoveFavoriteGame = `-- name: RemoveFavoriteGame :exec const RemoveFavoriteGame = `-- name: RemoveFavoriteGame :exec
DELETE FROM favorite_games DELETE FROM favorite_games
WHERE user_id = $1 AND game_id = $2 WHERE user_id = $1
AND game_id = $2
` `
type RemoveFavoriteGameParams struct { type RemoveFavoriteGameParams struct {
@ -707,7 +814,14 @@ UPDATE virtual_game_providers
SET enabled = $2, SET enabled = $2,
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE provider_id = $1 WHERE provider_id = $1
RETURNING id, provider_id, provider_name, logo_dark, logo_light, enabled, created_at, updated_at RETURNING id,
provider_id,
provider_name,
logo_dark,
logo_light,
enabled,
created_at,
updated_at
` `
type UpdateVirtualGameProviderEnabledParams struct { type UpdateVirtualGameProviderEnabledParams struct {
@ -733,7 +847,8 @@ func (q *Queries) UpdateVirtualGameProviderEnabled(ctx context.Context, arg Upda
const UpdateVirtualGameSessionStatus = `-- name: UpdateVirtualGameSessionStatus :exec const UpdateVirtualGameSessionStatus = `-- name: UpdateVirtualGameSessionStatus :exec
UPDATE virtual_game_sessions UPDATE virtual_game_sessions
SET status = $2, updated_at = CURRENT_TIMESTAMP SET status = $2,
updated_at = CURRENT_TIMESTAMP
WHERE id = $1 WHERE id = $1
` `
@ -749,7 +864,8 @@ func (q *Queries) UpdateVirtualGameSessionStatus(ctx context.Context, arg Update
const UpdateVirtualGameTransactionStatus = `-- name: UpdateVirtualGameTransactionStatus :exec const UpdateVirtualGameTransactionStatus = `-- name: UpdateVirtualGameTransactionStatus :exec
UPDATE virtual_game_transactions UPDATE virtual_game_transactions
SET status = $2, updated_at = CURRENT_TIMESTAMP SET status = $2,
updated_at = CURRENT_TIMESTAMP
WHERE id = $1 WHERE id = $1
` `

View File

@ -217,9 +217,9 @@ func (s *service) fetchUpcomingEventsFromProvider(ctx context.Context, source_ur
s.mongoLogger.Error("Failed to fetch event data for page", zap.Error(err)) s.mongoLogger.Error("Failed to fetch event data for page", zap.Error(err))
return return
} }
const pageLimit int = 200 const pageLimit int = 200
sportIDs := []int{1, 18, 17, 3, 83, 15, 12, 19, 8, 16, 91} sportIDs := []int{1, 18, 17, 3, 83, 15, 12, 19, 8, 16, 91}
// const pageLimit int = 1
// sportIDs := []int{1} // sportIDs := []int{1}
var skippedLeague []string var skippedLeague []string

View File

@ -7,11 +7,16 @@ import (
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db" dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
"github.com/jackc/pgx/v5/pgtype" "github.com/jackc/pgx/v5/pgtype"
"go.uber.org/zap"
) )
func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest) (*domain.ProviderResponse, error) { func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest) (*domain.ProviderResponse, error) {
logger := s.mongoLogger.With(zap.String("service", "AddProviders"), zap.Any("ProviderRequest", req))
// 0. Remove all existing providers first // 0. Remove all existing providers first
if err := s.repo.DeleteAllVirtualGameProviders(ctx); err != nil { if err := s.repo.DeleteAllVirtualGameProviders(ctx); err != nil {
logger.Error("failed to delete all virtual game providers", zap.Error(err))
return nil, fmt.Errorf("failed to clear existing providers: %w", err) return nil, fmt.Errorf("failed to clear existing providers: %w", err)
} }
@ -21,6 +26,7 @@ func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest)
} }
// Optional fields // Optional fields
sigParams["extraData"] = fmt.Sprintf("%t", req.ExtraData) // false is still included
if req.Size > 0 { if req.Size > 0 {
sigParams["size"] = fmt.Sprintf("%d", req.Size) sigParams["size"] = fmt.Sprintf("%d", req.Size)
} else { } else {
@ -50,6 +56,7 @@ func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest)
} }
if _, err := s.repo.CreateVirtualGameProvider(ctx, createParams); err != nil { if _, err := s.repo.CreateVirtualGameProvider(ctx, createParams); err != nil {
logger.Error("failed to add provider", zap.Error(err))
return nil, fmt.Errorf("failed to add provider %s: %w", p.ProviderID, err) return nil, fmt.Errorf("failed to add provider %s: %w", p.ProviderID, err)
} }
} }
@ -64,6 +71,7 @@ func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest)
} }
if _, err := s.repo.CreateVirtualGameProvider(ctx, popokParams); err != nil { if _, err := s.repo.CreateVirtualGameProvider(ctx, popokParams); err != nil {
logger.Error("failed to add popok provider", zap.Any("popokParams", popokParams), zap.Error(err))
return nil, fmt.Errorf("failed to add popok provider: %w", err) return nil, fmt.Errorf("failed to add popok provider: %w", err)
} }
@ -80,9 +88,10 @@ func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest)
func (s *Service) GetAllVirtualGames(ctx context.Context, params dbgen.GetAllVirtualGamesParams) ([]domain.UnifiedGame, error) { func (s *Service) GetAllVirtualGames(ctx context.Context, params dbgen.GetAllVirtualGamesParams) ([]domain.UnifiedGame, error) {
// Build params for repo call // Build params for repo call
logger := s.mongoLogger.With(zap.String("service", "GetAllVirtualGames"), zap.Any("params", params))
rows, err := s.repo.ListAllVirtualGames(ctx, params) rows, err := s.repo.ListAllVirtualGames(ctx, params)
if err != nil { if err != nil {
logger.Error("[GetAllVirtualGames] Failed to fetch virtual games", zap.Error(err))
return nil, fmt.Errorf("failed to fetch virtual games: %w", err) return nil, fmt.Errorf("failed to fetch virtual games: %w", err)
} }
@ -128,16 +137,29 @@ func (s *Service) GetAllVirtualGames(ctx context.Context, params dbgen.GetAllVir
} }
func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.ProviderRequest, currency string) ([]domain.UnifiedGame, error) { func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.ProviderRequest, currency string) ([]domain.UnifiedGame, error) {
var allGames []domain.UnifiedGame
logger := s.mongoLogger.With(
zap.String("service", "FetchAndStoreAllVirtualGames"),
zap.Any("ProviderRequest", req),
)
// This is necessary, since the provider is a foreign key
_, err := s.AddProviders(ctx, req)
if err != nil {
return nil, fmt.Errorf("failed to add providers to database: %w", err)
}
var allGames []domain.UnifiedGame
// --- 1. Get providers from external API --- // --- 1. Get providers from external API ---
providersRes, err := s.GetProviders(ctx, req) providersRes, err := s.GetProviders(ctx, req)
if err != nil { if err != nil {
logger.Error("Failed to fetch provider", zap.Error(err))
return nil, fmt.Errorf("failed to fetch providers: %w", err) return nil, fmt.Errorf("failed to fetch providers: %w", err)
} }
// --- 2. Fetch games for each provider --- // --- 2. Fetch games for each provider ---
for _, p := range providersRes.Items { for _, p := range providersRes.Items {
// Violates foreign key if the provider isn't added
games, err := s.GetGames(ctx, domain.GameListRequest{ games, err := s.GetGames(ctx, domain.GameListRequest{
BrandID: s.cfg.VeliGames.BrandID, BrandID: s.cfg.VeliGames.BrandID,
ProviderID: p.ProviderID, ProviderID: p.ProviderID,
@ -145,6 +167,7 @@ func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.P
Size: req.Size, Size: req.Size,
}) })
if err != nil { if err != nil {
logger.Error("failed to get veli games", zap.String("ProviderID", p.ProviderID), zap.Error(err))
continue // skip failing provider but continue others continue // skip failing provider but continue others
} }
@ -164,7 +187,7 @@ func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.P
allGames = append(allGames, unified) allGames = append(allGames, unified)
// --- Save to DB --- // --- Save to DB ---
_, _ = s.repo.CreateVirtualGame(ctx, dbgen.CreateVirtualGameParams{ _, err = s.repo.CreateVirtualGame(ctx, dbgen.CreateVirtualGameParams{
GameID: g.GameID, GameID: g.GameID,
ProviderID: g.ProviderID, ProviderID: g.ProviderID,
Name: g.Name, Name: g.Name,
@ -190,12 +213,17 @@ func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.P
// Thumbnail: g.Thumbnail, // Thumbnail: g.Thumbnail,
// Status: g.Status, // Status: g.Status,
}) })
if err != nil {
logger.Error("failed to create virtual game", zap.Error(err))
}
} }
} }
// --- 3. Handle PopOK separately --- // --- 3. Handle PopOK separately ---
popokGames, err := s.virtualGameSvc.ListGames(ctx, currency) popokGames, err := s.virtualGameSvc.ListGames(ctx, currency)
if err != nil { if err != nil {
logger.Error("failed to fetch PopOk games", zap.Error(err))
return nil, fmt.Errorf("failed to fetch PopOK games: %w", err) return nil, fmt.Errorf("failed to fetch PopOK games: %w", err)
} }
@ -221,7 +249,7 @@ func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.P
} }
// --- Save to DB --- // --- Save to DB ---
_, _ = s.repo.CreateVirtualGame(ctx, dbgen.CreateVirtualGameParams{ _, err = s.repo.CreateVirtualGame(ctx, dbgen.CreateVirtualGameParams{
GameID: fmt.Sprintf("popok-%d", g.ID), GameID: fmt.Sprintf("popok-%d", g.ID),
ProviderID: "popok", ProviderID: "popok",
Name: g.GameName, Name: g.GameName,
@ -235,6 +263,10 @@ func (s *Service) FetchAndStoreAllVirtualGames(ctx context.Context, req domain.P
Valid: true, Valid: true,
}, },
}) })
if err != nil {
logger.Error("failed to create virtual game", zap.Error(err))
}
} }
return allGames, nil return allGames, nil

View File

@ -11,6 +11,7 @@ import (
"github.com/SamuelTariku/FortuneBet-Backend/internal/repository" "github.com/SamuelTariku/FortuneBet-Backend/internal/repository"
virtualgameservice "github.com/SamuelTariku/FortuneBet-Backend/internal/services/virtualGame" virtualgameservice "github.com/SamuelTariku/FortuneBet-Backend/internal/services/virtualGame"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/wallet" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/wallet"
"go.uber.org/zap"
) )
var ( var (
@ -26,16 +27,26 @@ type Service struct {
client *Client client *Client
walletSvc *wallet.Service walletSvc *wallet.Service
transfetStore wallet.TransferStore transfetStore wallet.TransferStore
mongoLogger *zap.Logger
cfg *config.Config cfg *config.Config
} }
func New(virtualGameSvc virtualgameservice.VirtualGameService, repo repository.VirtualGameRepository, client *Client, walletSvc *wallet.Service, transferStore wallet.TransferStore, cfg *config.Config) *Service { func New(
virtualGameSvc virtualgameservice.VirtualGameService,
repo repository.VirtualGameRepository,
client *Client,
walletSvc *wallet.Service,
transferStore wallet.TransferStore,
mongoLogger *zap.Logger,
cfg *config.Config,
) *Service {
return &Service{ return &Service{
virtualGameSvc: virtualGameSvc, virtualGameSvc: virtualGameSvc,
repo: repo, repo: repo,
client: client, client: client,
walletSvc: walletSvc, walletSvc: walletSvc,
transfetStore: transferStore, transfetStore: transferStore,
mongoLogger: mongoLogger,
cfg: cfg, cfg: cfg,
} }
} }

View File

@ -12,6 +12,7 @@ import (
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/virtualGame/veli" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/virtualGame/veli"
"github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/response" "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/response"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/jackc/pgx/v5/pgtype"
) )
type launchVirtualGameReq struct { type launchVirtualGameReq struct {
@ -50,12 +51,29 @@ func (h *Handler) ListVirtualGames(c *fiber.Ctx) error {
} }
category := c.Query("category", "") category := c.Query("category", "")
search := c.Query("search", "") search := c.Query("search", "")
providerID := c.Query("providerID", "")
params := dbgen.GetAllVirtualGamesParams{ params := dbgen.GetAllVirtualGamesParams{
Column1: category, Category: pgtype.Text{
Column2: search, String: category,
Limit: int32(limit), Valid: category != "",
Offset: int32(offset), },
Name: pgtype.Text{
String: search,
Valid: search != "",
},
ProviderID: pgtype.Text{
String: providerID,
Valid: providerID != "",
},
Offset: pgtype.Int4{
Int32: int32(offset),
Valid: offset != 0,
},
Limit: pgtype.Int4{
Int32: int32(limit),
Valid: limit != 0,
},
} }
// --- Call service method --- // --- Call service method ---