small fix

This commit is contained in:
Samuel Tariku 2025-04-14 00:09:04 +03:00
parent 98cb576873
commit 788119f718
5 changed files with 107 additions and 106 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ coverage
.env .env
tmp tmp
build build
*.log

View File

@ -176,7 +176,6 @@ CREATE TABLE IF NOT EXISTS branch_cashiers (
branch_id BIGINT NOT NULL, branch_id BIGINT NOT NULL,
UNIQUE(user_id, branch_id) UNIQUE(user_id, branch_id)
); );
CREATE TABLE events ( CREATE TABLE events (
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
sport_id TEXT, sport_id TEXT,
@ -217,24 +216,14 @@ CREATE TABLE odds (
fetched_at TIMESTAMP DEFAULT now(), fetched_at TIMESTAMP DEFAULT now(),
source TEXT DEFAULT 'b365api', source TEXT DEFAULT 'b365api',
is_active BOOLEAN DEFAULT true, is_active BOOLEAN DEFAULT true,
UNIQUE (market_id, name, handicap),
UNIQUE (event_id, market_id, name, handicap) UNIQUE (event_id, market_id, name, handicap)
); );
ALTER TABLE refresh_tokens ALTER TABLE refresh_tokens
ADD CONSTRAINT fk_refresh_tokens_users FOREIGN KEY (user_id) REFERENCES users(id); ADD CONSTRAINT fk_refresh_tokens_users FOREIGN KEY (user_id) REFERENCES users(id);
ALTER TABLE bets ALTER TABLE bets
ADD CONSTRAINT fk_bets_users FOREIGN KEY (user_id) REFERENCES users(id), ADD CONSTRAINT fk_bets_users FOREIGN KEY (user_id) REFERENCES users(id),
ADD CONSTRAINT fk_bets_branches FOREIGN KEY (branch_id) REFERENCES branches(id); ADD CONSTRAINT fk_bets_branches FOREIGN KEY (branch_id) REFERENCES branches(id);
ALTER TABLE bet_outcomes
ADD CONSTRAINT fk_bet_outcomes_bets FOREIGN KEY (bet_id) REFERENCES bets(id),
ADD CONSTRAINT fk_bet_outcomes_events FOREIGN KEY (event_id) REFERENCES supported_operations(id),
ADD CONSTRAINT fk_bet_outcomes_odds FOREIGN KEY (odd_id) REFERENCES supported_operations(id);
ALTER TABLE ticket_outcomes
ADD CONSTRAINT fk_ticket_outcomes_tickets FOREIGN KEY (ticket_id) REFERENCES tickets(id),
ADD CONSTRAINT fk_ticket_outcomes_events FOREIGN KEY (event_id) REFERENCES supported_operations(id),
ADD CONSTRAINT fk_ticket_outcomes_odds FOREIGN KEY (odd_id) REFERENCES supported_operations(id);
ALTER TABLE wallets ALTER TABLE wallets
ADD CONSTRAINT fk_wallets_users FOREIGN KEY (user_id) REFERENCES users(id); ADD CONSTRAINT fk_wallets_users FOREIGN KEY (user_id) REFERENCES users(id);
ALTER TABLE customer_wallets ALTER TABLE customer_wallets
@ -341,5 +330,4 @@ VALUES (
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP CURRENT_TIMESTAMP
); );
--------------------------------------------------Bet365 Data Fetching + Event Managment------------------------------------------------ --------------------------------------------------Bet365 Data Fetching + Event Managment------------------------------------------------

View File

