- Removed the CheckAndSendResultNotifications method from the result service. - Consolidated notification logic into a new notification.go file. - Updated email and in-app notification formatting to include event processing periods. - Added error handling for wallet operations to check if wallets are active before processing transfers. - Introduced new error for disabled wallets. - Updated cron jobs to comment out unnecessary tasks. - Added bulk update functionality for bet outcomes by odd IDs in the odd handler. - Renamed ticket handler methods for clarity and consistency. - Updated API version in routes.
925 lines
22 KiB
Go
925 lines
22 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: bet.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const BulkUpdateBetOutcomeStatusByOddIDs = `-- name: BulkUpdateBetOutcomeStatusByOddIDs :exec
|
|
UPDATE bet_outcomes
|
|
SET status = $1
|
|
WHERE odd_id = ANY($2::BIGINT [])
|
|
`
|
|
|
|
type BulkUpdateBetOutcomeStatusByOddIDsParams struct {
|
|
Status int32 `json:"status"`
|
|
OddIds []int64 `json:"odd_ids"`
|
|
}
|
|
|
|
func (q *Queries) BulkUpdateBetOutcomeStatusByOddIDs(ctx context.Context, arg BulkUpdateBetOutcomeStatusByOddIDsParams) error {
|
|
_, err := q.db.Exec(ctx, BulkUpdateBetOutcomeStatusByOddIDs, arg.Status, arg.OddIds)
|
|
return err
|
|
}
|
|
|
|
const CreateBet = `-- name: CreateBet :one
|
|
INSERT INTO bets (
|
|
amount,
|
|
total_odds,
|
|
status,
|
|
user_id,
|
|
is_shop_bet,
|
|
outcomes_hash,
|
|
fast_code,
|
|
company_id
|
|
)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
RETURNING id, company_id, amount, total_odds, status, user_id, is_shop_bet, cashed_out, outcomes_hash, fast_code, processed, created_at, updated_at
|
|
`
|
|
|
|
type CreateBetParams struct {
|
|
Amount int64 `json:"amount"`
|
|
TotalOdds float32 `json:"total_odds"`
|
|
Status int32 `json:"status"`
|
|
UserID int64 `json:"user_id"`
|
|
IsShopBet bool `json:"is_shop_bet"`
|
|
OutcomesHash string `json:"outcomes_hash"`
|
|
FastCode string `json:"fast_code"`
|
|
CompanyID int64 `json:"company_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateBet(ctx context.Context, arg CreateBetParams) (Bet, error) {
|
|
row := q.db.QueryRow(ctx, CreateBet,
|
|
arg.Amount,
|
|
arg.TotalOdds,
|
|
arg.Status,
|
|
arg.UserID,
|
|
arg.IsShopBet,
|
|
arg.OutcomesHash,
|
|
arg.FastCode,
|
|
arg.CompanyID,
|
|
)
|
|
var i Bet
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.UserID,
|
|
&i.IsShopBet,
|
|
&i.CashedOut,
|
|
&i.OutcomesHash,
|
|
&i.FastCode,
|
|
&i.Processed,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
type CreateBetOutcomeParams struct {
|
|
BetID int64 `json:"bet_id"`
|
|
SportID int64 `json:"sport_id"`
|
|
EventID int64 `json:"event_id"`
|
|
OddID int64 `json:"odd_id"`
|
|
HomeTeamName string `json:"home_team_name"`
|
|
AwayTeamName string `json:"away_team_name"`
|
|
MarketID int64 `json:"market_id"`
|
|
MarketName string `json:"market_name"`
|
|
Odd float32 `json:"odd"`
|
|
OddName string `json:"odd_name"`
|
|
OddHeader string `json:"odd_header"`
|
|
OddHandicap string `json:"odd_handicap"`
|
|
Expires pgtype.Timestamp `json:"expires"`
|
|
}
|
|
|
|
const DeleteBet = `-- name: DeleteBet :exec
|
|
DELETE FROM bets
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBet(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteBet, id)
|
|
return err
|
|
}
|
|
|
|
const DeleteBetOutcome = `-- name: DeleteBetOutcome :exec
|
|
DELETE FROM bet_outcomes
|
|
WHERE bet_id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteBetOutcome(ctx context.Context, betID int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteBetOutcome, betID)
|
|
return err
|
|
}
|
|
|
|
const GetAllBets = `-- name: GetAllBets :many
|
|
SELECT id, company_id, amount, total_odds, status, user_id, is_shop_bet, cashed_out, outcomes_hash, fast_code, processed, created_at, updated_at, full_name, phone_number, outcomes, company_slug
|
|
FROM bet_with_outcomes
|
|
wHERE (
|
|
user_id = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
is_shop_bet = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
company_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
status = $4
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
cashed_out = $5
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
full_name ILIKE '%' || $6 || '%'
|
|
OR phone_number ILIKE '%' || $6 || '%'
|
|
OR $6 IS NULL
|
|
)
|
|
AND (
|
|
created_at > $7
|
|
OR $7 IS NULL
|
|
)
|
|
AND (
|
|
created_at < $8
|
|
OR $8 IS NULL
|
|
)
|
|
LIMIT $10 OFFSET $9
|
|
`
|
|
|
|
type GetAllBetsParams struct {
|
|
UserID pgtype.Int8 `json:"user_id"`
|
|
IsShopBet pgtype.Bool `json:"is_shop_bet"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Status pgtype.Int4 `json:"status"`
|
|
CashedOut pgtype.Bool `json:"cashed_out"`
|
|
Query pgtype.Text `json:"query"`
|
|
CreatedBefore pgtype.Timestamp `json:"created_before"`
|
|
CreatedAfter pgtype.Timestamp `json:"created_after"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
func (q *Queries) GetAllBets(ctx context.Context, arg GetAllBetsParams) ([]BetWithOutcome, error) {
|
|
rows, err := q.db.Query(ctx, GetAllBets,
|
|
arg.UserID,
|
|
arg.IsShopBet,
|
|
arg.CompanyID,
|
|
arg.Status,
|
|
arg.CashedOut,
|
|
arg.Query,
|
|
arg.CreatedBefore,
|
|
arg.CreatedAfter,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetWithOutcome
|
|
for rows.Next() {
|
|
var i BetWithOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.UserID,
|
|
&i.IsShopBet,
|
|
&i.CashedOut,
|
|
&i.OutcomesHash,
|
|
&i.FastCode,
|
|
&i.Processed,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.Outcomes,
|
|
&i.CompanySlug,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetBetByFastCode = `-- name: GetBetByFastCode :one
|
|
SELECT id, company_id, amount, total_odds, status, user_id, is_shop_bet, cashed_out, outcomes_hash, fast_code, processed, created_at, updated_at, full_name, phone_number, outcomes, company_slug
|
|
FROM bet_with_outcomes
|
|
WHERE fast_code = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetBetByFastCode(ctx context.Context, fastCode string) (BetWithOutcome, error) {
|
|
row := q.db.QueryRow(ctx, GetBetByFastCode, fastCode)
|
|
var i BetWithOutcome
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.UserID,
|
|
&i.IsShopBet,
|
|
&i.CashedOut,
|
|
&i.OutcomesHash,
|
|
&i.FastCode,
|
|
&i.Processed,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.Outcomes,
|
|
&i.CompanySlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetBetByID = `-- name: GetBetByID :one
|
|
SELECT id, company_id, amount, total_odds, status, user_id, is_shop_bet, cashed_out, outcomes_hash, fast_code, processed, created_at, updated_at, full_name, phone_number, outcomes, company_slug
|
|
FROM bet_with_outcomes
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetByID(ctx context.Context, id int64) (BetWithOutcome, error) {
|
|
row := q.db.QueryRow(ctx, GetBetByID, id)
|
|
var i BetWithOutcome
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.UserID,
|
|
&i.IsShopBet,
|
|
&i.CashedOut,
|
|
&i.OutcomesHash,
|
|
&i.FastCode,
|
|
&i.Processed,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.Outcomes,
|
|
&i.CompanySlug,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetBetByUserID = `-- name: GetBetByUserID :many
|
|
SELECT id, company_id, amount, total_odds, status, user_id, is_shop_bet, cashed_out, outcomes_hash, fast_code, processed, created_at, updated_at, full_name, phone_number, outcomes, company_slug
|
|
FROM bet_with_outcomes
|
|
WHERE user_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetByUserID(ctx context.Context, userID int64) ([]BetWithOutcome, error) {
|
|
rows, err := q.db.Query(ctx, GetBetByUserID, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetWithOutcome
|
|
for rows.Next() {
|
|
var i BetWithOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.UserID,
|
|
&i.IsShopBet,
|
|
&i.CashedOut,
|
|
&i.OutcomesHash,
|
|
&i.FastCode,
|
|
&i.Processed,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.Outcomes,
|
|
&i.CompanySlug,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetBetCountByOutcomesHash = `-- name: GetBetCountByOutcomesHash :one
|
|
SELECT COUNT(*)
|
|
FROM bets
|
|
WHERE outcomes_hash = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetCountByOutcomesHash(ctx context.Context, outcomesHash string) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetBetCountByOutcomesHash, outcomesHash)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const GetBetCountByUserID = `-- name: GetBetCountByUserID :one
|
|
SELECT COUNT(*)
|
|
FROM bets
|
|
WHERE user_id = $1
|
|
AND outcomes_hash = $2
|
|
`
|
|
|
|
type GetBetCountByUserIDParams struct {
|
|
UserID int64 `json:"user_id"`
|
|
OutcomesHash string `json:"outcomes_hash"`
|
|
}
|
|
|
|
func (q *Queries) GetBetCountByUserID(ctx context.Context, arg GetBetCountByUserIDParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetBetCountByUserID, arg.UserID, arg.OutcomesHash)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const GetBetOutcomeByBetID = `-- name: GetBetOutcomeByBetID :many
|
|
SELECT id, bet_id, sport_id, event_id, odd_id, home_team_name, away_team_name, market_id, market_name, odd, odd_name, odd_header, odd_handicap, status, expires
|
|
FROM bet_outcomes
|
|
WHERE bet_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetOutcomeByBetID(ctx context.Context, betID int64) ([]BetOutcome, error) {
|
|
rows, err := q.db.Query(ctx, GetBetOutcomeByBetID, betID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetOutcome
|
|
for rows.Next() {
|
|
var i BetOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BetID,
|
|
&i.SportID,
|
|
&i.EventID,
|
|
&i.OddID,
|
|
&i.HomeTeamName,
|
|
&i.AwayTeamName,
|
|
&i.MarketID,
|
|
&i.MarketName,
|
|
&i.Odd,
|
|
&i.OddName,
|
|
&i.OddHeader,
|
|
&i.OddHandicap,
|
|
&i.Status,
|
|
&i.Expires,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetBetOutcomeByEventID = `-- name: GetBetOutcomeByEventID :many
|
|
SELECT id, bet_id, sport_id, event_id, odd_id, home_team_name, away_team_name, market_id, market_name, odd, odd_name, odd_header, odd_handicap, status, expires
|
|
FROM bet_outcomes
|
|
WHERE (event_id = $1)
|
|
AND (
|
|
status = $2
|
|
OR $2 IS NULL
|
|
OR status = $3
|
|
OR $3 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetBetOutcomeByEventIDParams struct {
|
|
EventID int64 `json:"event_id"`
|
|
FilterStatus pgtype.Int4 `json:"filter_status"`
|
|
FilterStatus2 pgtype.Int4 `json:"filter_status_2"`
|
|
}
|
|
|
|
func (q *Queries) GetBetOutcomeByEventID(ctx context.Context, arg GetBetOutcomeByEventIDParams) ([]BetOutcome, error) {
|
|
rows, err := q.db.Query(ctx, GetBetOutcomeByEventID, arg.EventID, arg.FilterStatus, arg.FilterStatus2)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetOutcome
|
|
for rows.Next() {
|
|
var i BetOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BetID,
|
|
&i.SportID,
|
|
&i.EventID,
|
|
&i.OddID,
|
|
&i.HomeTeamName,
|
|
&i.AwayTeamName,
|
|
&i.MarketID,
|
|
&i.MarketName,
|
|
&i.Odd,
|
|
&i.OddName,
|
|
&i.OddHeader,
|
|
&i.OddHandicap,
|
|
&i.Status,
|
|
&i.Expires,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetBetOutcomeCountByOddID = `-- name: GetBetOutcomeCountByOddID :one
|
|
SELECT COUNT(*)
|
|
FROM bet_outcomes
|
|
WHERE odd_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBetOutcomeCountByOddID(ctx context.Context, oddID int64) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetBetOutcomeCountByOddID, oddID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const GetBetOutcomeViewByEventID = `-- name: GetBetOutcomeViewByEventID :many
|
|
SELECT bet_outcomes.id, bet_outcomes.bet_id, bet_outcomes.sport_id, bet_outcomes.event_id, bet_outcomes.odd_id, bet_outcomes.home_team_name, bet_outcomes.away_team_name, bet_outcomes.market_id, bet_outcomes.market_name, bet_outcomes.odd, bet_outcomes.odd_name, bet_outcomes.odd_header, bet_outcomes.odd_handicap, bet_outcomes.status, bet_outcomes.expires,
|
|
users.first_name,
|
|
users.last_name,
|
|
bets.amount,
|
|
bets.total_odds,
|
|
companies.name as company_name
|
|
FROM bet_outcomes
|
|
JOIN bets ON bets.id = bet_outcomes.bet_id
|
|
JOIN users ON bets.user_id = users.id
|
|
JOIN companies ON bets.company_id = companies.id
|
|
WHERE bet_outcomes.event_id = $1
|
|
AND (
|
|
bets.company_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
bet_outcomes.status = $3
|
|
OR $3 IS NULL
|
|
)
|
|
LIMIT $5 OFFSET $4
|
|
`
|
|
|
|
type GetBetOutcomeViewByEventIDParams struct {
|
|
EventID int64 `json:"event_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
FilterStatus pgtype.Int4 `json:"filter_status"`
|
|
Offset pgtype.Int4 `json:"offset"`
|
|
Limit pgtype.Int4 `json:"limit"`
|
|
}
|
|
|
|
type GetBetOutcomeViewByEventIDRow struct {
|
|
ID int64 `json:"id"`
|
|
BetID int64 `json:"bet_id"`
|
|
SportID int64 `json:"sport_id"`
|
|
EventID int64 `json:"event_id"`
|
|
OddID int64 `json:"odd_id"`
|
|
HomeTeamName string `json:"home_team_name"`
|
|
AwayTeamName string `json:"away_team_name"`
|
|
MarketID int64 `json:"market_id"`
|
|
MarketName string `json:"market_name"`
|
|
Odd float32 `json:"odd"`
|
|
OddName string `json:"odd_name"`
|
|
OddHeader string `json:"odd_header"`
|
|
OddHandicap string `json:"odd_handicap"`
|
|
Status int32 `json:"status"`
|
|
Expires pgtype.Timestamp `json:"expires"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
Amount int64 `json:"amount"`
|
|
TotalOdds float32 `json:"total_odds"`
|
|
CompanyName string `json:"company_name"`
|
|
}
|
|
|
|
func (q *Queries) GetBetOutcomeViewByEventID(ctx context.Context, arg GetBetOutcomeViewByEventIDParams) ([]GetBetOutcomeViewByEventIDRow, error) {
|
|
rows, err := q.db.Query(ctx, GetBetOutcomeViewByEventID,
|
|
arg.EventID,
|
|
arg.CompanyID,
|
|
arg.FilterStatus,
|
|
arg.Offset,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetBetOutcomeViewByEventIDRow
|
|
for rows.Next() {
|
|
var i GetBetOutcomeViewByEventIDRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BetID,
|
|
&i.SportID,
|
|
&i.EventID,
|
|
&i.OddID,
|
|
&i.HomeTeamName,
|
|
&i.AwayTeamName,
|
|
&i.MarketID,
|
|
&i.MarketName,
|
|
&i.Odd,
|
|
&i.OddName,
|
|
&i.OddHeader,
|
|
&i.OddHandicap,
|
|
&i.Status,
|
|
&i.Expires,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.CompanyName,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetBetsForCashback = `-- name: GetBetsForCashback :many
|
|
SELECT id, company_id, amount, total_odds, status, user_id, is_shop_bet, cashed_out, outcomes_hash, fast_code, processed, created_at, updated_at, full_name, phone_number, outcomes, company_slug
|
|
FROM bet_with_outcomes
|
|
WHERE status = 2
|
|
AND processed = false
|
|
`
|
|
|
|
func (q *Queries) GetBetsForCashback(ctx context.Context) ([]BetWithOutcome, error) {
|
|
rows, err := q.db.Query(ctx, GetBetsForCashback)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetWithOutcome
|
|
for rows.Next() {
|
|
var i BetWithOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.CompanyID,
|
|
&i.Amount,
|
|
&i.TotalOdds,
|
|
&i.Status,
|
|
&i.UserID,
|
|
&i.IsShopBet,
|
|
&i.CashedOut,
|
|
&i.OutcomesHash,
|
|
&i.FastCode,
|
|
&i.Processed,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.FullName,
|
|
&i.PhoneNumber,
|
|
&i.Outcomes,
|
|
&i.CompanySlug,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetTotalBets = `-- name: GetTotalBets :one
|
|
SELECT COUNT(*)
|
|
FROM bets
|
|
wHERE (
|
|
user_id = $1
|
|
OR $1 IS NULL
|
|
)
|
|
AND (
|
|
is_shop_bet = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
company_id = $3
|
|
OR $3 IS NULL
|
|
)
|
|
AND (
|
|
status = $4
|
|
OR $4 IS NULL
|
|
)
|
|
AND (
|
|
cashed_out = $5
|
|
OR $5 IS NULL
|
|
)
|
|
AND (
|
|
full_name ILIKE '%' || $6 || '%'
|
|
OR phone_number ILIKE '%' || $6 || '%'
|
|
OR $6 IS NULL
|
|
)
|
|
AND (
|
|
created_at > $7
|
|
OR $7 IS NULL
|
|
)
|
|
AND (
|
|
created_at < $8
|
|
OR $8 IS NULL
|
|
)
|
|
`
|
|
|
|
type GetTotalBetsParams struct {
|
|
UserID pgtype.Int8 `json:"user_id"`
|
|
IsShopBet pgtype.Bool `json:"is_shop_bet"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
Status pgtype.Int4 `json:"status"`
|
|
CashedOut pgtype.Bool `json:"cashed_out"`
|
|
Query pgtype.Text `json:"query"`
|
|
CreatedBefore pgtype.Timestamp `json:"created_before"`
|
|
CreatedAfter pgtype.Timestamp `json:"created_after"`
|
|
}
|
|
|
|
func (q *Queries) GetTotalBets(ctx context.Context, arg GetTotalBetsParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetTotalBets,
|
|
arg.UserID,
|
|
arg.IsShopBet,
|
|
arg.CompanyID,
|
|
arg.Status,
|
|
arg.CashedOut,
|
|
arg.Query,
|
|
arg.CreatedBefore,
|
|
arg.CreatedAfter,
|
|
)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const TotalBetOutcomeViewByEventID = `-- name: TotalBetOutcomeViewByEventID :one
|
|
SELECT count(*)
|
|
FROM bet_outcomes
|
|
JOIN bets ON bets.id = bet_outcomes.bet_id
|
|
WHERE bet_outcomes.event_id = $1
|
|
AND (
|
|
bets.company_id = $2
|
|
OR $2 IS NULL
|
|
)
|
|
AND (
|
|
bet_outcomes.status = $3
|
|
OR $3 IS NULL
|
|
)
|
|
`
|
|
|
|
type TotalBetOutcomeViewByEventIDParams struct {
|
|
EventID int64 `json:"event_id"`
|
|
CompanyID pgtype.Int8 `json:"company_id"`
|
|
FilterStatus pgtype.Int4 `json:"filter_status"`
|
|
}
|
|
|
|
func (q *Queries) TotalBetOutcomeViewByEventID(ctx context.Context, arg TotalBetOutcomeViewByEventIDParams) (int64, error) {
|
|
row := q.db.QueryRow(ctx, TotalBetOutcomeViewByEventID, arg.EventID, arg.CompanyID, arg.FilterStatus)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const UpdateBetOutcomeStatus = `-- name: UpdateBetOutcomeStatus :one
|
|
UPDATE bet_outcomes
|
|
SET status = $1
|
|
WHERE id = $2
|
|
RETURNING id, bet_id, sport_id, event_id, odd_id, home_team_name, away_team_name, market_id, market_name, odd, odd_name, odd_header, odd_handicap, status, expires
|
|
`
|
|
|
|
type UpdateBetOutcomeStatusParams struct {
|
|
Status int32 `json:"status"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBetOutcomeStatus(ctx context.Context, arg UpdateBetOutcomeStatusParams) (BetOutcome, error) {
|
|
row := q.db.QueryRow(ctx, UpdateBetOutcomeStatus, arg.Status, arg.ID)
|
|
var i BetOutcome
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.BetID,
|
|
&i.SportID,
|
|
&i.EventID,
|
|
&i.OddID,
|
|
&i.HomeTeamName,
|
|
&i.AwayTeamName,
|
|
&i.MarketID,
|
|
&i.MarketName,
|
|
&i.Odd,
|
|
&i.OddName,
|
|
&i.OddHeader,
|
|
&i.OddHandicap,
|
|
&i.Status,
|
|
&i.Expires,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const UpdateBetOutcomeStatusByBetID = `-- name: UpdateBetOutcomeStatusByBetID :one
|
|
UPDATE bet_outcomes
|
|
SET status = $1
|
|
WHERE bet_id = $2
|
|
RETURNING id, bet_id, sport_id, event_id, odd_id, home_team_name, away_team_name, market_id, market_name, odd, odd_name, odd_header, odd_handicap, status, expires
|
|
`
|
|
|
|
type UpdateBetOutcomeStatusByBetIDParams struct {
|
|
Status int32 `json:"status"`
|
|
BetID int64 `json:"bet_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBetOutcomeStatusByBetID(ctx context.Context, arg UpdateBetOutcomeStatusByBetIDParams) (BetOutcome, error) {
|
|
row := q.db.QueryRow(ctx, UpdateBetOutcomeStatusByBetID, arg.Status, arg.BetID)
|
|
var i BetOutcome
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.BetID,
|
|
&i.SportID,
|
|
&i.EventID,
|
|
&i.OddID,
|
|
&i.HomeTeamName,
|
|
&i.AwayTeamName,
|
|
&i.MarketID,
|
|
&i.MarketName,
|
|
&i.Odd,
|
|
&i.OddName,
|
|
&i.OddHeader,
|
|
&i.OddHandicap,
|
|
&i.Status,
|
|
&i.Expires,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const UpdateBetOutcomeStatusForEvent = `-- name: UpdateBetOutcomeStatusForEvent :many
|
|
UPDATE bet_outcomes
|
|
SEt status = $1
|
|
WHERE event_id = $2
|
|
RETURNING id, bet_id, sport_id, event_id, odd_id, home_team_name, away_team_name, market_id, market_name, odd, odd_name, odd_header, odd_handicap, status, expires
|
|
`
|
|
|
|
type UpdateBetOutcomeStatusForEventParams struct {
|
|
Status int32 `json:"status"`
|
|
EventID int64 `json:"event_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBetOutcomeStatusForEvent(ctx context.Context, arg UpdateBetOutcomeStatusForEventParams) ([]BetOutcome, error) {
|
|
rows, err := q.db.Query(ctx, UpdateBetOutcomeStatusForEvent, arg.Status, arg.EventID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetOutcome
|
|
for rows.Next() {
|
|
var i BetOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BetID,
|
|
&i.SportID,
|
|
&i.EventID,
|
|
&i.OddID,
|
|
&i.HomeTeamName,
|
|
&i.AwayTeamName,
|
|
&i.MarketID,
|
|
&i.MarketName,
|
|
&i.Odd,
|
|
&i.OddName,
|
|
&i.OddHeader,
|
|
&i.OddHandicap,
|
|
&i.Status,
|
|
&i.Expires,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateBetOutcomeStatusForOddID = `-- name: UpdateBetOutcomeStatusForOddID :many
|
|
UPDATE bet_outcomes
|
|
SEt status = $1
|
|
WHERE odd_id = $2
|
|
RETURNING id, bet_id, sport_id, event_id, odd_id, home_team_name, away_team_name, market_id, market_name, odd, odd_name, odd_header, odd_handicap, status, expires
|
|
`
|
|
|
|
type UpdateBetOutcomeStatusForOddIDParams struct {
|
|
Status int32 `json:"status"`
|
|
OddID int64 `json:"odd_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBetOutcomeStatusForOddID(ctx context.Context, arg UpdateBetOutcomeStatusForOddIDParams) ([]BetOutcome, error) {
|
|
rows, err := q.db.Query(ctx, UpdateBetOutcomeStatusForOddID, arg.Status, arg.OddID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []BetOutcome
|
|
for rows.Next() {
|
|
var i BetOutcome
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.BetID,
|
|
&i.SportID,
|
|
&i.EventID,
|
|
&i.OddID,
|
|
&i.HomeTeamName,
|
|
&i.AwayTeamName,
|
|
&i.MarketID,
|
|
&i.MarketName,
|
|
&i.Odd,
|
|
&i.OddName,
|
|
&i.OddHeader,
|
|
&i.OddHandicap,
|
|
&i.Status,
|
|
&i.Expires,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdateBetWithCashback = `-- name: UpdateBetWithCashback :exec
|
|
UPDATE bets
|
|
SET processed = $1
|
|
WHERE id = $2
|
|
`
|
|
|
|
type UpdateBetWithCashbackParams struct {
|
|
Processed bool `json:"processed"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBetWithCashback(ctx context.Context, arg UpdateBetWithCashbackParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateBetWithCashback, arg.Processed, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const UpdateCashOut = `-- name: UpdateCashOut :exec
|
|
UPDATE bets
|
|
SET cashed_out = $2,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdateCashOutParams struct {
|
|
ID int64 `json:"id"`
|
|
CashedOut bool `json:"cashed_out"`
|
|
}
|
|
|
|
func (q *Queries) UpdateCashOut(ctx context.Context, arg UpdateCashOutParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateCashOut, arg.ID, arg.CashedOut)
|
|
return err
|
|
}
|
|
|
|
const UpdateStatus = `-- name: UpdateStatus :exec
|
|
UPDATE bets
|
|
SET status = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $2
|
|
`
|
|
|
|
type UpdateStatusParams struct {
|
|
Status int32 `json:"status"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateStatus(ctx context.Context, arg UpdateStatusParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateStatus, arg.Status, arg.ID)
|
|
return err
|
|
}
|