1166 lines
30 KiB
Go
1166 lines
30 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: virtual_games.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const AddFavoriteGame = `-- name: AddFavoriteGame :exec
|
|
INSERT INTO virtual_game_favourites (user_id, game_id, provider_id, created_at)
|
|
VALUES ($1, $2, $3, NOW())
|
|
ON CONFLICT (game_id, user_id) DO NOTHING
|
|
`
|
|
|
|
type AddFavoriteGameParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
GameID int64 `json:"game_id"`
|
|
ProviderID string `json:"provider_id"`
|
|
}
|
|
|
|
func (q *Queries) AddFavoriteGame(ctx context.Context, arg AddFavoriteGameParams) error {
|
|
_, err := q.db.Exec(ctx, AddFavoriteGame, arg.UserID, arg.GameID, arg.ProviderID)
|
|
return err
|
|
}
|
|
|
|
const CountVirtualGameProviders = `-- name: CountVirtualGameProviders :one
|
|
SELECT COUNT(*) AS total
|
|
FROM virtual_game_providers
|
|
`
|
|
|
|
func (q *Queries) CountVirtualGameProviders(ctx context.Context) (int64, error) {
|
|
row := q.db.QueryRow(ctx, CountVirtualGameProviders)
|
|
var total int64
|
|
err := row.Scan(&total)
|
|
return total, err
|
|
}
|
|
|
|
const CreateVirtualGame = `-- name: CreateVirtualGame :one
|
|
INSERT INTO virtual_games (
|
|
game_id,
|
|
provider_id,
|
|
name,
|
|
category,
|
|
device_type,
|
|
volatility,
|
|
rtp,
|
|
has_demo,
|
|
has_free_bets,
|
|
bets,
|
|
thumbnail,
|
|
status
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11,
|
|
$12
|
|
)
|
|
RETURNING id,
|
|
game_id,
|
|
provider_id,
|
|
name,
|
|
category,
|
|
device_type,
|
|
volatility,
|
|
rtp,
|
|
has_demo,
|
|
has_free_bets,
|
|
bets,
|
|
thumbnail,
|
|
status,
|
|
created_at,
|
|
updated_at
|
|
`
|
|
|
|
type CreateVirtualGameParams struct {
|
|
GameID string `json:"game_id"`
|
|
ProviderID string `json:"provider_id"`
|
|
Name string `json:"name"`
|
|
Category pgtype.Text `json:"category"`
|
|
DeviceType pgtype.Text `json:"device_type"`
|
|
Volatility pgtype.Text `json:"volatility"`
|
|
Rtp pgtype.Numeric `json:"rtp"`
|
|
HasDemo pgtype.Bool `json:"has_demo"`
|
|
HasFreeBets pgtype.Bool `json:"has_free_bets"`
|
|
Bets []pgtype.Numeric `json:"bets"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Status pgtype.Int4 `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGame(ctx context.Context, arg CreateVirtualGameParams) (VirtualGame, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGame,
|
|
arg.GameID,
|
|
arg.ProviderID,
|
|
arg.Name,
|
|
arg.Category,
|
|
arg.DeviceType,
|
|
arg.Volatility,
|
|
arg.Rtp,
|
|
arg.HasDemo,
|
|
arg.HasFreeBets,
|
|
arg.Bets,
|
|
arg.Thumbnail,
|
|
arg.Status,
|
|
)
|
|
var i VirtualGame
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.GameID,
|
|
&i.ProviderID,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.DeviceType,
|
|
&i.Volatility,
|
|
&i.Rtp,
|
|
&i.HasDemo,
|
|
&i.HasFreeBets,
|
|
&i.Bets,
|
|
&i.Thumbnail,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameHistory = `-- name: CreateVirtualGameHistory :one
|
|
INSERT INTO virtual_game_histories (
|
|
-- session_id,
|
|
user_id,
|
|
company_id,
|
|
provider,
|
|
wallet_id,
|
|
game_id,
|
|
transaction_type,
|
|
amount,
|
|
currency,
|
|
external_transaction_id,
|
|
reference_transaction_id,
|
|
status
|
|
)
|
|
VALUES (
|
|
$1,
|
|
$2,
|
|
$3,
|
|
$4,
|
|
$5,
|
|
$6,
|
|
$7,
|
|
$8,
|
|
$9,
|
|
$10,
|
|
$11
|
|
-- $12
|
|
)
|
|
RETURNING id,
|
|
-- session_id,
|
|
user_id,
|
|
company_id,
|
|
provider,
|
|
wallet_id,
|
|
game_id,
|
|
transaction_type,
|
|
amount,
|
|
currency,
|
|
external_transaction_id,
|
|
reference_transaction_id,
|
|
status,
|
|
created_at,
|
|
updated_at
|
|
`
|
|
|
|
type CreateVirtualGameHistoryParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Provider pgtype.Text `json:"provider"`
|
|
WalletID pgtype.Int8 `json:"wallet_id"`
|
|
GameID pgtype.Int8 `json:"game_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
ReferenceTransactionID pgtype.Text `json:"reference_transaction_id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameHistory(ctx context.Context, arg CreateVirtualGameHistoryParams) (VirtualGameHistory, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameHistory,
|
|
arg.UserID,
|
|
arg.CompanyID,
|
|
arg.Provider,
|
|
arg.WalletID,
|
|
arg.GameID,
|
|
arg.TransactionType,
|
|
arg.Amount,
|
|
arg.Currency,
|
|
arg.ExternalTransactionID,
|
|
arg.ReferenceTransactionID,
|
|
arg.Status,
|
|
)
|
|
var i VirtualGameHistory
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.CompanyID,
|
|
&i.Provider,
|
|
&i.WalletID,
|
|
&i.GameID,
|
|
&i.TransactionType,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.ExternalTransactionID,
|
|
&i.ReferenceTransactionID,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameProvider = `-- name: CreateVirtualGameProvider :one
|
|
INSERT INTO virtual_game_providers (
|
|
provider_id,
|
|
provider_name,
|
|
logo_dark,
|
|
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 {
|
|
ProviderID string `json:"provider_id"`
|
|
ProviderName string `json:"provider_name"`
|
|
LogoDark pgtype.Text `json:"logo_dark"`
|
|
LogoLight pgtype.Text `json:"logo_light"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameProvider(ctx context.Context, arg CreateVirtualGameProviderParams) (VirtualGameProvider, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameProvider,
|
|
arg.ProviderID,
|
|
arg.ProviderName,
|
|
arg.LogoDark,
|
|
arg.LogoLight,
|
|
arg.Enabled,
|
|
)
|
|
var i VirtualGameProvider
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameProviderReport = `-- name: CreateVirtualGameProviderReport :one
|
|
INSERT INTO virtual_game_provider_reports (
|
|
provider_id,
|
|
report_date,
|
|
total_games_played,
|
|
total_bets,
|
|
total_payouts,
|
|
total_players,
|
|
report_type,
|
|
created_at,
|
|
updated_at
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, COALESCE($7, 'daily'), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
|
|
)
|
|
ON CONFLICT (provider_id, report_date, report_type) DO UPDATE
|
|
SET
|
|
total_games_played = EXCLUDED.total_games_played,
|
|
total_bets = EXCLUDED.total_bets,
|
|
total_payouts = EXCLUDED.total_payouts,
|
|
total_players = EXCLUDED.total_players,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
RETURNING id, provider_id, report_date, total_games_played, total_bets, total_payouts, total_profit, total_players, report_type, created_at, updated_at
|
|
`
|
|
|
|
type CreateVirtualGameProviderReportParams struct {
|
|
ProviderID string `json:"provider_id"`
|
|
ReportDate pgtype.Date `json:"report_date"`
|
|
TotalGamesPlayed pgtype.Int8 `json:"total_games_played"`
|
|
TotalBets pgtype.Numeric `json:"total_bets"`
|
|
TotalPayouts pgtype.Numeric `json:"total_payouts"`
|
|
TotalPlayers pgtype.Int8 `json:"total_players"`
|
|
Column7 interface{} `json:"column_7"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameProviderReport(ctx context.Context, arg CreateVirtualGameProviderReportParams) (VirtualGameProviderReport, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameProviderReport,
|
|
arg.ProviderID,
|
|
arg.ReportDate,
|
|
arg.TotalGamesPlayed,
|
|
arg.TotalBets,
|
|
arg.TotalPayouts,
|
|
arg.TotalPlayers,
|
|
arg.Column7,
|
|
)
|
|
var i VirtualGameProviderReport
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ReportDate,
|
|
&i.TotalGamesPlayed,
|
|
&i.TotalBets,
|
|
&i.TotalPayouts,
|
|
&i.TotalProfit,
|
|
&i.TotalPlayers,
|
|
&i.ReportType,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameReport = `-- name: CreateVirtualGameReport :one
|
|
INSERT INTO virtual_game_reports (
|
|
game_id,
|
|
provider_id,
|
|
report_date,
|
|
total_rounds,
|
|
total_bets,
|
|
total_payouts,
|
|
total_players,
|
|
report_type,
|
|
created_at,
|
|
updated_at
|
|
) VALUES (
|
|
$1, $2, $3, $4, $5, $6, $7, COALESCE($8, 'daily'), CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
|
|
)
|
|
ON CONFLICT (game_id, report_date, report_type) DO UPDATE
|
|
SET
|
|
total_rounds = EXCLUDED.total_rounds,
|
|
total_bets = EXCLUDED.total_bets,
|
|
total_payouts = EXCLUDED.total_payouts,
|
|
total_players = EXCLUDED.total_players,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
RETURNING id, game_id, provider_id, report_date, total_rounds, total_bets, total_payouts, total_profit, total_players, report_type, created_at, updated_at
|
|
`
|
|
|
|
type CreateVirtualGameReportParams struct {
|
|
GameID string `json:"game_id"`
|
|
ProviderID string `json:"provider_id"`
|
|
ReportDate pgtype.Date `json:"report_date"`
|
|
TotalRounds pgtype.Int8 `json:"total_rounds"`
|
|
TotalBets pgtype.Numeric `json:"total_bets"`
|
|
TotalPayouts pgtype.Numeric `json:"total_payouts"`
|
|
TotalPlayers pgtype.Int8 `json:"total_players"`
|
|
Column8 interface{} `json:"column_8"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameReport(ctx context.Context, arg CreateVirtualGameReportParams) (VirtualGameReport, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameReport,
|
|
arg.GameID,
|
|
arg.ProviderID,
|
|
arg.ReportDate,
|
|
arg.TotalRounds,
|
|
arg.TotalBets,
|
|
arg.TotalPayouts,
|
|
arg.TotalPlayers,
|
|
arg.Column8,
|
|
)
|
|
var i VirtualGameReport
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.GameID,
|
|
&i.ProviderID,
|
|
&i.ReportDate,
|
|
&i.TotalRounds,
|
|
&i.TotalBets,
|
|
&i.TotalPayouts,
|
|
&i.TotalProfit,
|
|
&i.TotalPlayers,
|
|
&i.ReportType,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameSession = `-- name: CreateVirtualGameSession :one
|
|
INSERT INTO virtual_game_sessions (
|
|
user_id,
|
|
game_id,
|
|
session_token
|
|
)
|
|
VALUES ($1, $2, $3)
|
|
RETURNING
|
|
id,
|
|
user_id,
|
|
game_id,
|
|
session_token,
|
|
created_at,
|
|
updated_at
|
|
`
|
|
|
|
type CreateVirtualGameSessionParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
GameID string `json:"game_id"`
|
|
SessionToken string `json:"session_token"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameSession(ctx context.Context, arg CreateVirtualGameSessionParams) (VirtualGameSession, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameSession, arg.UserID, arg.GameID, arg.SessionToken)
|
|
var i VirtualGameSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.GameID,
|
|
&i.SessionToken,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const CreateVirtualGameTransaction = `-- name: CreateVirtualGameTransaction :one
|
|
INSERT INTO virtual_game_transactions (
|
|
-- session_id,
|
|
user_id,
|
|
company_id,
|
|
provider,
|
|
wallet_id,
|
|
transaction_type,
|
|
amount,
|
|
currency,
|
|
external_transaction_id,
|
|
status
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
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 {
|
|
UserID int64 `json:"user_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Provider pgtype.Text `json:"provider"`
|
|
WalletID int64 `json:"wallet_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type CreateVirtualGameTransactionRow struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Provider pgtype.Text `json:"provider"`
|
|
WalletID int64 `json:"wallet_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
Status string `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateVirtualGameTransaction(ctx context.Context, arg CreateVirtualGameTransactionParams) (CreateVirtualGameTransactionRow, error) {
|
|
row := q.db.QueryRow(ctx, CreateVirtualGameTransaction,
|
|
arg.UserID,
|
|
arg.CompanyID,
|
|
arg.Provider,
|
|
arg.WalletID,
|
|
arg.TransactionType,
|
|
arg.Amount,
|
|
arg.Currency,
|
|
arg.ExternalTransactionID,
|
|
arg.Status,
|
|
)
|
|
var i CreateVirtualGameTransactionRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.CompanyID,
|
|
&i.Provider,
|
|
&i.WalletID,
|
|
&i.TransactionType,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.ExternalTransactionID,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteAllVirtualGameProviders = `-- name: DeleteAllVirtualGameProviders :exec
|
|
DELETE FROM virtual_game_providers
|
|
`
|
|
|
|
func (q *Queries) DeleteAllVirtualGameProviders(ctx context.Context) error {
|
|
_, err := q.db.Exec(ctx, DeleteAllVirtualGameProviders)
|
|
return err
|
|
}
|
|
|
|
const DeleteAllVirtualGames = `-- name: DeleteAllVirtualGames :exec
|
|
DELETE FROM virtual_games
|
|
`
|
|
|
|
func (q *Queries) DeleteAllVirtualGames(ctx context.Context) error {
|
|
_, err := q.db.Exec(ctx, DeleteAllVirtualGames)
|
|
return err
|
|
}
|
|
|
|
const DeleteVirtualGameProvider = `-- name: DeleteVirtualGameProvider :exec
|
|
DELETE FROM virtual_game_providers
|
|
WHERE provider_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteVirtualGameProvider(ctx context.Context, providerID string) error {
|
|
_, err := q.db.Exec(ctx, DeleteVirtualGameProvider, providerID)
|
|
return err
|
|
}
|
|
|
|
const GetAllVirtualGames = `-- name: GetAllVirtualGames :many
|
|
SELECT vg.id,
|
|
vg.game_id,
|
|
vg.provider_id,
|
|
vp.provider_name,
|
|
vg.name,
|
|
vg.category,
|
|
vg.device_type,
|
|
vg.volatility,
|
|
vg.rtp,
|
|
vg.has_demo,
|
|
vg.has_free_bets,
|
|
vg.bets,
|
|
vg.thumbnail,
|
|
vg.status,
|
|
vg.created_at,
|
|
vg.updated_at
|
|
FROM virtual_games vg
|
|
JOIN virtual_game_providers vp ON vg.provider_id = vp.provider_id
|
|
WHERE (
|
|
vg.category = $1
|
|
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
|
|
LIMIT $5 OFFSET $4
|
|
`
|
|
|
|
type GetAllVirtualGamesParams struct {
|
|
Category pgtype.Text `json:"category"`
|
|
Name pgtype.Text `json:"name"`
|
|
ProviderID pgtype.Text `json:"provider_id"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
type GetAllVirtualGamesRow struct {
|
|
ID int64 `json:"id"`
|
|
GameID string `json:"game_id"`
|
|
ProviderID string `json:"provider_id"`
|
|
ProviderName string `json:"provider_name"`
|
|
Name string `json:"name"`
|
|
Category pgtype.Text `json:"category"`
|
|
DeviceType pgtype.Text `json:"device_type"`
|
|
Volatility pgtype.Text `json:"volatility"`
|
|
Rtp pgtype.Numeric `json:"rtp"`
|
|
HasDemo pgtype.Bool `json:"has_demo"`
|
|
HasFreeBets pgtype.Bool `json:"has_free_bets"`
|
|
Bets []pgtype.Numeric `json:"bets"`
|
|
Thumbnail pgtype.Text `json:"thumbnail"`
|
|
Status pgtype.Int4 `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetAllVirtualGames(ctx context.Context, arg GetAllVirtualGamesParams) ([]GetAllVirtualGamesRow, error) {
|
|
rows, err := q.db.Query(ctx, GetAllVirtualGames,
|
|
arg.Category,
|
|
arg.Name,
|
|
arg.ProviderID,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllVirtualGamesRow
|
|
for rows.Next() {
|
|
var i GetAllVirtualGamesRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.GameID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.DeviceType,
|
|
&i.Volatility,
|
|
&i.Rtp,
|
|
&i.HasDemo,
|
|
&i.HasFreeBets,
|
|
&i.Bets,
|
|
&i.Thumbnail,
|
|
&i.Status,
|
|
&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 GetUserFavoriteGamesPaginated = `-- name: GetUserFavoriteGamesPaginated :many
|
|
SELECT
|
|
vg.id, vg.game_id, vg.provider_id, vg.name, vg.category, vg.device_type, vg.volatility, vg.rtp, vg.has_demo, vg.has_free_bets, vg.bets, vg.thumbnail, vg.status, vg.created_at, vg.updated_at
|
|
FROM virtual_games vg
|
|
JOIN virtual_game_favourites vf
|
|
ON vf.game_id = vg.id
|
|
WHERE
|
|
vf.user_id = $1
|
|
AND ($2::varchar IS NULL OR vf.provider_id = $2)
|
|
ORDER BY vf.created_at DESC
|
|
LIMIT $3 OFFSET $4
|
|
`
|
|
|
|
type GetUserFavoriteGamesPaginatedParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
Column2 string `json:"column_2"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) GetUserFavoriteGamesPaginated(ctx context.Context, arg GetUserFavoriteGamesPaginatedParams) ([]VirtualGame, error) {
|
|
rows, err := q.db.Query(ctx, GetUserFavoriteGamesPaginated,
|
|
arg.UserID,
|
|
arg.Column2,
|
|
arg.Limit,
|
|
arg.Offset,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []VirtualGame
|
|
for rows.Next() {
|
|
var i VirtualGame
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.GameID,
|
|
&i.ProviderID,
|
|
&i.Name,
|
|
&i.Category,
|
|
&i.DeviceType,
|
|
&i.Volatility,
|
|
&i.Rtp,
|
|
&i.HasDemo,
|
|
&i.HasFreeBets,
|
|
&i.Bets,
|
|
&i.Thumbnail,
|
|
&i.Status,
|
|
&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 GetVirtualGameProviderByID = `-- name: GetVirtualGameProviderByID :one
|
|
SELECT id,
|
|
provider_id,
|
|
provider_name,
|
|
logo_dark,
|
|
logo_light,
|
|
enabled,
|
|
created_at,
|
|
updated_at
|
|
FROM virtual_game_providers
|
|
WHERE provider_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetVirtualGameProviderByID(ctx context.Context, providerID string) (VirtualGameProvider, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameProviderByID, providerID)
|
|
var i VirtualGameProvider
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetVirtualGameProviderReportByProviderAndDate = `-- name: GetVirtualGameProviderReportByProviderAndDate :one
|
|
SELECT id, provider_id, report_date, total_games_played, total_bets, total_payouts, total_profit, total_players, report_type, created_at, updated_at
|
|
FROM virtual_game_provider_reports
|
|
WHERE provider_id = $1
|
|
AND report_date = $2
|
|
AND report_type = $3
|
|
`
|
|
|
|
type GetVirtualGameProviderReportByProviderAndDateParams struct {
|
|
ProviderID string `json:"provider_id"`
|
|
ReportDate pgtype.Date `json:"report_date"`
|
|
ReportType pgtype.Text `json:"report_type"`
|
|
}
|
|
|
|
func (q *Queries) GetVirtualGameProviderReportByProviderAndDate(ctx context.Context, arg GetVirtualGameProviderReportByProviderAndDateParams) (VirtualGameProviderReport, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameProviderReportByProviderAndDate, arg.ProviderID, arg.ReportDate, arg.ReportType)
|
|
var i VirtualGameProviderReport
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ReportDate,
|
|
&i.TotalGamesPlayed,
|
|
&i.TotalBets,
|
|
&i.TotalPayouts,
|
|
&i.TotalProfit,
|
|
&i.TotalPlayers,
|
|
&i.ReportType,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetVirtualGameSessionByToken = `-- name: GetVirtualGameSessionByToken :one
|
|
SELECT id,
|
|
user_id,
|
|
game_id,
|
|
session_token,
|
|
created_at,
|
|
updated_at
|
|
FROM virtual_game_sessions
|
|
WHERE session_token = $1
|
|
`
|
|
|
|
func (q *Queries) GetVirtualGameSessionByToken(ctx context.Context, sessionToken string) (VirtualGameSession, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameSessionByToken, sessionToken)
|
|
var i VirtualGameSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.GameID,
|
|
&i.SessionToken,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetVirtualGameSessionByUserID = `-- name: GetVirtualGameSessionByUserID :one
|
|
SELECT
|
|
id,
|
|
user_id,
|
|
game_id,
|
|
session_token,
|
|
created_at,
|
|
updated_at
|
|
FROM virtual_game_sessions
|
|
WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetVirtualGameSessionByUserID(ctx context.Context, userID int64) (VirtualGameSession, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameSessionByUserID, userID)
|
|
var i VirtualGameSession
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.GameID,
|
|
&i.SessionToken,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetVirtualGameSummaryInRange = `-- name: GetVirtualGameSummaryInRange :many
|
|
SELECT c.name AS company_name,
|
|
vg.name AS game_name,
|
|
COUNT(vgt.id) AS number_of_bets,
|
|
COALESCE(SUM(vgt.amount), 0) AS total_transaction_sum
|
|
FROM virtual_game_transactions vgt
|
|
-- JOIN virtual_game_sessions vgs ON vgt.session_id = vgs.id
|
|
JOIN virtual_games vg ON vgs.game_id = vg.id
|
|
JOIN companies c ON vgt.company_id = c.id
|
|
WHERE vgt.transaction_type = 'BET'
|
|
AND vgt.created_at BETWEEN $1 AND $2
|
|
GROUP BY c.name,
|
|
vg.name
|
|
`
|
|
|
|
type GetVirtualGameSummaryInRangeParams struct {
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
CreatedAt_2 pgtype.Timestamptz `json:"created_at_2"`
|
|
}
|
|
|
|
type GetVirtualGameSummaryInRangeRow struct {
|
|
CompanyName string `json:"company_name"`
|
|
GameName string `json:"game_name"`
|
|
NumberOfBets int64 `json:"number_of_bets"`
|
|
TotalTransactionSum interface{} `json:"total_transaction_sum"`
|
|
}
|
|
|
|
func (q *Queries) GetVirtualGameSummaryInRange(ctx context.Context, arg GetVirtualGameSummaryInRangeParams) ([]GetVirtualGameSummaryInRangeRow, error) {
|
|
rows, err := q.db.Query(ctx, GetVirtualGameSummaryInRange, arg.CreatedAt, arg.CreatedAt_2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetVirtualGameSummaryInRangeRow
|
|
for rows.Next() {
|
|
var i GetVirtualGameSummaryInRangeRow
|
|
if err := rows.Scan(
|
|
&i.CompanyName,
|
|
&i.GameName,
|
|
&i.NumberOfBets,
|
|
&i.TotalTransactionSum,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
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
|
|
FROM virtual_game_transactions
|
|
WHERE external_transaction_id = $1
|
|
`
|
|
|
|
type GetVirtualGameTransactionByExternalIDRow struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
WalletID int64 `json:"wallet_id"`
|
|
TransactionType string `json:"transaction_type"`
|
|
Amount int64 `json:"amount"`
|
|
Currency string `json:"currency"`
|
|
ExternalTransactionID string `json:"external_transaction_id"`
|
|
Status string `json:"status"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetVirtualGameTransactionByExternalID(ctx context.Context, externalTransactionID string) (GetVirtualGameTransactionByExternalIDRow, error) {
|
|
row := q.db.QueryRow(ctx, GetVirtualGameTransactionByExternalID, externalTransactionID)
|
|
var i GetVirtualGameTransactionByExternalIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.WalletID,
|
|
&i.TransactionType,
|
|
&i.Amount,
|
|
&i.Currency,
|
|
&i.ExternalTransactionID,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const ListVirtualGameProviderReportsByGamesPlayedAsc = `-- name: ListVirtualGameProviderReportsByGamesPlayedAsc :many
|
|
SELECT id, provider_id, report_date, total_games_played, total_bets, total_payouts, total_profit, total_players, report_type, created_at, updated_at
|
|
FROM virtual_game_provider_reports
|
|
ORDER BY total_games_played ASC
|
|
`
|
|
|
|
func (q *Queries) ListVirtualGameProviderReportsByGamesPlayedAsc(ctx context.Context) ([]VirtualGameProviderReport, error) {
|
|
rows, err := q.db.Query(ctx, ListVirtualGameProviderReportsByGamesPlayedAsc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []VirtualGameProviderReport
|
|
for rows.Next() {
|
|
var i VirtualGameProviderReport
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ReportDate,
|
|
&i.TotalGamesPlayed,
|
|
&i.TotalBets,
|
|
&i.TotalPayouts,
|
|
&i.TotalProfit,
|
|
&i.TotalPlayers,
|
|
&i.ReportType,
|
|
&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 ListVirtualGameProviderReportsByGamesPlayedDesc = `-- name: ListVirtualGameProviderReportsByGamesPlayedDesc :many
|
|
SELECT id, provider_id, report_date, total_games_played, total_bets, total_payouts, total_profit, total_players, report_type, created_at, updated_at
|
|
FROM virtual_game_provider_reports
|
|
ORDER BY total_games_played DESC
|
|
`
|
|
|
|
func (q *Queries) ListVirtualGameProviderReportsByGamesPlayedDesc(ctx context.Context) ([]VirtualGameProviderReport, error) {
|
|
rows, err := q.db.Query(ctx, ListVirtualGameProviderReportsByGamesPlayedDesc)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []VirtualGameProviderReport
|
|
for rows.Next() {
|
|
var i VirtualGameProviderReport
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ReportDate,
|
|
&i.TotalGamesPlayed,
|
|
&i.TotalBets,
|
|
&i.TotalPayouts,
|
|
&i.TotalProfit,
|
|
&i.TotalPlayers,
|
|
&i.ReportType,
|
|
&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 ListVirtualGameProviders = `-- name: ListVirtualGameProviders :many
|
|
SELECT id,
|
|
provider_id,
|
|
provider_name,
|
|
logo_dark,
|
|
logo_light,
|
|
enabled,
|
|
created_at,
|
|
updated_at
|
|
FROM virtual_game_providers
|
|
ORDER BY created_at DESC
|
|
LIMIT $1 OFFSET $2
|
|
`
|
|
|
|
type ListVirtualGameProvidersParams struct {
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
func (q *Queries) ListVirtualGameProviders(ctx context.Context, arg ListVirtualGameProvidersParams) ([]VirtualGameProvider, error) {
|
|
rows, err := q.db.Query(ctx, ListVirtualGameProviders, arg.Limit, arg.Offset)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []VirtualGameProvider
|
|
for rows.Next() {
|
|
var i VirtualGameProvider
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&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 RemoveFavoriteGame = `-- name: RemoveFavoriteGame :exec
|
|
DELETE FROM virtual_game_favourites
|
|
WHERE user_id = $1 AND game_id = $2 AND provider_id = $3
|
|
`
|
|
|
|
type RemoveFavoriteGameParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
GameID int64 `json:"game_id"`
|
|
ProviderID string `json:"provider_id"`
|
|
}
|
|
|
|
func (q *Queries) RemoveFavoriteGame(ctx context.Context, arg RemoveFavoriteGameParams) error {
|
|
_, err := q.db.Exec(ctx, RemoveFavoriteGame, arg.UserID, arg.GameID, arg.ProviderID)
|
|
return err
|
|
}
|
|
|
|
const UpdateVirtualGameProviderEnabled = `-- name: UpdateVirtualGameProviderEnabled :one
|
|
UPDATE virtual_game_providers
|
|
SET enabled = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE provider_id = $1
|
|
RETURNING id,
|
|
provider_id,
|
|
provider_name,
|
|
logo_dark,
|
|
logo_light,
|
|
enabled,
|
|
created_at,
|
|
updated_at
|
|
`
|
|
|
|
type UpdateVirtualGameProviderEnabledParams struct {
|
|
ProviderID string `json:"provider_id"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
func (q *Queries) UpdateVirtualGameProviderEnabled(ctx context.Context, arg UpdateVirtualGameProviderEnabledParams) (VirtualGameProvider, error) {
|
|
row := q.db.QueryRow(ctx, UpdateVirtualGameProviderEnabled, arg.ProviderID, arg.Enabled)
|
|
var i VirtualGameProvider
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.ProviderID,
|
|
&i.ProviderName,
|
|
&i.LogoDark,
|
|
&i.LogoLight,
|
|
&i.Enabled,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const UpdateVirtualGameProviderReportByDate = `-- name: UpdateVirtualGameProviderReportByDate :exec
|
|
UPDATE virtual_game_provider_reports
|
|
SET
|
|
total_games_played = total_games_played + $4,
|
|
total_bets = total_bets + $5,
|
|
total_payouts = total_payouts + $6,
|
|
total_players = total_players + $7,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE
|
|
provider_id = $1
|
|
AND report_date = $2
|
|
AND report_type = $3
|
|
`
|
|
|
|
type UpdateVirtualGameProviderReportByDateParams struct {
|
|
ProviderID string `json:"provider_id"`
|
|
ReportDate pgtype.Date `json:"report_date"`
|
|
ReportType pgtype.Text `json:"report_type"`
|
|
TotalGamesPlayed pgtype.Int8 `json:"total_games_played"`
|
|
TotalBets pgtype.Numeric `json:"total_bets"`
|
|
TotalPayouts pgtype.Numeric `json:"total_payouts"`
|
|
TotalPlayers pgtype.Int8 `json:"total_players"`
|
|
}
|
|
|
|
func (q *Queries) UpdateVirtualGameProviderReportByDate(ctx context.Context, arg UpdateVirtualGameProviderReportByDateParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateVirtualGameProviderReportByDate,
|
|
arg.ProviderID,
|
|
arg.ReportDate,
|
|
arg.ReportType,
|
|
arg.TotalGamesPlayed,
|
|
arg.TotalBets,
|
|
arg.TotalPayouts,
|
|
arg.TotalPlayers,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const UpdateVirtualGameTransactionStatus = `-- name: UpdateVirtualGameTransactionStatus :exec
|
|
UPDATE virtual_game_transactions
|
|
SET status = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateVirtualGameTransactionStatusParams struct {
|
|
ID int64 `json:"id"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
func (q *Queries) UpdateVirtualGameTransactionStatus(ctx context.Context, arg UpdateVirtualGameTransactionStatusParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateVirtualGameTransactionStatus, arg.ID, arg.Status)
|
|
return err
|
|
}
|