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
tmp
build
*.log

View File

@ -176,7 +176,6 @@ CREATE TABLE IF NOT EXISTS branch_cashiers (
branch_id BIGINT NOT NULL,
UNIQUE(user_id, branch_id)
);
CREATE TABLE events (
id TEXT PRIMARY KEY,
sport_id TEXT,
@ -217,24 +216,14 @@ CREATE TABLE odds (
fetched_at TIMESTAMP DEFAULT now(),
source TEXT DEFAULT 'b365api',
is_active BOOLEAN DEFAULT true,
UNIQUE (market_id, name, handicap),
UNIQUE (event_id, market_id, name, handicap)
);
ALTER TABLE refresh_tokens
ADD CONSTRAINT fk_refresh_tokens_users FOREIGN KEY (user_id) REFERENCES users(id);
ALTER TABLE bets
ADD CONSTRAINT fk_bets_users FOREIGN KEY (user_id) REFERENCES users(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
ADD CONSTRAINT fk_wallets_users FOREIGN KEY (user_id) REFERENCES users(id);
ALTER TABLE customer_wallets
@ -341,5 +330,4 @@ VALUES (
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP
);
--------------------------------------------------Bet365 Data Fetching + Event Managment------------------------------------------------

View File

@ -148,6 +148,7 @@ type Odd struct {
MarketCategory pgtype.Text `json:"market_category"`
MarketID pgtype.Text `json:"market_id"`
Name pgtype.Text `json:"name"`
Header pgtype.Text `json:"header"`
Handicap pgtype.Text `json:"handicap"`
OddsValue pgtype.Float8 `json:"odds_value"`
Section string `json:"section"`

View File

@ -12,8 +12,7 @@ import (
)
const GetALLPrematchOdds = `-- name: GetALLPrematchOdds :many
SELECT
event_id,
SELECT event_id,
fi,
market_type,
market_name,
@ -29,7 +28,8 @@ SELECT
source,
is_active
FROM odds
WHERE is_active = true AND source = 'b365api'
WHERE is_active = true
AND source = 'b365api'
`
type GetALLPrematchOddsRow struct {
@ -87,8 +87,7 @@ func (q *Queries) GetALLPrematchOdds(ctx context.Context) ([]GetALLPrematchOddsR
}
const GetPrematchOdds = `-- name: GetPrematchOdds :many
SELECT
event_id,
SELECT event_id,
fi,
market_type,
market_name,
@ -104,7 +103,8 @@ SELECT
source,
is_active
FROM odds
WHERE is_active = true AND source = 'b365api'
WHERE is_active = true
AND source = 'b365api'
`
type GetPrematchOddsRow struct {
@ -162,8 +162,7 @@ func (q *Queries) GetPrematchOdds(ctx context.Context) ([]GetPrematchOddsRow, er
}
const GetPrematchOddsByUpcomingID = `-- name: GetPrematchOddsByUpcomingID :many
SELECT
o.event_id,
SELECT o.event_id,
o.fi,
o.market_type,
o.market_name,
@ -249,15 +248,13 @@ func (q *Queries) GetPrematchOddsByUpcomingID(ctx context.Context, arg GetPremat
}
const GetRawOddsByID = `-- name: GetRawOddsByID :one
SELECT
id,
SELECT id,
raw_odds,
fetched_at
FROM odds
WHERE
raw_odds @> $1::jsonb AND
is_active = true AND
source = 'b365api'
WHERE raw_odds @> $1::jsonb
AND is_active = true
AND source = 'b365api'
LIMIT 1
`
@ -291,12 +288,26 @@ INSERT INTO odds (
is_active,
source,
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
odds_value = EXCLUDED.odds_value,
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 odds_value = EXCLUDED.odds_value,
raw_odds = EXCLUDED.raw_odds,
market_type = EXCLUDED.market_type,
market_name = EXCLUDED.market_name,

View File

@ -5,10 +5,10 @@ import (
"log/slog"
"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/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/transaction"
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/user"
@ -16,7 +16,6 @@ import (
jwtutil "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/jwt"
customvalidator "github.com/SamuelTariku/FortuneBet-Backend/internal/web_server/validator"
notificationservice "github.com/SamuelTariku/FortuneBet-Backend/internal/services/notfication"
"github.com/bytedance/sonic"
"github.com/gofiber/fiber/v2"
@ -65,9 +64,10 @@ func NewApp(
})
app.Use(cors.New(cors.Config{
AllowOrigins: "http://localhost:5173", // Specify your frontend's origin
AllowMethods: "GET,POST,PUT,DELETE", // Specify the allowed HTTP methods
AllowHeaders: "Content-Type,Authorization", // Specify the allowed headers
AllowOrigins: "http://localhost:8000", // Specify your frontend's origin
AllowMethods: "GET,POST,PUT,DELETE,OPTIONS", // Specify the allowed HTTP methods
AllowHeaders: "Content-Type,Authorization,platform", // Specify the allowed headers
AllowCredentials: true,
}))
s := &App{