Atlas Gaming Fixes

This commit is contained in:
Yared Yemane 2025-10-17 11:30:33 +03:00
parent fc69ca3f52
commit e0e4ff4b64
6 changed files with 44 additions and 28 deletions

View File

@ -52,7 +52,6 @@ func (c *Client) generateHash(body []byte, timestamp string) string {
func (c *Client) post(ctx context.Context, path string, body map[string]any, result any) error { func (c *Client) post(ctx context.Context, path string, body map[string]any, result any) error {
// Add timestamp first // Add timestamp first
timestamp := nowTimestamp() timestamp := nowTimestamp()
body["timestamp"] = timestamp
// Marshal without hash first // Marshal without hash first
tmp, _ := json.Marshal(body) tmp, _ := json.Marshal(body)
@ -61,12 +60,14 @@ func (c *Client) post(ctx context.Context, path string, body map[string]any, res
hash := c.generateHash(tmp, timestamp) hash := c.generateHash(tmp, timestamp)
body["hash"] = hash body["hash"] = hash
body["timestamp"] = timestamp
fmt.Printf("atlasPost: %v \n", body) fmt.Printf("atlasPost: %v \n", body)
// Marshal final body // Marshal final body
data, _ := json.Marshal(body) data, _ := json.Marshal(body)
req, _ := http.NewRequestWithContext(ctx, "POST", c.BaseURL+path, bytes.NewReader(data)) req, _ := http.NewRequestWithContext(ctx, "POST", c.BaseURL+path, bytes.NewReader(data))
req.Header.Set("Content-Type", "text/javascript") req.Header.Set("Content-Type", "application/json")
// Debug // Debug
fmt.Println("Request URL:", c.BaseURL+path) fmt.Println("Request URL:", c.BaseURL+path)

View File

@ -235,7 +235,7 @@ func (h *Handler) GetFixturesWithPreodds(c *fiber.Ctx) error {
} }
// Helper: parse comma-separated string into []int // Helper: parse comma-separated string into []int
func parseIntSlice(input string) []int { func ParseIntSlice(input string) []int {
if input == "" { if input == "" {
return nil return nil
} }
@ -250,7 +250,7 @@ func parseIntSlice(input string) []int {
} }
// Helper: convert []int to []int64 // Helper: convert []int to []int64
func intSliceToInt64Slice(input []int) []int64 { func IntSliceToInt64Slice(input []int) []int64 {
if input == nil { if input == nil {
return nil return nil
} }

View File

@ -3,7 +3,7 @@ package handlers
import ( import (
"context" "context"
"errors" "errors"
"fmt" // "fmt"
"strings" "strings"
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain" "github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
@ -120,13 +120,14 @@ func (h *Handler) GetGamesByProvider(c *fiber.Ctx) error {
// @Failure 502 {object} domain.ErrorResponse // @Failure 502 {object} domain.ErrorResponse
// @Router /api/v1/veli/start-game [post] // @Router /api/v1/veli/start-game [post]
func (h *Handler) StartGame(c *fiber.Ctx) error { func (h *Handler) StartGame(c *fiber.Ctx) error {
userId, ok := c.Locals("user_id").(int64) // userId, ok := c.Locals("user_id").(int64)
if !ok { // fmt.Printf("\n\nVeli Start Game User ID is %v\n\n", userId)
return c.Status(fiber.StatusUnauthorized).JSON(domain.ErrorResponse{ // if !ok {
Error: "missing user id", // return c.Status(fiber.StatusUnauthorized).JSON(domain.ErrorResponse{
Message: "Unauthorized", // Error: "missing user id",
}) // Message: "Unauthorized",
} // })
// }
var req domain.GameStartRequest var req domain.GameStartRequest
if err := c.BodyParser(&req); err != nil { if err := c.BodyParser(&req); err != nil {
@ -139,7 +140,7 @@ func (h *Handler) StartGame(c *fiber.Ctx) error {
// There needs to be a way to generate a sessionID // There needs to be a way to generate a sessionID
// Attach user ID to request // Attach user ID to request
req.PlayerID = fmt.Sprintf("%d", userId) // req.PlayerID = fmt.Sprintf("%d", userId)
// Default brand if not provided // Default brand if not provided
if req.BrandID == "" { if req.BrandID == "" {

View File

@ -264,6 +264,14 @@ func (h *Handler) HandlePlayerInfo(c *fiber.Ctx) error {
} }
func (h *Handler) HandleBet(c *fiber.Ctx) error { func (h *Handler) HandleBet(c *fiber.Ctx) error {
// userID := c.Locals("user_id")
// fmt.Printf("\n\nBet User ID is%v\n\n",userID)
// if userID == "" {
// return c.Status(fiber.StatusBadRequest).JSON(domain.ErrorResponse{
// Message: "Failed to process Bet request",
// Error: "Invalid user identification",
// })
// }
// Read the raw body // Read the raw body
body := c.Body() body := c.Body()
if len(body) == 0 { if len(body) == 0 {
@ -292,6 +300,8 @@ func (h *Handler) HandleBet(c *fiber.Ctx) error {
}) })
} }
// req.PlayerID = fmt.Sprintf("%v", userID)
res, err := h.veliVirtualGameSvc.ProcessBet(c.Context(), req) res, err := h.veliVirtualGameSvc.ProcessBet(c.Context(), req)
if err != nil { if err != nil {
if errors.Is(err, veli.ErrDuplicateTransaction) { if errors.Is(err, veli.ErrDuplicateTransaction) {
@ -316,6 +326,8 @@ func (h *Handler) HandleBet(c *fiber.Ctx) error {
}) })
} }
// req.PlayerID = fmt.Sprintf("%v", userID)
resp, err := h.virtualGameSvc.ProcessBet(c.Context(), &req) resp, err := h.virtualGameSvc.ProcessBet(c.Context(), &req)
if err != nil { if err != nil {
code := fiber.StatusInternalServerError code := fiber.StatusInternalServerError
@ -341,6 +353,8 @@ func (h *Handler) HandleBet(c *fiber.Ctx) error {
}) })
} }
// req.PlayerID = fmt.Sprintf("%v", userID)
resp, err := h.atlasVirtualGameSvc.ProcessBet(c.Context(), req) resp, err := h.atlasVirtualGameSvc.ProcessBet(c.Context(), req)
if err != nil { if err != nil {
// code := fiber.StatusInternalServerError // code := fiber.StatusInternalServerError

View File

@ -284,7 +284,7 @@ func (a *App) initAppRoutes() {
tenant.Get("/events/:id/bets", a.authMiddleware, a.CompanyOnly, h.GetTenantBetsByEventID) tenant.Get("/events/:id/bets", a.authMiddleware, a.CompanyOnly, h.GetTenantBetsByEventID)
//EnetPulse //EnetPulse
groupV1.Get("/odds/pre-match", h.GetPreMatchOdds) // groupV1.Get("/odds/pre-match", h.GetPreMatchOdds)
groupV1.Get("/sports", h.GetAllSports) groupV1.Get("/sports", h.GetAllSports)
groupV1.Get("/tournament_templates", h.GetAllTournamentTemplates) groupV1.Get("/tournament_templates", h.GetAllTournamentTemplates)
groupV1.Get("/tournaments", h.GetAllTournaments) groupV1.Get("/tournaments", h.GetAllTournaments)
@ -400,7 +400,7 @@ func (a *App) initAppRoutes() {
//Veli Virtual Game Routes //Veli Virtual Game Routes
groupV1.Post("/veli/providers", h.GetProviders) groupV1.Post("/veli/providers", h.GetProviders)
groupV1.Post("/veli/games-list", h.GetGamesByProvider) groupV1.Post("/veli/games-list", h.GetGamesByProvider)
groupV1.Post("/veli/start-game", a.authMiddleware, h.StartGame) groupV1.Post("/veli/start-game", h.StartGame)
groupV1.Post("/veli/start-demo-game", h.StartDemoGame) groupV1.Post("/veli/start-demo-game", h.StartDemoGame)
a.fiber.Post("/balance", h.GetBalance) a.fiber.Post("/balance", h.GetBalance)
groupV1.Post("/veli/gaming-activity", a.authMiddleware, h.GetGamingActivity) groupV1.Post("/veli/gaming-activity", a.authMiddleware, h.GetGamingActivity)
@ -408,7 +408,7 @@ func (a *App) initAppRoutes() {
groupV1.Post("/veli/credit-balances", a.authMiddleware, h.GetCreditBalances) groupV1.Post("/veli/credit-balances", a.authMiddleware, h.GetCreditBalances)
//Atlas Virtual Game Routes //Atlas Virtual Game Routes
groupV1.Get("/atlas/games", a.authMiddleware, h.InitAtlasGame) groupV1.Get("/atlas/games", h.GetAtlasVGames)
groupV1.Post("/atlas/init-game", a.authMiddleware, h.InitAtlasGame) groupV1.Post("/atlas/init-game", a.authMiddleware, h.InitAtlasGame)
a.fiber.Post("/account", h.AtlasGetUserDataCallback) a.fiber.Post("/account", h.AtlasGetUserDataCallback)
a.fiber.Post("/betwin", h.HandleAtlasBetWin) a.fiber.Post("/betwin", h.HandleAtlasBetWin)

View File

@ -46,45 +46,45 @@ postgres:
.PHONY: backup .PHONY: backup
backup: backup:
@mkdir -p backup @mkdir -p backup
@docker exec -t fortunebet-backend-postgres-1 pg_dump -U root --data-only --exclude-table=schema_migrations gh | gzip > backup/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz @docker exec -t fortunebet-postgres-1 pg_dump -U root --data-only --exclude-table=schema_migrations gh | gzip > backup/dump_`date +%Y-%m-%d"_"%H_%M_%S`.sql.gz
restore: restore:
@echo "Restoring latest backup..." @echo "Restoring latest backup..."
@latest_file=$$(ls -t backup/dump_*.sql.gz | head -n 1); \ @latest_file=$$(ls -t backup/dump_*.sql.gz | head -n 1); \
echo "Restoring from $$latest_file"; \ echo "Restoring from $$latest_file"; \
gunzip -c $$latest_file | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh gunzip -c $$latest_file | docker exec -i fortunebet-postgres-1 psql -U root -d gh
restore_file: restore_file:
@echo "Restoring latest backup..." @echo "Restoring latest backup..."
gunzip -c $(file) | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh gunzip -c $(file) | docker exec -i fortunebet-postgres-1 psql -U root -d gh
.PHONY: seed_data .PHONY: seed_data
seed_data: seed_data:
@echo "Waiting for PostgreSQL to be ready..." @echo "Waiting for PostgreSQL to be ready..."
@until docker exec fortunebet-backend-postgres-1 pg_isready -U root -d gh; do \ @until docker exec fortunebet-postgres-1 pg_isready -U root -d gh; do \
echo "PostgreSQL is not ready yet..."; \ echo "PostgreSQL is not ready yet..."; \
sleep 1; \ sleep 1; \
done done
@for file in db/data/*.sql; do \ @for file in db/data/*.sql; do \
echo "Seeding $$file..."; \ echo "Seeding $$file..."; \
cat $$file | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh; \ cat $$file | docker exec -i fortunebet-postgres-1 psql -U root -d gh; \
done done
.PHONY: seed_dev_data .PHONY: seed_dev_data
seed_dev_data: seed_dev_data:
@echo "Waiting for PostgreSQL to be ready..." @echo "Waiting for PostgreSQL to be ready..."
@until docker exec fortunebet-backend-postgres-1 pg_isready -U root -d gh; do \ @until docker exec fortunebet-postgres-1 pg_isready -U root -d gh; do \
echo "PostgreSQL is not ready yet..."; \ echo "PostgreSQL is not ready yet..."; \
sleep 1; \ sleep 1; \
done done
cat db/scripts/fix_autoincrement_desync.sql | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh; cat db/scripts/fix_autoincrement_desync.sql | docker exec -i fortunebet-postgres-1 psql -U root -d gh;
@for file in db/dev_data/*.sql; do \ @for file in db/dev_data/*.sql; do \
if [ -f "$$file" ]; then \ if [ -f "$$file" ]; then \
echo "Seeding $$file..."; \ echo "Seeding $$file..."; \
cat $$file | docker exec -i fortunebet-backend-postgres-1 psql -U root -d gh; \ cat $$file | docker exec -i fortunebet-postgres-1 psql -U root -d gh; \
fi \ fi \
done done
postgres_log: postgres_log:
docker logs fortunebet-backend-postgres-1 docker logs fortunebet-postgres-1
.PHONY: swagger .PHONY: swagger
swagger: swagger:
@swag init -g cmd/main.go @swag init -g cmd/main.go
@ -94,7 +94,7 @@ logs:
db-up: | logs db-up: | logs
@mkdir -p logs @mkdir -p logs
@docker compose up -d postgres migrate mongo @docker compose up -d postgres migrate mongo
@docker logs fortunebet-backend-postgres-1 > logs/postgres.log 2>&1 & @docker logs fortunebet-postgres-1 > logs/postgres.log 2>&1 &
.PHONY: db-down .PHONY: db-down
db-down: db-down:
@docker compose down -v @docker compose down -v