@ -148,6 +148,7 @@ 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"`

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,
@ -179,12 +178,12 @@ 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'
AND o.is_active = true AND o.is_active = true
AND o.source = 'b365api' AND o.source = 'b365api'
LIMIT $2 OFFSET $3 LIMIT $2 OFFSET $3
` `
@ -249,15 +248,13 @@ func (q *Queries) GetPrematchOddsByUpcomingID(ctx context.Context, arg GetPremat
} }
const GetRawOddsByID = `-- name: GetRawOddsByID :one const GetRawOddsByID = `-- name: GetRawOddsByID :one
SELECT SELECT id,
id,
raw_odds, raw_odds,
fetched_at fetched_at
FROM odds FROM odds
WHERE WHERE raw_odds @> $1::jsonb
raw_odds @> $1::jsonb AND AND is_active = true
is_active = true AND AND source = 'b365api'
source = 'b365api'
LIMIT 1 LIMIT 1
` `
@ -276,35 +273,49 @@ func (q *Queries) GetRawOddsByID(ctx context.Context, dollar_1 []byte) (GetRawOd
const InsertNonLiveOdd = `-- name: InsertNonLiveOdd :exec const InsertNonLiveOdd = `-- name: InsertNonLiveOdd :exec
INSERT INTO odds ( INSERT INTO odds (
event_id, event_id,
fi, fi,
market_type, market_type,
market_name, market_name,
market_category, market_category,
market_id, market_id,
name, name,
handicap, handicap,
odds_value, odds_value,
section, section,
category, category,
raw_odds, raw_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 (market_id, name, handicap) DO UPDATE SET $3,
odds_value = EXCLUDED.odds_value, $4,
raw_odds = EXCLUDED.raw_odds, $5,
market_type = EXCLUDED.market_type, $6,
market_name = EXCLUDED.market_name, $7,
$8,
$9,
$10,
$11,
$12,
$13,
$14,
$15
) ON CONFLICT (market_id, name, handicap) DO
UPDATE
SET odds_value = EXCLUDED.odds_value,
raw_odds = EXCLUDED.raw_odds,
market_type = EXCLUDED.market_type,
market_name = EXCLUDED.market_name,
market_category = EXCLUDED.market_category, market_category = EXCLUDED.market_category,
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
` `
type InsertNonLiveOddParams struct { type InsertNonLiveOddParams struct {

View File

@ -1,25 +1,24 @@
package httpserver package httpserver
import ( import (
"fmt" "fmt"
"log/slog" "log/slog"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/authentication" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/authentication"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/event"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/odds"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/bet" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/bet"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/branch" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/branch"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/event"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/odds"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/ticket" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/ticket"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/transaction" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/transaction"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/user" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/user"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/wallet" "github.com/SamuelTariku/FortuneBet-Backend/internal/services/wallet"
jwtutil "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/jwt" jwtutil "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/jwt"
customvalidator "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/validator" customvalidator "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/validator"
notificationservice "github.com/SamuelTariku/FortuneBet-Backend/internal/services/notfication" notificationservice "github.com/SamuelTariku/FortuneBet-Backend/internal/services/notfication"
"github.com/bytedance/sonic" "github.com/bytedance/sonic"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors" "github.com/gofiber/fiber/v2/middleware/cors"
) )
@ -38,46 +37,47 @@ type App struct {
validator *customvalidator.CustomValidator validator *customvalidator.CustomValidator
JwtConfig jwtutil.JwtConfig JwtConfig jwtutil.JwtConfig
Logger *slog.Logger Logger *slog.Logger
prematchSvc *odds.ServiceImpl prematchSvc *odds.ServiceImpl
eventSvc event.Service eventSvc event.Service
} }
func NewApp( func NewApp(
port int, validator *customvalidator.CustomValidator, port int, validator *customvalidator.CustomValidator,
authSvc *authentication.Service, authSvc *authentication.Service,
logger *slog.Logger, logger *slog.Logger,
JwtConfig jwtutil.JwtConfig, JwtConfig jwtutil.JwtConfig,
userSvc *user.Service, userSvc *user.Service,
ticketSvc *ticket.Service, ticketSvc *ticket.Service,
betSvc *bet.Service, betSvc *bet.Service,
walletSvc *wallet.Service, walletSvc *wallet.Service,
transactionSvc *transaction.Service, transactionSvc *transaction.Service,
branchSvc *branch.Service, branchSvc *branch.Service,
notidicationStore notificationservice.NotificationStore, notidicationStore notificationservice.NotificationStore,
prematchSvc *odds.ServiceImpl, prematchSvc *odds.ServiceImpl,
eventSvc event.Service, eventSvc event.Service,
) *App { ) *App {
app := fiber.New(fiber.Config{ app := fiber.New(fiber.Config{
CaseSensitive: true, CaseSensitive: true,
DisableHeaderNormalizing: true, DisableHeaderNormalizing: true,
JSONEncoder: sonic.Marshal, JSONEncoder: sonic.Marshal,
JSONDecoder: sonic.Unmarshal, JSONDecoder: sonic.Unmarshal,
}) })
app.Use(cors.New(cors.Config{ app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:5173", // Specify your frontend's origin AllowOrigins: "http://localhost:8000", // Specify your frontend's origin
AllowMethods: "GET,POST,PUT,DELETE", // Specify the allowed HTTP methods AllowMethods: "GET,POST,PUT,DELETE,OPTIONS", // Specify the allowed HTTP methods
AllowHeaders: "Content-Type,Authorization", // Specify the allowed headers AllowHeaders: "Content-Type,Authorization,platform", // Specify the allowed headers
AllowCredentials: true,
})) }))
s := &App{ s := &App{
fiber: app, fiber: app,
port: port, port: port,
authSvc: authSvc, authSvc: authSvc,
validator: validator, validator: validator,
logger: logger, logger: logger,
JwtConfig: JwtConfig, JwtConfig: JwtConfig,
userSvc: userSvc, userSvc: userSvc,
ticketSvc: ticketSvc, ticketSvc: ticketSvc,
betSvc: betSvc, betSvc: betSvc,
walletSvc: walletSvc, walletSvc: walletSvc,
@ -85,15 +85,15 @@ func NewApp(
branchSvc: branchSvc, branchSvc: branchSvc,
NotidicationStore: notidicationStore, NotidicationStore: notidicationStore,
Logger: logger, Logger: logger,
prematchSvc: prematchSvc, prematchSvc: prematchSvc,
eventSvc: eventSvc, eventSvc: eventSvc,
} }
s.initAppRoutes() s.initAppRoutes()
return s return s
} }
func (a *App) Run() error { func (a *App) Run() error {
return a.fiber.Listen(fmt.Sprintf(":%d", a.port)) return a.fiber.Listen(fmt.Sprintf(":%d", a.port))
} }