fix market fetching
This commit is contained in:
parent
35b846bcc8
commit
d5be4803ae
|
|
@ -15,12 +15,26 @@ INSERT INTO odds (
|
||||||
is_active,
|
is_active,
|
||||||
source,
|
source,
|
||||||
fetched_at
|
fetched_at
|
||||||
) VALUES (
|
)
|
||||||
$1, $2, $3, $4, $5, $6, $7,
|
VALUES (
|
||||||
$8, $9, $10, $11, $12, $13, $14, $15
|
$1,
|
||||||
)
|
$2,
|
||||||
ON CONFLICT (event_id, market_id) DO UPDATE SET
|
$3,
|
||||||
odds_value = EXCLUDED.odds_value,
|
$4,
|
||||||
|
$5,
|
||||||
|
$6,
|
||||||
|
$7,
|
||||||
|
$8,
|
||||||
|
$9,
|
||||||
|
$10,
|
||||||
|
$11,
|
||||||
|
$12,
|
||||||
|
$13,
|
||||||
|
$14,
|
||||||
|
$15
|
||||||
|
) ON CONFLICT (event_id, market_id) DO
|
||||||
|
UPDATE
|
||||||
|
SET odds_value = EXCLUDED.odds_value,
|
||||||
raw_odds = EXCLUDED.raw_odds,
|
raw_odds = EXCLUDED.raw_odds,
|
||||||
market_type = EXCLUDED.market_type,
|
market_type = EXCLUDED.market_type,
|
||||||
market_name = EXCLUDED.market_name,
|
market_name = EXCLUDED.market_name,
|
||||||
|
|
@ -31,13 +45,8 @@ ON CONFLICT (event_id, market_id) DO UPDATE SET
|
||||||
is_active = EXCLUDED.is_active,
|
is_active = EXCLUDED.is_active,
|
||||||
source = EXCLUDED.source,
|
source = EXCLUDED.source,
|
||||||
fi = EXCLUDED.fi;
|
fi = EXCLUDED.fi;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- name: GetPrematchOdds :many
|
-- name: GetPrematchOdds :many
|
||||||
SELECT
|
SELECT event_id,
|
||||||
event_id,
|
|
||||||
fi,
|
fi,
|
||||||
market_type,
|
market_type,
|
||||||
market_name,
|
market_name,
|
||||||
|
|
@ -53,11 +62,10 @@ SELECT
|
||||||
source,
|
source,
|
||||||
is_active
|
is_active
|
||||||
FROM odds
|
FROM odds
|
||||||
WHERE is_active = true AND source = 'b365api';
|
WHERE is_active = true
|
||||||
|
AND source = 'b365api';
|
||||||
-- name: GetALLPrematchOdds :many
|
-- name: GetALLPrematchOdds :many
|
||||||
SELECT
|
SELECT event_id,
|
||||||
event_id,
|
|
||||||
fi,
|
fi,
|
||||||
market_type,
|
market_type,
|
||||||
market_name,
|
market_name,
|
||||||
|
|
@ -73,23 +81,20 @@ SELECT
|
||||||
source,
|
source,
|
||||||
is_active
|
is_active
|
||||||
FROM odds
|
FROM odds
|
||||||
WHERE is_active = true AND source = 'b365api';
|
WHERE is_active = true
|
||||||
|
AND source = 'b365api';
|
||||||
-- name: GetRawOddsByMarketID :many
|
-- name: GetRawOddsByMarketID :many
|
||||||
SELECT
|
SELECT id,
|
||||||
id,
|
|
||||||
raw_odds,
|
raw_odds,
|
||||||
fetched_at
|
fetched_at
|
||||||
FROM odds
|
FROM odds
|
||||||
WHERE
|
WHERE market_id = $1
|
||||||
market_id = $1 AND
|
AND fi = $2
|
||||||
is_active = true AND
|
AND is_active = true
|
||||||
source = 'b365api'
|
AND source = 'b365api'
|
||||||
LIMIT $2 OFFSET $3;
|
LIMIT $3 OFFSET $4;
|
||||||
|
|
||||||
-- name: GetPrematchOddsByUpcomingID :many
|
-- name: GetPrematchOddsByUpcomingID :many
|
||||||
SELECT
|
SELECT o.event_id,
|
||||||
o.event_id,
|
|
||||||
o.fi,
|
o.fi,
|
||||||
o.market_type,
|
o.market_type,
|
||||||
o.market_name,
|
o.market_name,
|
||||||
|
|
@ -105,7 +110,7 @@ SELECT
|
||||||
o.source,
|
o.source,
|
||||||
o.is_active
|
o.is_active
|
||||||
FROM odds o
|
FROM odds o
|
||||||
JOIN events e ON o.fi = e.id
|
JOIN events e ON o.fi = e.id
|
||||||
WHERE e.id = $1
|
WHERE e.id = $1
|
||||||
AND e.is_live = false
|
AND e.is_live = false
|
||||||
AND e.status = 'upcoming'
|
AND e.status = 'upcoming'
|
||||||
|
|
|
||||||
101
docs/docs.go
101
docs/docs.go
|
|
@ -1354,53 +1354,6 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/prematch/odds/raw/{market_id}": {
|
|
||||||
"get": {
|
|
||||||
"description": "Retrieve raw odds records using a Market ID",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"prematch"
|
|
||||||
],
|
|
||||||
"summary": "Retrieve raw odds by Market ID",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Market ID",
|
|
||||||
"name": "market_id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "OK",
|
|
||||||
"schema": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/definitions/domain.RawOddsByMarketID"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad Request",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/response.APIResponse"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal Server Error",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/response.APIResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/prematch/odds/upcoming/{upcoming_id}": {
|
"/prematch/odds/upcoming/{upcoming_id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Retrieve prematch odds by upcoming event ID (FI from Bet365) with optional pagination",
|
"description": "Retrieve prematch odds by upcoming event ID (FI from Bet365) with optional pagination",
|
||||||
|
|
@ -1460,6 +1413,60 @@ const docTemplate = `{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/prematch/odds/upcoming/{upcoming_id}/market/{market_id}": {
|
||||||
|
"get": {
|
||||||
|
"description": "Retrieve raw odds records using a Market ID",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"prematch"
|
||||||
|
],
|
||||||
|
"summary": "Retrieve raw odds by Market ID",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Upcoming ID",
|
||||||
|
"name": "upcoming_id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Market ID",
|
||||||
|
"name": "market_id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/domain.RawOddsByMarketID"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.APIResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.APIResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/prematch/odds/{event_id}": {
|
"/prematch/odds/{event_id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Retrieve prematch odds for a specific event by event ID",
|
"description": "Retrieve prematch odds for a specific event by event ID",
|
||||||
|
|
|
||||||
|
|
@ -1346,53 +1346,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/prematch/odds/raw/{market_id}": {
|
|
||||||
"get": {
|
|
||||||
"description": "Retrieve raw odds records using a Market ID",
|
|
||||||
"consumes": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"produces": [
|
|
||||||
"application/json"
|
|
||||||
],
|
|
||||||
"tags": [
|
|
||||||
"prematch"
|
|
||||||
],
|
|
||||||
"summary": "Retrieve raw odds by Market ID",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": "string",
|
|
||||||
"description": "Market ID",
|
|
||||||
"name": "market_id",
|
|
||||||
"in": "path",
|
|
||||||
"required": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "OK",
|
|
||||||
"schema": {
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/definitions/domain.RawOddsByMarketID"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"400": {
|
|
||||||
"description": "Bad Request",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/response.APIResponse"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal Server Error",
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/definitions/response.APIResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/prematch/odds/upcoming/{upcoming_id}": {
|
"/prematch/odds/upcoming/{upcoming_id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Retrieve prematch odds by upcoming event ID (FI from Bet365) with optional pagination",
|
"description": "Retrieve prematch odds by upcoming event ID (FI from Bet365) with optional pagination",
|
||||||
|
|
@ -1452,6 +1405,60 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/prematch/odds/upcoming/{upcoming_id}/market/{market_id}": {
|
||||||
|
"get": {
|
||||||
|
"description": "Retrieve raw odds records using a Market ID",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"prematch"
|
||||||
|
],
|
||||||
|
"summary": "Retrieve raw odds by Market ID",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Upcoming ID",
|
||||||
|
"name": "upcoming_id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Market ID",
|
||||||
|
"name": "market_id",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/domain.RawOddsByMarketID"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.APIResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/response.APIResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/prematch/odds/{event_id}": {
|
"/prematch/odds/{event_id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Retrieve prematch odds for a specific event by event ID",
|
"description": "Retrieve prematch odds for a specific event by event ID",
|
||||||
|
|
|
||||||
|
|
@ -1704,37 +1704,6 @@ paths:
|
||||||
summary: Retrieve prematch odds for an event
|
summary: Retrieve prematch odds for an event
|
||||||
tags:
|
tags:
|
||||||
- prematch
|
- prematch
|
||||||
/prematch/odds/raw/{market_id}:
|
|
||||||
get:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
description: Retrieve raw odds records using a Market ID
|
|
||||||
parameters:
|
|
||||||
- description: Market ID
|
|
||||||
in: path
|
|
||||||
name: market_id
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: OK
|
|
||||||
schema:
|
|
||||||
items:
|
|
||||||
$ref: '#/definitions/domain.RawOddsByMarketID'
|
|
||||||
type: array
|
|
||||||
"400":
|
|
||||||
description: Bad Request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/response.APIResponse'
|
|
||||||
"500":
|
|
||||||
description: Internal Server Error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/response.APIResponse'
|
|
||||||
summary: Retrieve raw odds by Market ID
|
|
||||||
tags:
|
|
||||||
- prematch
|
|
||||||
/prematch/odds/upcoming/{upcoming_id}:
|
/prematch/odds/upcoming/{upcoming_id}:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
|
@ -1775,6 +1744,42 @@ paths:
|
||||||
summary: Retrieve prematch odds by upcoming ID (FI)
|
summary: Retrieve prematch odds by upcoming ID (FI)
|
||||||
tags:
|
tags:
|
||||||
- prematch
|
- prematch
|
||||||
|
/prematch/odds/upcoming/{upcoming_id}/market/{market_id}:
|
||||||
|
get:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Retrieve raw odds records using a Market ID
|
||||||
|
parameters:
|
||||||
|
- description: Upcoming ID
|
||||||
|
in: path
|
||||||
|
name: upcoming_id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Market ID
|
||||||
|
in: path
|
||||||
|
name: market_id
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/domain.RawOddsByMarketID'
|
||||||
|
type: array
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.APIResponse'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/response.APIResponse'
|
||||||
|
summary: Retrieve raw odds by Market ID
|
||||||
|
tags:
|
||||||
|
- prematch
|
||||||
/search/branch:
|
/search/branch:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,6 @@ type Odd struct {
|
||||||
MarketCategory pgtype.Text `json:"market_category"`
|
MarketCategory pgtype.Text `json:"market_category"`
|
||||||
MarketID pgtype.Text `json:"market_id"`
|
MarketID pgtype.Text `json:"market_id"`
|
||||||
Name pgtype.Text `json:"name"`
|
Name pgtype.Text `json:"name"`
|
||||||
Header pgtype.Text `json:"header"`
|
|
||||||
Handicap pgtype.Text `json:"handicap"`
|
Handicap pgtype.Text `json:"handicap"`
|
||||||
OddsValue pgtype.Float8 `json:"odds_value"`
|
OddsValue pgtype.Float8 `json:"odds_value"`
|
||||||
Section string `json:"section"`
|
Section string `json:"section"`
|
||||||
|
|
|
||||||
|
|
@ -253,15 +253,17 @@ SELECT id,
|
||||||
fetched_at
|
fetched_at
|
||||||
FROM odds
|
FROM odds
|
||||||
WHERE market_id = $1
|
WHERE market_id = $1
|
||||||
|
AND fi = $2
|
||||||
AND is_active = true
|
AND is_active = true
|
||||||
AND source = 'b365api'
|
AND source = 'b365api'
|
||||||
LIMIT $2 OFFSET $3
|
LIMIT $3 OFFSET $4
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetRawOddsByMarketIDParams struct {
|
type GetRawOddsByMarketIDParams struct {
|
||||||
MarketID pgtype.Text
|
MarketID pgtype.Text `json:"market_id"`
|
||||||
Limit int32
|
Fi pgtype.Text `json:"fi"`
|
||||||
Offset int32
|
Limit int32 `json:"limit"`
|
||||||
|
Offset int32 `json:"offset"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetRawOddsByMarketIDRow struct {
|
type GetRawOddsByMarketIDRow struct {
|
||||||
|
|
@ -271,7 +273,12 @@ type GetRawOddsByMarketIDRow struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetRawOddsByMarketID(ctx context.Context, arg GetRawOddsByMarketIDParams) ([]GetRawOddsByMarketIDRow, error) {
|
func (q *Queries) GetRawOddsByMarketID(ctx context.Context, arg GetRawOddsByMarketIDParams) ([]GetRawOddsByMarketIDRow, error) {
|
||||||
rows, err := q.db.Query(ctx, GetRawOddsByMarketID, arg.MarketID, arg.Limit, arg.Offset)
|
rows, err := q.db.Query(ctx, GetRawOddsByMarketID,
|
||||||
|
arg.MarketID,
|
||||||
|
arg.Fi,
|
||||||
|
arg.Limit,
|
||||||
|
arg.Offset,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -324,37 +331,15 @@ VALUES (
|
||||||
$13,
|
$13,
|
||||||
$14,
|
$14,
|
||||||
$15
|
$15
|
||||||
) ON CONFLICT (market_id, name, handicap) DO
|
) ON CONFLICT (event_id, market_id) DO
|
||||||
UPDATE
|
UPDATE
|
||||||
SET odds_value = EXCLUDED.odds_value,
|
SET odds_value = EXCLUDED.odds_value,
|
||||||
raw_odds = EXCLUDED.raw_odds,
|
|
||||||
market_type = EXCLUDED.market_type,
|
|
||||||
market_name = EXCLUDED.market_name,
|
|
||||||
event_id,
|
|
||||||
fi,
|
|
||||||
market_type,
|
|
||||||
market_name,
|
|
||||||
market_category,
|
|
||||||
market_id,
|
|
||||||
name,
|
|
||||||
handicap,
|
|
||||||
odds_value,
|
|
||||||
section,
|
|
||||||
category,
|
|
||||||
raw_odds,
|
|
||||||
is_active,
|
|
||||||
source,
|
|
||||||
fetched_at
|
|
||||||
) VALUES (
|
|
||||||
$1, $2, $3, $4, $5, $6, $7,
|
|
||||||
$8, $9, $10, $11, $12, $13, $14, $15
|
|
||||||
)
|
|
||||||
ON CONFLICT (event_id, market_id) DO UPDATE SET
|
|
||||||
odds_value = EXCLUDED.odds_value,
|
|
||||||
raw_odds = EXCLUDED.raw_odds,
|
raw_odds = EXCLUDED.raw_odds,
|
||||||
market_type = EXCLUDED.market_type,
|
market_type = EXCLUDED.market_type,
|
||||||
market_name = EXCLUDED.market_name,
|
market_name = EXCLUDED.market_name,
|
||||||
market_category = EXCLUDED.market_category,
|
market_category = EXCLUDED.market_category,
|
||||||
|
name = EXCLUDED.name,
|
||||||
|
handicap = EXCLUDED.handicap,
|
||||||
fetched_at = EXCLUDED.fetched_at,
|
fetched_at = EXCLUDED.fetched_at,
|
||||||
is_active = EXCLUDED.is_active,
|
is_active = EXCLUDED.is_active,
|
||||||
source = EXCLUDED.source,
|
source = EXCLUDED.source,
|
||||||
|
|
|
||||||
|
|
@ -176,9 +176,10 @@ func (s *Store) GetALLPrematchOdds(ctx context.Context) ([]domain.Odd, error) {
|
||||||
return domainOdds, nil
|
return domainOdds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) GetRawOddsByMarketID(ctx context.Context, rawOddsID string) (domain.RawOddsByMarketID, error) {
|
func (s *Store) GetRawOddsByMarketID(ctx context.Context, rawOddsID string, upcomingID string) (domain.RawOddsByMarketID, error) {
|
||||||
params := dbgen.GetRawOddsByMarketIDParams{
|
params := dbgen.GetRawOddsByMarketIDParams{
|
||||||
MarketID: pgtype.Text{String: rawOddsID, Valid: true},
|
MarketID: pgtype.Text{String: rawOddsID, Valid: true},
|
||||||
|
Fi: pgtype.Text{String: upcomingID, Valid: true},
|
||||||
Limit: 1,
|
Limit: 1,
|
||||||
Offset: 0,
|
Offset: 0,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,5 @@ type Service interface {
|
||||||
FetchNonLiveOdds(ctx context.Context) error
|
FetchNonLiveOdds(ctx context.Context) error
|
||||||
GetPrematchOdds(ctx context.Context, eventID string) ([]domain.Odd, error)
|
GetPrematchOdds(ctx context.Context, eventID string) ([]domain.Odd, error)
|
||||||
GetALLPrematchOdds(ctx context.Context) ([]domain.Odd, error)
|
GetALLPrematchOdds(ctx context.Context) ([]domain.Odd, error)
|
||||||
GetRawOddsByMarketID(ctx context.Context, marketID string) ([]domain.RawOddsByMarketID, error)
|
GetRawOddsByMarketID(ctx context.Context, marketID string, upcomingID string) ([]domain.RawOddsByMarketID, error)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ func New(token string, store *repository.Store) *ServiceImpl {
|
||||||
return &ServiceImpl{token: token, store: store}
|
return &ServiceImpl{token: token, store: store}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *ServiceImpl) FetchNonLiveOdds(ctx context.Context) error {
|
func (s *ServiceImpl) FetchNonLiveOdds(ctx context.Context) error {
|
||||||
eventIDs, err := s.store.GetAllUpcomingEvents(ctx)
|
eventIDs, err := s.store.GetAllUpcomingEvents(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -112,8 +111,6 @@ type OddsSection struct {
|
||||||
Sp map[string]OddsMarket `json:"sp"`
|
Sp map[string]OddsMarket `json:"sp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func (s *ServiceImpl) GetPrematchOdds(ctx context.Context, eventID string) ([]domain.Odd, error) {
|
func (s *ServiceImpl) GetPrematchOdds(ctx context.Context, eventID string) ([]domain.Odd, error) {
|
||||||
return s.store.GetPrematchOdds(ctx, eventID)
|
return s.store.GetPrematchOdds(ctx, eventID)
|
||||||
}
|
}
|
||||||
|
|
@ -122,8 +119,8 @@ func (s *ServiceImpl) GetALLPrematchOdds(ctx context.Context) ([]domain.Odd, err
|
||||||
return s.store.GetALLPrematchOdds(ctx)
|
return s.store.GetALLPrematchOdds(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServiceImpl) GetRawOddsByMarketID(ctx context.Context, marketID string) ([]domain.RawOddsByMarketID, error) {
|
func (s *ServiceImpl) GetRawOddsByMarketID(ctx context.Context, marketID string, upcomingID string) ([]domain.RawOddsByMarketID, error) {
|
||||||
rows, err := s.store.GetRawOddsByMarketID(ctx, marketID)
|
rows, err := s.store.GetRawOddsByMarketID(ctx, marketID, upcomingID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package httpserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "context"
|
// "context"
|
||||||
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
eventsvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/event"
|
eventsvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/event"
|
||||||
|
|
@ -26,7 +27,6 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
|
||||||
// {
|
// {
|
||||||
// spec: "*/5 * * * * *", // Every 5 seconds
|
// spec: "*/5 * * * * *", // Every 5 seconds
|
||||||
// task: func() {
|
// task: func() {
|
||||||
|
|
@ -36,7 +36,6 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
|
||||||
// {
|
// {
|
||||||
// spec: "*/5 * * * * *", // Every 5 seconds
|
// spec: "*/5 * * * * *", // Every 5 seconds
|
||||||
// task: func() {
|
// task: func() {
|
||||||
|
|
@ -45,12 +44,10 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for _, job := range schedule {
|
for _, job := range schedule {
|
||||||
|
job.task()
|
||||||
if _, err := c.AddFunc(job.spec, job.task); err != nil {
|
if _, err := c.AddFunc(job.spec, job.task); err != nil {
|
||||||
log.Fatalf("Failed to schedule cron job: %v", err)
|
log.Fatalf("Failed to schedule cron job: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ func GetPrematchOdds(logger *slog.Logger, prematchSvc *odds.ServiceImpl) fiber.H
|
||||||
return response.WriteJSON(c, fiber.StatusOK, "Prematch odds retrieved successfully", odds, nil)
|
return response.WriteJSON(c, fiber.StatusOK, "Prematch odds retrieved successfully", odds, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//GetALLPrematchOdds
|
|
||||||
|
// GetALLPrematchOdds
|
||||||
// @Summary Retrieve all prematch odds
|
// @Summary Retrieve all prematch odds
|
||||||
// @Description Retrieve all prematch odds from the database
|
// @Description Retrieve all prematch odds from the database
|
||||||
// @Tags prematch
|
// @Tags prematch
|
||||||
|
|
@ -55,28 +56,35 @@ func GetALLPrematchOdds(logger *slog.Logger, prematchSvc *odds.ServiceImpl) fibe
|
||||||
return response.WriteJSON(c, fiber.StatusOK, "All prematch odds retrieved successfully", odds, nil)
|
return response.WriteJSON(c, fiber.StatusOK, "All prematch odds retrieved successfully", odds, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRawOddsByMarketID
|
// GetRawOddsByMarketID
|
||||||
// @Summary Retrieve raw odds by Market ID
|
// @Summary Retrieve raw odds by Market ID
|
||||||
// @Description Retrieve raw odds records using a Market ID
|
// @Description Retrieve raw odds records using a Market ID
|
||||||
// @Tags prematch
|
// @Tags prematch
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Param upcoming_id path string true "Upcoming ID"
|
||||||
// @Param market_id path string true "Market ID"
|
// @Param market_id path string true "Market ID"
|
||||||
// @Success 200 {array} domain.RawOddsByMarketID
|
// @Success 200 {array} domain.RawOddsByMarketID
|
||||||
// @Failure 400 {object} response.APIResponse
|
// @Failure 400 {object} response.APIResponse
|
||||||
// @Failure 500 {object} response.APIResponse
|
// @Failure 500 {object} response.APIResponse
|
||||||
// @Router /prematch/odds/raw/{market_id} [get]
|
// @Router /prematch/odds/upcoming/{upcoming_id}/market/{market_id} [get]
|
||||||
func GetRawOddsByMarketID(logger *slog.Logger, prematchSvc *odds.ServiceImpl) fiber.Handler {
|
func GetRawOddsByMarketID(logger *slog.Logger, prematchSvc *odds.ServiceImpl) fiber.Handler {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
marketID := c.Params("market_id")
|
marketID := c.Params("market_id")
|
||||||
|
upcomingID := c.Params("upcoming_id")
|
||||||
if marketID == "" {
|
if marketID == "" {
|
||||||
return response.WriteJSON(c, fiber.StatusBadRequest, "Missing market_id", nil, nil)
|
return response.WriteJSON(c, fiber.StatusBadRequest, "Missing market_id", nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
rawOdds, err := prematchSvc.GetRawOddsByMarketID(c.Context(), marketID)
|
if upcomingID == "" {
|
||||||
|
return response.WriteJSON(c, fiber.StatusBadRequest, "Missing upcoming_id", nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
rawOdds, err := prematchSvc.GetRawOddsByMarketID(c.Context(), marketID, upcomingID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("failed to fetch raw odds", "error", err)
|
logger.Error("failed to fetch raw odds", "error", err)
|
||||||
return response.WriteJSON(c, fiber.StatusInternalServerError, "Failed to retrieve raw odds", nil, nil)
|
return response.WriteJSON(c, fiber.StatusInternalServerError, "Failed to retrieve raw odds", err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.WriteJSON(c, fiber.StatusOK, "Raw odds retrieved successfully", rawOdds, nil)
|
return response.WriteJSON(c, fiber.StatusOK, "Raw odds retrieved successfully", rawOdds, nil)
|
||||||
|
|
@ -101,6 +109,7 @@ func GetAllUpcomingEvents(logger *slog.Logger, eventSvc event.Service) fiber.Han
|
||||||
return response.WriteJSON(c, fiber.StatusOK, "All upcoming events retrieved successfully", events, nil)
|
return response.WriteJSON(c, fiber.StatusOK, "All upcoming events retrieved successfully", events, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Retrieve an upcoming by ID
|
// @Summary Retrieve an upcoming by ID
|
||||||
// @Description Retrieve an upcoming event by ID
|
// @Description Retrieve an upcoming event by ID
|
||||||
// @Tags prematch
|
// @Tags prematch
|
||||||
|
|
@ -126,6 +135,7 @@ func GetUpcomingEventByID(logger *slog.Logger, eventSvc event.Service) fiber.Han
|
||||||
return response.WriteJSON(c, fiber.StatusOK, "Upcoming event retrieved successfully", event, nil)
|
return response.WriteJSON(c, fiber.StatusOK, "Upcoming event retrieved successfully", event, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Retrieve prematch odds by upcoming ID (FI)
|
// @Summary Retrieve prematch odds by upcoming ID (FI)
|
||||||
// @Description Retrieve prematch odds by upcoming event ID (FI from Bet365) with optional pagination
|
// @Description Retrieve prematch odds by upcoming event ID (FI from Bet365) with optional pagination
|
||||||
// @Tags prematch
|
// @Tags prematch
|
||||||
|
|
@ -163,4 +173,3 @@ func GetPrematchOddsByUpcomingID(logger *slog.Logger, prematchSvc *odds.ServiceI
|
||||||
return response.WriteJSON(c, fiber.StatusOK, "Prematch odds retrieved successfully", odds, nil)
|
return response.WriteJSON(c, fiber.StatusOK, "Prematch odds retrieved successfully", odds, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ func (a *App) initAppRoutes() {
|
||||||
|
|
||||||
a.fiber.Get("/prematch/odds/:event_id", handlers.GetPrematchOdds(a.logger, a.prematchSvc))
|
a.fiber.Get("/prematch/odds/:event_id", handlers.GetPrematchOdds(a.logger, a.prematchSvc))
|
||||||
a.fiber.Get("/prematch/odds", handlers.GetALLPrematchOdds(a.logger, a.prematchSvc))
|
a.fiber.Get("/prematch/odds", handlers.GetALLPrematchOdds(a.logger, a.prematchSvc))
|
||||||
a.fiber.Get("/prematch/odds/raw/:market_id", handlers.GetRawOddsByMarketID(a.logger, a.prematchSvc))
|
a.fiber.Get("/prematch/odds/upcoming/:upcoming_id/market/:market_id", handlers.GetRawOddsByMarketID(a.logger, a.prematchSvc))
|
||||||
|
|
||||||
a.fiber.Get("/prematch/events/:id", handlers.GetUpcomingEventByID(a.logger, a.eventSvc))
|
a.fiber.Get("/prematch/events/:id", handlers.GetUpcomingEventByID(a.logger, a.eventSvc))
|
||||||
a.fiber.Get("/prematch/events", handlers.GetAllUpcomingEvents(a.logger, a.eventSvc))
|
a.fiber.Get("/prematch/events", handlers.GetAllUpcomingEvents(a.logger, a.eventSvc))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user