Merge branch 'auth' into integrate

This commit is contained in:
Samuel Tariku 2025-04-14 19:49:45 +03:00
commit ff393858d9
12 changed files with 653 additions and 567 deletions

View File

@ -15,24 +15,38 @@ INSERT INTO odds (
is_active, is_active,
source, source,
fetched_at fetched_at
) VALUES (
$1, $2, $3, $4, $5, $6, $7,
$8, $9, $10, $11, $12, $13, $14, $15
) )
ON CONFLICT (market_id, name, handicap) DO UPDATE SET VALUES (
odds_value = EXCLUDED.odds_value, $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,
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,
@ -48,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,
@ -68,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: GetRawOddsByID :one -- name: GetRawOddsByMarketID :many
SELECT SELECT id,
id,
raw_odds, raw_odds,
fetched_at fetched_at
FROM odds FROM odds
WHERE WHERE market_id = $1
raw_odds @> $1::jsonb AND AND fi = $2
is_active = true AND AND is_active = true
source = 'b365api' AND source = 'b365api'
LIMIT 1; 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,

View File

@ -1398,50 +1398,6 @@ const docTemplate = `{
} }
} }
}, },
"/prematch/odds/raw/{raw_odds_id}": {
"get": {
"description": "Retrieve raw odds by raw odds ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"prematch"
],
"summary": "Retrieve raw odds by ID",
"parameters": [
{
"type": "string",
"description": "Raw Odds ID",
"name": "raw_odds_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.RawOddsByID"
}
},
"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",
@ -1501,6 +1457,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",
@ -2748,12 +2758,9 @@ const docTemplate = `{
"BANK" "BANK"
] ]
}, },
"domain.RawOddsByID": { "domain.RawOddsByMarketID": {
"type": "object", "type": "object",
"properties": { "properties": {
"event_id": {
"type": "string"
},
"fetched_at": { "fetched_at": {
"type": "string" "type": "string"
}, },

View File

@ -1390,50 +1390,6 @@
} }
} }
}, },
"/prematch/odds/raw/{raw_odds_id}": {
"get": {
"description": "Retrieve raw odds by raw odds ID",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"prematch"
],
"summary": "Retrieve raw odds by ID",
"parameters": [
{
"type": "string",
"description": "Raw Odds ID",
"name": "raw_odds_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/domain.RawOddsByID"
}
},
"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",
@ -1493,6 +1449,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",
@ -2740,12 +2750,9 @@
"BANK" "BANK"
] ]
}, },
"domain.RawOddsByID": { "domain.RawOddsByMarketID": {
"type": "object", "type": "object",
"properties": { "properties": {
"event_id": {
"type": "string"
},
"fetched_at": { "fetched_at": {
"type": "string" "type": "string"
}, },

View File

@ -93,10 +93,8 @@ definitions:
- TELEBIRR_TRANSACTION - TELEBIRR_TRANSACTION
- ARIFPAY_TRANSACTION - ARIFPAY_TRANSACTION
- BANK - BANK
domain.RawOddsByID: domain.RawOddsByMarketID:
properties: properties:
event_id:
type: string
fetched_at: fetched_at:
type: string type: string
id: id:
@ -1829,35 +1827,6 @@ paths:
summary: Retrieve prematch odds for an event summary: Retrieve prematch odds for an event
tags: tags:
- prematch - prematch
/prematch/odds/raw/{raw_odds_id}:
get:
consumes:
- application/json
description: Retrieve raw odds by raw odds ID
parameters:
- description: Raw Odds ID
in: path
name: raw_odds_id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/domain.RawOddsByID'
"400":
description: Bad Request
schema:
$ref: '#/definitions/response.APIResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/response.APIResponse'
summary: Retrieve raw odds by ID
tags:
- prematch
/prematch/odds/upcoming/{upcoming_id}: /prematch/odds/upcoming/{upcoming_id}:
get: get:
consumes: consumes:
@ -1898,6 +1867,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:

View File

@ -12,8 +12,7 @@ import (
) )
const GetALLPrematchOdds = `-- name: GetALLPrematchOdds :many const GetALLPrematchOdds = `-- name: GetALLPrematchOdds :many
SELECT SELECT event_id,
event_id,
fi, fi,
market_type, market_type,
market_name, market_name,
@ -29,7 +28,8 @@ 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'
` `
type GetALLPrematchOddsRow struct { type GetALLPrematchOddsRow struct {
@ -87,8 +87,7 @@ func (q *Queries) GetALLPrematchOdds(ctx context.Context) ([]GetALLPrematchOddsR
} }
const GetPrematchOdds = `-- name: GetPrematchOdds :many const GetPrematchOdds = `-- name: GetPrematchOdds :many
SELECT SELECT event_id,
event_id,
fi, fi,
market_type, market_type,
market_name, market_name,
@ -104,7 +103,8 @@ 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'
` `
type GetPrematchOddsRow struct { type GetPrematchOddsRow struct {
@ -162,8 +162,7 @@ func (q *Queries) GetPrematchOdds(ctx context.Context) ([]GetPrematchOddsRow, er
} }
const GetPrematchOddsByUpcomingID = `-- name: GetPrematchOddsByUpcomingID :many const GetPrematchOddsByUpcomingID = `-- 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,
@ -248,30 +247,54 @@ func (q *Queries) GetPrematchOddsByUpcomingID(ctx context.Context, arg GetPremat
return items, nil return items, nil
} }
const GetRawOddsByID = `-- name: GetRawOddsByID :one const GetRawOddsByMarketID = `-- name: GetRawOddsByMarketID :many
SELECT SELECT id,
id,
raw_odds, raw_odds,
fetched_at fetched_at
FROM odds FROM odds
WHERE WHERE market_id = $1
raw_odds @> $1::jsonb AND AND fi = $2
is_active = true AND AND is_active = true
source = 'b365api' AND source = 'b365api'
LIMIT 1 LIMIT $3 OFFSET $4
` `
type GetRawOddsByIDRow struct { type GetRawOddsByMarketIDParams struct {
MarketID pgtype.Text `json:"market_id"`
Fi pgtype.Text `json:"fi"`
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
type GetRawOddsByMarketIDRow struct {
ID int32 `json:"id"` ID int32 `json:"id"`
RawOdds []byte `json:"raw_odds"` RawOdds []byte `json:"raw_odds"`
FetchedAt pgtype.Timestamp `json:"fetched_at"` FetchedAt pgtype.Timestamp `json:"fetched_at"`
} }
func (q *Queries) GetRawOddsByID(ctx context.Context, dollar_1 []byte) (GetRawOddsByIDRow, error) { func (q *Queries) GetRawOddsByMarketID(ctx context.Context, arg GetRawOddsByMarketIDParams) ([]GetRawOddsByMarketIDRow, error) {
row := q.db.QueryRow(ctx, GetRawOddsByID, dollar_1) rows, err := q.db.Query(ctx, GetRawOddsByMarketID,
var i GetRawOddsByIDRow arg.MarketID,
err := row.Scan(&i.ID, &i.RawOdds, &i.FetchedAt) arg.Fi,
return i, err arg.Limit,
arg.Offset,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetRawOddsByMarketIDRow
for rows.Next() {
var i GetRawOddsByMarketIDRow
if err := rows.Scan(&i.ID, &i.RawOdds, &i.FetchedAt); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
} }
const InsertNonLiveOdd = `-- name: InsertNonLiveOdd :exec const InsertNonLiveOdd = `-- name: InsertNonLiveOdd :exec
@ -291,16 +314,32 @@ INSERT INTO odds (
is_active, is_active,
source, source,
fetched_at fetched_at
) VALUES (
$1, $2, $3, $4, $5, $6, $7,
$8, $9, $10, $11, $12, $13, $14, $15
) )
ON CONFLICT (market_id, name, handicap) DO UPDATE SET VALUES (
odds_value = EXCLUDED.odds_value, $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,

View File

@ -38,9 +38,8 @@ type Odd struct {
Source string `json:"source"` Source string `json:"source"`
IsActive bool `json:"is_active"` IsActive bool `json:"is_active"`
} }
type RawOddsByID struct { type RawOddsByMarketID struct {
ID int64 `json:"id"` ID int64 `json:"id"`
EventID string `json:"event_id"`
RawOdds []RawMessage `json:"raw_odds"` RawOdds []RawMessage `json:"raw_odds"`
FetchedAt time.Time `json:"fetched_at"` FetchedAt time.Time `json:"fetched_at"`
} }

View File

@ -3,6 +3,7 @@ package repository
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"os" "os"
"strconv" "strconv"
"time" "time"
@ -175,21 +176,32 @@ func (s *Store) GetALLPrematchOdds(ctx context.Context) ([]domain.Odd, error) {
return domainOdds, nil return domainOdds, nil
} }
func (s *Store) GetRawOddsByID(ctx context.Context, rawOddsID string) (domain.RawOddsByID, error) { func (s *Store) GetRawOddsByMarketID(ctx context.Context, rawOddsID string, upcomingID string) (domain.RawOddsByMarketID, error) {
jsonFilter := `[{"id":"` + rawOddsID + `"}]` params := dbgen.GetRawOddsByMarketIDParams{
MarketID: pgtype.Text{String: rawOddsID, Valid: true},
odd, err := s.queries.GetRawOddsByID(ctx, []byte(jsonFilter)) Fi: pgtype.Text{String: upcomingID, Valid: true},
if err != nil { Limit: 1,
return domain.RawOddsByID{}, err Offset: 0,
} }
rows, err := s.queries.GetRawOddsByMarketID(ctx, params)
if err != nil {
return domain.RawOddsByMarketID{}, err
}
if len(rows) == 0 {
return domain.RawOddsByMarketID{}, fmt.Errorf("no raw odds found for market_id: %s", rawOddsID)
}
row := rows[0]
var rawOdds []json.RawMessage var rawOdds []json.RawMessage
if err := json.Unmarshal(odd.RawOdds, &rawOdds); err != nil { if err := json.Unmarshal(row.RawOdds, &rawOdds); err != nil {
return domain.RawOddsByID{}, err return domain.RawOddsByMarketID{}, err
} }
return domain.RawOddsByID{ return domain.RawOddsByMarketID{
ID: int64(odd.ID), ID: int64(row.ID),
RawOdds: func() []domain.RawMessage { RawOdds: func() []domain.RawMessage {
converted := make([]domain.RawMessage, len(rawOdds)) converted := make([]domain.RawMessage, len(rawOdds))
for i, r := range rawOdds { for i, r := range rawOdds {
@ -197,19 +209,17 @@ func (s *Store) GetRawOddsByID(ctx context.Context, rawOddsID string) (domain.Ra
} }
return converted return converted
}(), }(),
FetchedAt: odd.FetchedAt.Time, FetchedAt: row.FetchedAt.Time,
}, nil }, nil
} }
func (s *Store) GetPrematchOddsByUpcomingID(ctx context.Context, upcomingID string, limit, offset int32) ([]domain.Odd, error) { func (s *Store) GetPrematchOddsByUpcomingID(ctx context.Context, upcomingID string, limit, offset int32) ([]domain.Odd, error) {
// Prepare query parameters
params := dbgen.GetPrematchOddsByUpcomingIDParams{ params := dbgen.GetPrematchOddsByUpcomingIDParams{
ID: upcomingID, ID: upcomingID,
Limit: limit, Limit: limit,
Offset: offset, Offset: offset,
} }
// Execute the query
odds, err := s.queries.GetPrematchOddsByUpcomingID(ctx, params) odds, err := s.queries.GetPrematchOddsByUpcomingID(ctx, params)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -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)
GetRawOddsByID(ctx context.Context, rawOddsID string) ([]domain.RawOddsByID, error) GetRawOddsByMarketID(ctx context.Context, marketID string, upcomingID string) ([]domain.RawOddsByMarketID, error)
} }

View File

@ -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,13 +119,15 @@ func (s *ServiceImpl) GetALLPrematchOdds(ctx context.Context) ([]domain.Odd, err
return s.store.GetALLPrematchOdds(ctx) return s.store.GetALLPrematchOdds(ctx)
} }
func (s *ServiceImpl) GetRawOddsByID(ctx context.Context, rawOddsID string) ([]domain.RawOddsByID, error) { func (s *ServiceImpl) GetRawOddsByMarketID(ctx context.Context, marketID string, upcomingID string) ([]domain.RawOddsByMarketID, error) {
rawOdds, err := s.store.GetRawOddsByID(ctx, rawOddsID) rows, err := s.store.GetRawOddsByMarketID(ctx, marketID, upcomingID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return []domain.RawOddsByID{rawOdds}, nil
return []domain.RawOddsByMarketID{rows}, nil
} }
func (s *ServiceImpl) GetPrematchOddsByUpcomingID(ctx context.Context, upcomingID string, limit, offset int32) ([]domain.Odd, error) { func (s *ServiceImpl) GetPrematchOddsByUpcomingID(ctx context.Context, upcomingID string, limit, offset int32) ([]domain.Odd, error) {
return s.store.GetPrematchOddsByUpcomingID(ctx, upcomingID, limit, offset) return s.store.GetPrematchOddsByUpcomingID(ctx, upcomingID, limit, offset)
} }

View File

@ -1,6 +1,8 @@
package httpserver package httpserver
import ( import (
// "context"
"log" "log"
eventsvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/event" eventsvc "github.com/SamuelTariku/FortuneBet-Backend/internal/services/event"
@ -35,7 +37,7 @@ func StartDataFetchingCrons(eventService eventsvc.Service, oddsService oddssvc.S
// }, // },
// { // {
// spec: "*/30 * * * * *", // Every 30 seconds // spec: "*/5 * * * * *", // Every 5 seconds
// task: func() { // task: func() {
// if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil { // if err := oddsService.FetchNonLiveOdds(context.Background()); err != nil {
// log.Printf("FetchNonLiveOdds error: %v", err) // log.Printf("FetchNonLiveOdds error: %v", err)

View File

@ -36,6 +36,7 @@ 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
@ -55,27 +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)
} }
} }
// GetRawOddsByID
// @Summary Retrieve raw odds by ID // GetRawOddsByMarketID
// @Description Retrieve raw odds by raw odds ID // @Summary Retrieve raw odds by Market ID
// @Description Retrieve raw odds records using a Market ID
// @Tags prematch // @Tags prematch
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param raw_odds_id path string true "Raw Odds ID" // @Param upcoming_id path string true "Upcoming ID"
// @Success 200 {object} domain.RawOddsByID // @Param market_id path string true "Market ID"
// @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/{raw_odds_id} [get] // @Router /prematch/odds/upcoming/{upcoming_id}/market/{market_id} [get]
func GetRawOddsByID(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 {
rawOddsID := c.Params("raw_odds_id") marketID := c.Params("market_id")
if rawOddsID == "" { upcomingID := c.Params("upcoming_id")
return response.WriteJSON(c, fiber.StatusBadRequest, "Missing raw_odds_id", nil, nil) if marketID == "" {
return response.WriteJSON(c, fiber.StatusBadRequest, "Missing market_id", nil, nil)
} }
rawOdds, err := prematchSvc.GetRawOddsByID(c.Context(), rawOddsID) 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 {
return response.WriteJSON(c, fiber.StatusInternalServerError, "Failed to retrieve raw odds", nil, nil) logger.Error("failed to fetch raw odds", "error", err)
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)
@ -100,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
@ -125,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
@ -162,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)
} }
} }

View File

@ -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/:raw_odds_id", handlers.GetRawOddsByID(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))