enetpulse 1st phase repo and cron job implementation
This commit is contained in:
parent
0eac6e363d
commit
6ceff2843e
2
db/migrations/000006_enet_pulse.down.sql
Normal file
2
db/migrations/000006_enet_pulse.down.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DROP TABLE IF EXISTS enetpulse_sports;
|
||||
DROP TABLE IF EXISTS enetpulse_tournament_templates;
|
||||
23
db/migrations/000006_enet_pulse.up.sql
Normal file
23
db/migrations/000006_enet_pulse.up.sql
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
CREATE TABLE IF NOT EXISTS enetpulse_sports (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
sport_id VARCHAR(50) NOT NULL UNIQUE, -- from API "id"
|
||||
name VARCHAR(255) NOT NULL, -- from API "name"
|
||||
updates_count INT DEFAULT 0, -- from API "n"
|
||||
last_updated_at TIMESTAMPTZ, -- from API "ut"
|
||||
status INT DEFAULT 1, -- optional status (active/inactive)
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS enetpulse_tournament_templates (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
template_id VARCHAR(50) NOT NULL UNIQUE, -- from API "id"
|
||||
name VARCHAR(255) NOT NULL, -- from API "name"
|
||||
sport_fk VARCHAR(50) NOT NULL REFERENCES enetpulse_sports(sport_id) ON DELETE CASCADE,
|
||||
gender VARCHAR(20) DEFAULT 'unknown', -- from API "gender" {male, female, mixed, unknown}
|
||||
updates_count INT DEFAULT 0, -- from API "n"
|
||||
last_updated_at TIMESTAMPTZ, -- from API "ut"
|
||||
status INT DEFAULT 1, -- optional status (active/inactive)
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMPTZ
|
||||
);
|
||||
57
db/query/enet_pulse.sql
Normal file
57
db/query/enet_pulse.sql
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
-- name: CreateEnetpulseSport :one
|
||||
INSERT INTO enetpulse_sports (
|
||||
sport_id,
|
||||
name,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, NOW()
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetAllEnetpulseSports :many
|
||||
SELECT
|
||||
id,
|
||||
sport_id,
|
||||
name,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM enetpulse_sports
|
||||
ORDER BY name;
|
||||
|
||||
-- name: CreateEnetpulseTournamentTemplate :one
|
||||
INSERT INTO enetpulse_tournament_templates (
|
||||
template_id,
|
||||
name,
|
||||
sport_fk,
|
||||
gender,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, NOW()
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
|
||||
-- name: GetAllEnetpulseTournamentTemplates :many
|
||||
SELECT
|
||||
id,
|
||||
template_id,
|
||||
name,
|
||||
sport_fk,
|
||||
gender,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM enetpulse_tournament_templates
|
||||
ORDER BY name;
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: auth.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: bet.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: bet_stat.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: bonus.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: branch.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: cashier.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: company.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: copyfrom.go
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
|
||||
package dbgen
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: direct_deposit.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: disabled_odds.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
198
gen/db/enet_pulse.sql.go
Normal file
198
gen/db/enet_pulse.sql.go
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.29.0
|
||||
// source: enet_pulse.sql
|
||||
|
||||
package dbgen
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const CreateEnetpulseSport = `-- name: CreateEnetpulseSport :one
|
||||
INSERT INTO enetpulse_sports (
|
||||
sport_id,
|
||||
name,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, NOW()
|
||||
)
|
||||
RETURNING id, sport_id, name, updates_count, last_updated_at, status, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateEnetpulseSportParams struct {
|
||||
SportID string `json:"sport_id"`
|
||||
Name string `json:"name"`
|
||||
UpdatesCount pgtype.Int4 `json:"updates_count"`
|
||||
LastUpdatedAt pgtype.Timestamptz `json:"last_updated_at"`
|
||||
Status pgtype.Int4 `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateEnetpulseSport(ctx context.Context, arg CreateEnetpulseSportParams) (EnetpulseSport, error) {
|
||||
row := q.db.QueryRow(ctx, CreateEnetpulseSport,
|
||||
arg.SportID,
|
||||
arg.Name,
|
||||
arg.UpdatesCount,
|
||||
arg.LastUpdatedAt,
|
||||
arg.Status,
|
||||
)
|
||||
var i EnetpulseSport
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SportID,
|
||||
&i.Name,
|
||||
&i.UpdatesCount,
|
||||
&i.LastUpdatedAt,
|
||||
&i.Status,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const CreateEnetpulseTournamentTemplate = `-- name: CreateEnetpulseTournamentTemplate :one
|
||||
INSERT INTO enetpulse_tournament_templates (
|
||||
template_id,
|
||||
name,
|
||||
sport_fk,
|
||||
gender,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7, NOW()
|
||||
)
|
||||
RETURNING id, template_id, name, sport_fk, gender, updates_count, last_updated_at, status, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateEnetpulseTournamentTemplateParams struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
Name string `json:"name"`
|
||||
SportFk string `json:"sport_fk"`
|
||||
Gender pgtype.Text `json:"gender"`
|
||||
UpdatesCount pgtype.Int4 `json:"updates_count"`
|
||||
LastUpdatedAt pgtype.Timestamptz `json:"last_updated_at"`
|
||||
Status pgtype.Int4 `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateEnetpulseTournamentTemplate(ctx context.Context, arg CreateEnetpulseTournamentTemplateParams) (EnetpulseTournamentTemplate, error) {
|
||||
row := q.db.QueryRow(ctx, CreateEnetpulseTournamentTemplate,
|
||||
arg.TemplateID,
|
||||
arg.Name,
|
||||
arg.SportFk,
|
||||
arg.Gender,
|
||||
arg.UpdatesCount,
|
||||
arg.LastUpdatedAt,
|
||||
arg.Status,
|
||||
)
|
||||
var i EnetpulseTournamentTemplate
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.TemplateID,
|
||||
&i.Name,
|
||||
&i.SportFk,
|
||||
&i.Gender,
|
||||
&i.UpdatesCount,
|
||||
&i.LastUpdatedAt,
|
||||
&i.Status,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const GetAllEnetpulseSports = `-- name: GetAllEnetpulseSports :many
|
||||
SELECT
|
||||
id,
|
||||
sport_id,
|
||||
name,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM enetpulse_sports
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllEnetpulseSports(ctx context.Context) ([]EnetpulseSport, error) {
|
||||
rows, err := q.db.Query(ctx, GetAllEnetpulseSports)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EnetpulseSport
|
||||
for rows.Next() {
|
||||
var i EnetpulseSport
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SportID,
|
||||
&i.Name,
|
||||
&i.UpdatesCount,
|
||||
&i.LastUpdatedAt,
|
||||
&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 GetAllEnetpulseTournamentTemplates = `-- name: GetAllEnetpulseTournamentTemplates :many
|
||||
SELECT
|
||||
id,
|
||||
template_id,
|
||||
name,
|
||||
sport_fk,
|
||||
gender,
|
||||
updates_count,
|
||||
last_updated_at,
|
||||
status,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM enetpulse_tournament_templates
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
func (q *Queries) GetAllEnetpulseTournamentTemplates(ctx context.Context) ([]EnetpulseTournamentTemplate, error) {
|
||||
rows, err := q.db.Query(ctx, GetAllEnetpulseTournamentTemplates)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EnetpulseTournamentTemplate
|
||||
for rows.Next() {
|
||||
var i EnetpulseTournamentTemplate
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.TemplateID,
|
||||
&i.Name,
|
||||
&i.SportFk,
|
||||
&i.Gender,
|
||||
&i.UpdatesCount,
|
||||
&i.LastUpdatedAt,
|
||||
&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
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: event_history.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: events.sql
|
||||
|
||||
package dbgen
|
||||
|
|
@ -513,166 +513,6 @@ func (q *Queries) GetEventsWithSettings(ctx context.Context, arg GetEventsWithSe
|
|||
return items, nil
|
||||
}
|
||||
|
||||
const GetExpiredEvents = `-- name: GetExpiredEvents :many
|
||||
SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc
|
||||
FROM event_with_country
|
||||
WHERE start_time < now()
|
||||
and (
|
||||
status = $1
|
||||
OR $1 IS NULL
|
||||
)
|
||||
ORDER BY start_time ASC
|
||||
`
|
||||
|
||||
func (q *Queries) GetExpiredEvents(ctx context.Context, status pgtype.Text) ([]EventWithCountry, error) {
|
||||
rows, err := q.db.Query(ctx, GetExpiredEvents, status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EventWithCountry
|
||||
for rows.Next() {
|
||||
var i EventWithCountry
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SportID,
|
||||
&i.MatchName,
|
||||
&i.HomeTeam,
|
||||
&i.AwayTeam,
|
||||
&i.HomeTeamID,
|
||||
&i.AwayTeamID,
|
||||
&i.HomeKitImage,
|
||||
&i.AwayKitImage,
|
||||
&i.LeagueID,
|
||||
&i.LeagueName,
|
||||
&i.StartTime,
|
||||
&i.Score,
|
||||
&i.MatchMinute,
|
||||
&i.TimerStatus,
|
||||
&i.AddedTime,
|
||||
&i.MatchPeriod,
|
||||
&i.IsLive,
|
||||
&i.Status,
|
||||
&i.FetchedAt,
|
||||
&i.Source,
|
||||
&i.DefaultIsActive,
|
||||
&i.DefaultIsFeatured,
|
||||
&i.DefaultWinningUpperLimit,
|
||||
&i.IsMonitored,
|
||||
&i.LeagueCc,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetPaginatedUpcomingEvents = `-- name: GetPaginatedUpcomingEvents :many
|
||||
SELECT id, sport_id, match_name, home_team, away_team, home_team_id, away_team_id, home_kit_image, away_kit_image, league_id, league_name, start_time, score, match_minute, timer_status, added_time, match_period, is_live, status, fetched_at, source, default_is_active, default_is_featured, default_winning_upper_limit, is_monitored, league_cc
|
||||
FROM event_with_country
|
||||
WHERE start_time > now()
|
||||
AND is_live = false
|
||||
AND status = 'upcoming'
|
||||
AND (
|
||||
league_id = $1
|
||||
OR $1 IS NULL
|
||||
)
|
||||
AND (
|
||||
sport_id = $2
|
||||
OR $2 IS NULL
|
||||
)
|
||||
AND (
|
||||
match_name ILIKE '%' || $3 || '%'
|
||||
OR league_name ILIKE '%' || $3 || '%'
|
||||
OR $3 IS NULL
|
||||
)
|
||||
AND (
|
||||
start_time < $4
|
||||
OR $4 IS NULL
|
||||
)
|
||||
AND (
|
||||
start_time > $5
|
||||
OR $5 IS NULL
|
||||
)
|
||||
AND (
|
||||
league_cc = $6
|
||||
OR $6 IS NULL
|
||||
)
|
||||
ORDER BY start_time ASC
|
||||
LIMIT $8 OFFSET $7
|
||||
`
|
||||
|
||||
type GetPaginatedUpcomingEventsParams struct {
|
||||
LeagueID pgtype.Int8 `json:"league_id"`
|
||||
SportID pgtype.Int4 `json:"sport_id"`
|
||||
Query pgtype.Text `json:"query"`
|
||||
LastStartTime pgtype.Timestamp `json:"last_start_time"`
|
||||
FirstStartTime pgtype.Timestamp `json:"first_start_time"`
|
||||
CountryCode pgtype.Text `json:"country_code"`
|
||||
Offset pgtype.Int4 `json:"offset"`
|
||||
Limit pgtype.Int4 `json:"limit"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetPaginatedUpcomingEvents(ctx context.Context, arg GetPaginatedUpcomingEventsParams) ([]EventWithCountry, error) {
|
||||
rows, err := q.db.Query(ctx, GetPaginatedUpcomingEvents,
|
||||
arg.LeagueID,
|
||||
arg.SportID,
|
||||
arg.Query,
|
||||
arg.LastStartTime,
|
||||
arg.FirstStartTime,
|
||||
arg.CountryCode,
|
||||
arg.Offset,
|
||||
arg.Limit,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []EventWithCountry
|
||||
for rows.Next() {
|
||||
var i EventWithCountry
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.SportID,
|
||||
&i.MatchName,
|
||||
&i.HomeTeam,
|
||||
&i.AwayTeam,
|
||||
&i.HomeTeamID,
|
||||
&i.AwayTeamID,
|
||||
&i.HomeKitImage,
|
||||
&i.AwayKitImage,
|
||||
&i.LeagueID,
|
||||
&i.LeagueName,
|
||||
&i.StartTime,
|
||||
&i.Score,
|
||||
&i.MatchMinute,
|
||||
&i.TimerStatus,
|
||||
&i.AddedTime,
|
||||
&i.MatchPeriod,
|
||||
&i.IsLive,
|
||||
&i.Status,
|
||||
&i.FetchedAt,
|
||||
&i.Source,
|
||||
&i.DefaultIsActive,
|
||||
&i.DefaultIsFeatured,
|
||||
&i.DefaultWinningUpperLimit,
|
||||
&i.IsMonitored,
|
||||
&i.LeagueCc,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const GetSportAndLeagueIDs = `-- name: GetSportAndLeagueIDs :one
|
||||
SELECT sport_id, league_id FROM events
|
||||
WHERE id = $1
|
||||
|
|
@ -683,7 +523,7 @@ type GetSportAndLeagueIDsRow struct {
|
|||
LeagueID int64 `json:"league_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetSportAndLeagueIDs(ctx context.Context, id string) (GetSportAndLeagueIDsRow, error) {
|
||||
func (q *Queries) GetSportAndLeagueIDs(ctx context.Context, id int64) (GetSportAndLeagueIDsRow, error) {
|
||||
row := q.db.QueryRow(ctx, GetSportAndLeagueIDs, id)
|
||||
var i GetSportAndLeagueIDsRow
|
||||
err := row.Scan(&i.SportID, &i.LeagueID)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: events_stat.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: flags.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: institutions.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: issue_reporting.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: leagues.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: location.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
|
||||
package dbgen
|
||||
|
||||
|
|
@ -244,6 +244,30 @@ type DisabledOdd struct {
|
|||
CreatedAt pgtype.Timestamp `json:"created_at"`
|
||||
}
|
||||
|
||||
type EnetpulseSport struct {
|
||||
ID int64 `json:"id"`
|
||||
SportID string `json:"sport_id"`
|
||||
Name string `json:"name"`
|
||||
UpdatesCount pgtype.Int4 `json:"updates_count"`
|
||||
LastUpdatedAt pgtype.Timestamptz `json:"last_updated_at"`
|
||||
Status pgtype.Int4 `json:"status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type EnetpulseTournamentTemplate struct {
|
||||
ID int64 `json:"id"`
|
||||
TemplateID string `json:"template_id"`
|
||||
Name string `json:"name"`
|
||||
SportFk string `json:"sport_fk"`
|
||||
Gender pgtype.Text `json:"gender"`
|
||||
UpdatesCount pgtype.Int4 `json:"updates_count"`
|
||||
LastUpdatedAt pgtype.Timestamptz `json:"last_updated_at"`
|
||||
Status pgtype.Int4 `json:"status"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
ID int64 `json:"id"`
|
||||
SourceEventID string `json:"source_event_id"`
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: monitor.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: notification.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: odd_history.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: odds.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: otp.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: raffle.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: referal.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: report.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: result.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: result_log.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: settings.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: shop_transactions.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: ticket.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: transfer.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: user.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: virtual_games.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// sqlc v1.29.0
|
||||
// source: wallet.sql
|
||||
|
||||
package dbgen
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type EnetPulseSport struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
|
@ -365,3 +367,45 @@ type TournamentOddsResponse struct {
|
|||
TournamentID int64 `json:"objectFK"`
|
||||
Odds []PreMatchOutcome `json:"odds"` // reuse PreMatchOutcome struct from pre-match odds
|
||||
}
|
||||
|
||||
type CreateEnetpulseSport struct {
|
||||
SportID string `json:"sport_id"` // from API "id"
|
||||
Name string `json:"name"` // from API "name"
|
||||
UpdatesCount int `json:"updates_count,omitempty"` // from API "n"
|
||||
LastUpdatedAt time.Time `json:"last_updated_at"` // from API "ut"
|
||||
Status int `json:"status,omitempty"` // optional, default 1
|
||||
}
|
||||
|
||||
type EnetpulseSport struct {
|
||||
ID int64 `json:"id"` // DB primary key
|
||||
SportID string `json:"sport_id"` // from API "id"
|
||||
Name string `json:"name"` // from API "name"
|
||||
UpdatesCount int `json:"updates_count"` // from API "n"
|
||||
LastUpdatedAt time.Time `json:"last_updated_at"`
|
||||
Status int `json:"status"` // active/inactive
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type EnetpulseTournamentTemplate struct {
|
||||
ID int64 `json:"id"`
|
||||
TemplateID string `json:"template_id"` // from API "id"
|
||||
Name string `json:"name"` // from API "name"
|
||||
SportFK string `json:"sport_fk"` // related sport id
|
||||
Gender string `json:"gender"` // male, female, mixed, unknown
|
||||
UpdatesCount int `json:"updates_count"` // from API "n"
|
||||
LastUpdatedAt time.Time `json:"last_updated_at"`
|
||||
Status int `json:"status"` // optional
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type CreateEnetpulseTournamentTemplate struct {
|
||||
TemplateID string `json:"templateId"` // from API "id"
|
||||
Name string `json:"name"` // from API "name"
|
||||
SportFK int64 `json:"sportFK"` // foreign key to sport
|
||||
Gender string `json:"gender"` // male, female, mixed, unknown
|
||||
UpdatesCount int `json:"updatesCount"` // from API "n"
|
||||
LastUpdatedAt time.Time `json:"lastUpdatedAt"` // from API "ut"
|
||||
Status int `json:"status"` // optional, e.g., active/inactive
|
||||
}
|
||||
|
|
|
|||
141
internal/repository/enet_pulse.go
Normal file
141
internal/repository/enet_pulse.go
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func (s *Store) CreateEnetpulseSport(ctx context.Context, sport domain.CreateEnetpulseSport) (domain.EnetpulseSport, error) {
|
||||
// Convert domain model to DB model if needed
|
||||
dbSport, err := s.queries.CreateEnetpulseSport(ctx, ConvertCreateEnetpulseSport(sport))
|
||||
if err != nil {
|
||||
return domain.EnetpulseSport{}, err
|
||||
}
|
||||
return ConvertDBEnetpulseSport(dbSport), nil
|
||||
}
|
||||
|
||||
// Fetch all sports
|
||||
func (s *Store) GetAllEnetpulseSports(ctx context.Context) ([]domain.EnetpulseSport, error) {
|
||||
dbSports, err := s.queries.GetAllEnetpulseSports(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var sports []domain.EnetpulseSport
|
||||
for _, dbSport := range dbSports {
|
||||
sports = append(sports, ConvertDBEnetpulseSport(dbSport))
|
||||
}
|
||||
|
||||
return sports, nil
|
||||
}
|
||||
|
||||
func (s *Store) CreateEnetpulseTournamentTemplate(
|
||||
ctx context.Context,
|
||||
template domain.CreateEnetpulseTournamentTemplate,
|
||||
) (domain.EnetpulseTournamentTemplate, error) {
|
||||
// Convert domain model to DB model if needed
|
||||
dbTemplate, err := s.queries.CreateEnetpulseTournamentTemplate(
|
||||
ctx,
|
||||
ConvertCreateEnetpulseTournamentTemplate(template),
|
||||
)
|
||||
if err != nil {
|
||||
return domain.EnetpulseTournamentTemplate{}, err
|
||||
}
|
||||
return ConvertDBEnetpulseTournamentTemplate(dbTemplate), nil
|
||||
}
|
||||
|
||||
// Fetch all tournament templates
|
||||
func (s *Store) GetAllEnetpulseTournamentTemplates(ctx context.Context) ([]domain.EnetpulseTournamentTemplate, error) {
|
||||
dbTemplates, err := s.queries.GetAllEnetpulseTournamentTemplates(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var templates []domain.EnetpulseTournamentTemplate
|
||||
for _, dbTemplate := range dbTemplates {
|
||||
templates = append(templates, ConvertDBEnetpulseTournamentTemplate(dbTemplate))
|
||||
}
|
||||
|
||||
return templates, nil
|
||||
}
|
||||
|
||||
func ConvertCreateEnetpulseSport(s domain.CreateEnetpulseSport) dbgen.CreateEnetpulseSportParams {
|
||||
return dbgen.CreateEnetpulseSportParams{
|
||||
SportID: s.SportID,
|
||||
Name: s.Name,
|
||||
UpdatesCount: pgtype.Int4{Int32: int32(s.UpdatesCount), Valid: true}, // SQLC might use int32
|
||||
LastUpdatedAt: pgtype.Timestamptz{Time: s.LastUpdatedAt, Valid: true},
|
||||
Status: pgtype.Int4{Int32: int32(s.Status), Valid: true},
|
||||
// UpdatedAt: nil, // SQLC will default NOW() if nil
|
||||
}
|
||||
}
|
||||
|
||||
func ConvertDBEnetpulseSport(db dbgen.EnetpulseSport) domain.EnetpulseSport {
|
||||
return domain.EnetpulseSport{
|
||||
ID: db.ID,
|
||||
SportID: db.SportID,
|
||||
Name: db.Name,
|
||||
UpdatesCount: func() int {
|
||||
if db.UpdatesCount.Valid {
|
||||
return int(db.UpdatesCount.Int32)
|
||||
}
|
||||
return 0 // or another default value if needed
|
||||
}(), // cast from int32
|
||||
LastUpdatedAt: db.LastUpdatedAt.Time,
|
||||
Status: func() int {
|
||||
if db.Status.Valid {
|
||||
return int(db.Status.Int32)
|
||||
}
|
||||
return 0 // or another default value if needed
|
||||
}(), // cast from int32
|
||||
CreatedAt: db.CreatedAt.Time,
|
||||
UpdatedAt: db.UpdatedAt.Time,
|
||||
}
|
||||
}
|
||||
|
||||
func ConvertDBEnetpulseTournamentTemplate(db dbgen.EnetpulseTournamentTemplate) domain.EnetpulseTournamentTemplate {
|
||||
return domain.EnetpulseTournamentTemplate{
|
||||
ID: db.ID,
|
||||
TemplateID: db.TemplateID,
|
||||
Name: db.Name,
|
||||
SportFK: db.SportFk,
|
||||
Gender: func() string {
|
||||
if db.Gender.Valid {
|
||||
return db.Gender.String
|
||||
}
|
||||
return ""
|
||||
}(),
|
||||
UpdatesCount: func() int {
|
||||
if db.UpdatesCount.Valid {
|
||||
return int(db.UpdatesCount.Int32)
|
||||
}
|
||||
return 0
|
||||
}(),
|
||||
LastUpdatedAt: db.LastUpdatedAt.Time,
|
||||
Status: func() int {
|
||||
if db.Status.Valid {
|
||||
return int(db.Status.Int32)
|
||||
}
|
||||
return 0
|
||||
}(),
|
||||
CreatedAt: db.CreatedAt.Time,
|
||||
UpdatedAt: db.UpdatedAt.Time,
|
||||
}
|
||||
}
|
||||
|
||||
func ConvertCreateEnetpulseTournamentTemplate(
|
||||
t domain.CreateEnetpulseTournamentTemplate,
|
||||
) dbgen.CreateEnetpulseTournamentTemplateParams {
|
||||
return dbgen.CreateEnetpulseTournamentTemplateParams{
|
||||
TemplateID: t.TemplateID,
|
||||
SportFk: fmt.Sprintf("%d", t.SportFK),
|
||||
Gender: pgtype.Text{String: t.Gender, Valid: t.Gender != ""},
|
||||
UpdatesCount: pgtype.Int4{Int32: int32(t.UpdatesCount), Valid: true},
|
||||
LastUpdatedAt: pgtype.Timestamptz{Time: t.LastUpdatedAt, Valid: true},
|
||||
Status: pgtype.Int4{Int32: int32(t.Status), Valid: true},
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||
|
|
@ -294,7 +295,11 @@ func (s *Store) DeleteEvent(ctx context.Context, eventID int64) error {
|
|||
}
|
||||
|
||||
func (s *Store) GetSportAndLeagueIDs(ctx context.Context, eventID string) ([]int64, error) {
|
||||
sportAndLeagueIDs, err := s.queries.GetSportAndLeagueIDs(ctx, eventID)
|
||||
id, err := strconv.ParseInt(eventID, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid eventID: %v", err)
|
||||
}
|
||||
sportAndLeagueIDs, err := s.queries.GetSportAndLeagueIDs(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/config"
|
||||
|
|
@ -33,42 +34,167 @@ func New(cfg config.Config, store *repository.Store) *Service {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Service) FetchSports(ctx context.Context) error {
|
||||
func (s *Service) FetchAndStoreSports(ctx context.Context) error {
|
||||
// 1️⃣ Compose URL with credentials
|
||||
url := fmt.Sprintf(
|
||||
"http://eapi.enetpulse.com/sport/list/?username=%s&token=%s",
|
||||
s.cfg.EnetPulseConfig.UserName, s.cfg.EnetPulseConfig.Token,
|
||||
)
|
||||
|
||||
// 2️⃣ Create HTTP request with context
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating sport request: %w", err)
|
||||
}
|
||||
|
||||
// 3️⃣ Execute request
|
||||
resp, err := s.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("requesting sports: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 4️⃣ Check response status
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf("failed to fetch sports (status %d): %s",
|
||||
resp.StatusCode, string(body))
|
||||
return fmt.Errorf("failed to fetch sports (status %d): %s", resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
var sportsResp domain.SportsResponse
|
||||
// 5️⃣ Decode JSON response
|
||||
var sportsResp struct {
|
||||
Sports map[string]struct {
|
||||
ID string `json:"id"`
|
||||
N string `json:"n"` // updates count
|
||||
Name string `json:"name"`
|
||||
UT string `json:"ut"` // timestamp string
|
||||
} `json:"sports"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&sportsResp); err != nil {
|
||||
return fmt.Errorf("decoding sports response: %w", err)
|
||||
}
|
||||
|
||||
// Example: save sports to store or process
|
||||
// 6️⃣ Iterate and store each sport
|
||||
for _, sport := range sportsResp.Sports {
|
||||
// Insert/update in DB or cache
|
||||
// e.g. s.store.SaveSport(ctx, sport)
|
||||
fmt.Printf("Fetched sport: ID=%s Name=%s UpdatedAt=%s\n",
|
||||
sport.ID, sport.Name, sport.UT)
|
||||
// Parse updates count
|
||||
updatesCount := 0
|
||||
if sport.N != "" {
|
||||
if n, err := strconv.Atoi(sport.N); err == nil {
|
||||
updatesCount = n
|
||||
}
|
||||
}
|
||||
|
||||
// Parse timestamp
|
||||
lastUpdatedAt, err := time.Parse(time.RFC3339, sport.UT)
|
||||
if err != nil {
|
||||
// Fallback to zero time if parsing fails
|
||||
lastUpdatedAt = time.Time{}
|
||||
}
|
||||
|
||||
// Build domain object
|
||||
createSport := domain.CreateEnetpulseSport{
|
||||
SportID: sport.ID,
|
||||
Name: sport.Name,
|
||||
UpdatesCount: updatesCount,
|
||||
LastUpdatedAt: lastUpdatedAt,
|
||||
Status: 1, // default active
|
||||
}
|
||||
|
||||
// Insert or update in DB
|
||||
if _, err := s.store.CreateEnetpulseSport(ctx, createSport); err != nil {
|
||||
// Log error but continue
|
||||
// s.logger.Error("failed to store sport", zap.String("sport_id", sport.ID), zap.Error(err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// s.logger.Info("Successfully fetched and stored sports", zap.Int("count", len(sportsResp.Sports)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) FetchAndStoreTournamentTemplates(ctx context.Context) error {
|
||||
// 1️⃣ Fetch all sports from the database
|
||||
sports, err := s.store.GetAllEnetpulseSports(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fetch sports from DB: %w", err)
|
||||
}
|
||||
|
||||
for _, sport := range sports {
|
||||
// 2️⃣ Compose URL for each sport using its sportID
|
||||
url := fmt.Sprintf(
|
||||
"http://eapi.enetpulse.com/tournament_template/list/?sportFK=%s&username=%s&token=%s",
|
||||
sport.SportID,
|
||||
s.cfg.EnetPulseConfig.UserName,
|
||||
s.cfg.EnetPulseConfig.Token,
|
||||
)
|
||||
|
||||
// 3️⃣ Create HTTP request
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating tournament template request for sport %s: %w", sport.SportID, err)
|
||||
}
|
||||
|
||||
// 4️⃣ Execute request
|
||||
resp, err := s.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("requesting tournament templates for sport %s: %w", sport.SportID, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf("failed to fetch tournament templates for sport %s (status %d): %s",
|
||||
sport.SportID, resp.StatusCode, string(body))
|
||||
}
|
||||
|
||||
// 5️⃣ Decode JSON response
|
||||
var templatesResp struct {
|
||||
TournamentTemplates map[string]struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
SportFK string `json:"sportFK"`
|
||||
Gender string `json:"gender"`
|
||||
N string `json:"n"` // updates count
|
||||
UT string `json:"ut"` // timestamp
|
||||
} `json:"tournament_templates"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&templatesResp); err != nil {
|
||||
return fmt.Errorf("decoding tournament templates for sport %s: %w", sport.SportID, err)
|
||||
}
|
||||
|
||||
// 6️⃣ Iterate and store each tournament template
|
||||
for _, tmpl := range templatesResp.TournamentTemplates {
|
||||
updatesCount := 0
|
||||
if tmpl.N != "" {
|
||||
if n, err := strconv.Atoi(tmpl.N); err == nil {
|
||||
updatesCount = n
|
||||
}
|
||||
}
|
||||
|
||||
lastUpdatedAt, err := time.Parse(time.RFC3339, tmpl.UT)
|
||||
if err != nil {
|
||||
lastUpdatedAt = time.Time{}
|
||||
}
|
||||
|
||||
createTemplate := domain.CreateEnetpulseTournamentTemplate{
|
||||
TemplateID: tmpl.ID,
|
||||
Name: tmpl.Name,
|
||||
SportFK: sport.ID, // use DB sport ID
|
||||
Gender: tmpl.Gender,
|
||||
UpdatesCount: updatesCount,
|
||||
LastUpdatedAt: lastUpdatedAt,
|
||||
Status: 1, // default active
|
||||
}
|
||||
|
||||
// Insert into DB
|
||||
if _, err := s.store.CreateEnetpulseTournamentTemplate(ctx, createTemplate); err != nil {
|
||||
// Log error but continue
|
||||
// s.logger.Error("failed to store tournament template", zap.String("template_id", tmpl.ID), zap.Error(err))
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// s.logger.Info("Successfully fetched and stored all tournament templates")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||
betSvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/bet"
|
||||
enetpulse "github.com/SamuelTariku/FortuneBet-Backend/internal/services/enet_pulse"
|
||||
eventsvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/event"
|
||||
oddssvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/odds"
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/report"
|
||||
|
|
@ -242,3 +243,51 @@ func ProcessBetCashback(ctx context.Context, betService *betSvc.Service) {
|
|||
c.Start()
|
||||
log.Println("Cron jobs started for bet cashbacks")
|
||||
}
|
||||
|
||||
func StartEnetPulseCron(enetPulseSvc *enetpulse.Service, mongoLogger *zap.Logger) {
|
||||
c := cron.New(cron.WithSeconds())
|
||||
|
||||
schedule := []struct {
|
||||
spec string
|
||||
task func()
|
||||
}{
|
||||
{
|
||||
spec: "0 * * * * *", // Every minute
|
||||
task: func() {
|
||||
mongoLogger.Info("Began fetching and storing sports cron task")
|
||||
if err := enetPulseSvc.FetchAndStoreSports(context.Background()); err != nil {
|
||||
mongoLogger.Error("Failed to fetch and store sports",
|
||||
zap.Error(err),
|
||||
)
|
||||
} else {
|
||||
mongoLogger.Info("Completed fetching and storing sports without errors")
|
||||
}
|
||||
|
||||
mongoLogger.Info("Began fetching and storing tournament templates cron task")
|
||||
if err := enetPulseSvc.FetchAndStoreTournamentTemplates(context.Background()); err != nil {
|
||||
mongoLogger.Error("Failed to fetch and store tournament templates",
|
||||
zap.Error(err),
|
||||
)
|
||||
} else {
|
||||
mongoLogger.Info("Completed fetching and storing tournament templates without errors")
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, job := range schedule {
|
||||
// Run the task immediately at startup
|
||||
job.task()
|
||||
|
||||
// Schedule the task
|
||||
if _, err := c.AddFunc(job.spec, job.task); err != nil {
|
||||
mongoLogger.Error("Failed to schedule EnetPulse cron job",
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
c.Start()
|
||||
log.Println("EnetPulse cron jobs started for fetching and storing sports and tournament templates")
|
||||
mongoLogger.Info("EnetPulse cron jobs started for fetching and storing sports and tournament templates")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,34 @@ import (
|
|||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
// GetAtlasVGames godoc
|
||||
// @Summary List Atlas virtual games
|
||||
// @Description Retrieves available Atlas virtual games from the provider
|
||||
// @Tags Virtual Games - Atlas
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.Response{data=[]domain.AtlasGameEntity}
|
||||
// @Failure 502 {object} domain.ErrorResponse
|
||||
// @Router /api/v1/atlas/games [get]
|
||||
func (h *Handler) GetAtlasVGames(c *fiber.Ctx) error {
|
||||
// Call the service
|
||||
games, err := h.veliVirtualGameSvc.GetAtlasVGames(c.Context())
|
||||
if err != nil {
|
||||
log.Println("GetAtlasVGames error:", err)
|
||||
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
||||
Message: "Failed to fetch Atlas virtual games",
|
||||
Error: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// Return the list of games
|
||||
return c.Status(fiber.StatusOK).JSON(domain.Response{
|
||||
Message: "Atlas virtual games retrieved successfully",
|
||||
Data: games,
|
||||
StatusCode: fiber.StatusOK,
|
||||
Success: true,
|
||||
})
|
||||
}
|
||||
|
||||
// InitAtlasGame godoc
|
||||
// @Summary Start an Atlas virtual game session
|
||||
// @Description Initializes a game session for the given player using Atlas virtual game provider
|
||||
|
|
|
|||
|
|
@ -381,6 +381,7 @@ func (a *App) initAppRoutes() {
|
|||
groupV1.Post("/veli/credit-balances", a.authMiddleware, h.GetCreditBalances)
|
||||
|
||||
//Atlas Virtual Game Routes
|
||||
groupV1.Get("/atlas/games", a.authMiddleware, h.InitAtlasGame)
|
||||
groupV1.Post("/atlas/init-game", a.authMiddleware, h.InitAtlasGame)
|
||||
a.fiber.Post("/account", h.AtlasGetUserDataCallback)
|
||||
a.fiber.Post("/betwin", h.HandleAtlasBetWin)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user