provider enable/disable fix
This commit is contained in:
parent
70f33f1fa9
commit
82497ffc64
|
|
@ -44,16 +44,36 @@ func (s *Service) AddProviders(ctx context.Context, req domain.ProviderRequest)
|
||||||
createParams := dbgen.CreateVirtualGameProviderParams{
|
createParams := dbgen.CreateVirtualGameProviderParams{
|
||||||
ProviderID: p.ProviderID,
|
ProviderID: p.ProviderID,
|
||||||
ProviderName: p.ProviderName,
|
ProviderName: p.ProviderName,
|
||||||
LogoDark: pgtype.Text{String: p.LogoForDark, Valid: true},
|
LogoDark: pgtype.Text{String: p.LogoForDark, Valid: p.LogoForDark != ""},
|
||||||
LogoLight: pgtype.Text{String: p.LogoForLight, Valid: true},
|
LogoLight: pgtype.Text{String: p.LogoForLight, Valid: p.LogoForLight != ""},
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := s.repo.CreateVirtualGameProvider(ctx, createParams); err != nil {
|
if _, err := s.repo.CreateVirtualGameProvider(ctx, createParams); err != nil {
|
||||||
// Log error but continue with other providers
|
|
||||||
return nil, fmt.Errorf("failed to add provider %s: %w", p.ProviderID, err)
|
return nil, fmt.Errorf("failed to add provider %s: %w", p.ProviderID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 4. Always add "popok" provider manually
|
||||||
|
popokParams := dbgen.CreateVirtualGameProviderParams{
|
||||||
|
ProviderID: "popok",
|
||||||
|
ProviderName: "Popok Gaming",
|
||||||
|
LogoDark: pgtype.Text{String: "/static/logos/popok-dark.png", Valid: true}, // adjust as needed
|
||||||
|
LogoLight: pgtype.Text{String: "/static/logos/popok-light.png", Valid: true}, // adjust as needed
|
||||||
|
Enabled: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := s.repo.CreateVirtualGameProvider(ctx, popokParams); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to add popok provider: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optionally also append it to the response for consistency
|
||||||
|
// res.Items = append(res.Items, domain.VirtualGameProvider{
|
||||||
|
// ProviderID: uuid.New().String(),
|
||||||
|
// ProviderName: "Popok Gaming",
|
||||||
|
// LogoForDark: "/static/logos/popok-dark.png",
|
||||||
|
// LogoForLight: "/static/logos/popok-light.png",
|
||||||
|
// })
|
||||||
|
|
||||||
return &res, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,39 +62,102 @@ func (s *Service) GetProviders(ctx context.Context, req domain.ProviderRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) GetGames(ctx context.Context, req domain.GameListRequest) ([]domain.GameEntity, error) {
|
func (s *Service) GetGames(ctx context.Context, req domain.GameListRequest) ([]domain.GameEntity, error) {
|
||||||
sigParams := map[string]any{
|
// 1. Check if provider is enabled in DB
|
||||||
"brandId": req.BrandID, "providerId": req.ProviderID,
|
provider, err := s.repo.GetVirtualGameProviderByID(ctx, req.ProviderID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to check provider %s: %w", req.ProviderID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !provider.Enabled {
|
||||||
|
// Provider exists but is disabled → return empty list (or error if you prefer)
|
||||||
|
return nil, fmt.Errorf("provider %s is disabled", req.ProviderID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Prepare signature params
|
||||||
|
sigParams := map[string]any{
|
||||||
|
"brandId": req.BrandID,
|
||||||
|
"providerId": req.ProviderID,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Call external API
|
||||||
var res struct {
|
var res struct {
|
||||||
Items []domain.GameEntity `json:"items"`
|
Items []domain.GameEntity `json:"items"`
|
||||||
}
|
}
|
||||||
err := s.client.post(ctx, "/game-lists/public/games", req, sigParams, &res)
|
if err := s.client.post(ctx, "/game-lists/public/games", req, sigParams, &res); err != nil {
|
||||||
return res.Items, err
|
return nil, fmt.Errorf("failed to fetch games for provider %s: %w", req.ProviderID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) StartGame(ctx context.Context, req domain.GameStartRequest) (*domain.GameStartResponse, error) {
|
func (s *Service) StartGame(ctx context.Context, req domain.GameStartRequest) (*domain.GameStartResponse, error) {
|
||||||
sigParams := map[string]any{
|
// 1. Check if provider is enabled in DB
|
||||||
"sessionId": req.SessionID, "providerId": req.ProviderID,
|
provider, err := s.repo.GetVirtualGameProviderByID(ctx, req.ProviderID)
|
||||||
"gameId": req.GameID, "language": req.Language, "playerId": req.PlayerID,
|
if err != nil {
|
||||||
"currency": req.Currency, "deviceType": req.DeviceType, "country": "US",
|
return nil, fmt.Errorf("failed to check provider %s: %w", req.ProviderID, err)
|
||||||
"ip": req.IP, "brandId": req.BrandID,
|
|
||||||
}
|
|
||||||
var res domain.GameStartResponse
|
|
||||||
err := s.client.post(ctx, "/unified-api/public/start-game", req, sigParams, &res)
|
|
||||||
return &res, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) StartDemoGame(ctx context.Context, req domain.DemoGameRequest) (*domain.GameStartResponse, error) {
|
if !provider.Enabled {
|
||||||
|
// Provider exists but is disabled → return error
|
||||||
|
return nil, fmt.Errorf("provider %s is disabled", req.ProviderID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Prepare signature params
|
||||||
sigParams := map[string]any{
|
sigParams := map[string]any{
|
||||||
"providerId": req.ProviderID, "gameId": req.GameID,
|
"sessionId": req.SessionID,
|
||||||
"language": req.Language, "deviceType": req.DeviceType,
|
"providerId": req.ProviderID,
|
||||||
"ip": req.IP, "brandId": req.BrandID,
|
"gameId": req.GameID,
|
||||||
|
"language": req.Language,
|
||||||
|
"playerId": req.PlayerID,
|
||||||
|
"currency": req.Currency,
|
||||||
|
"deviceType": req.DeviceType,
|
||||||
|
"country": "US",
|
||||||
|
"ip": req.IP,
|
||||||
|
"brandId": req.BrandID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. Call external API
|
||||||
var res domain.GameStartResponse
|
var res domain.GameStartResponse
|
||||||
err := s.client.post(ctx, "/unified-api/public/start-demo-game", req, sigParams, &res)
|
if err := s.client.post(ctx, "/unified-api/public/start-game", req, sigParams, &res); err != nil {
|
||||||
return &res, err
|
return nil, fmt.Errorf("failed to start game with provider %s: %w", req.ProviderID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return &res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (s *Service) StartDemoGame(ctx context.Context, req domain.DemoGameRequest) (*domain.GameStartResponse, error) {
|
||||||
|
// 1. Check if provider is enabled in DB
|
||||||
|
provider, err := s.repo.GetVirtualGameProviderByID(ctx, req.ProviderID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to check provider %s: %w", req.ProviderID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !provider.Enabled {
|
||||||
|
// Provider exists but is disabled → return error
|
||||||
|
return nil, fmt.Errorf("provider %s is disabled", req.ProviderID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Prepare signature params
|
||||||
|
sigParams := map[string]any{
|
||||||
|
"providerId": req.ProviderID,
|
||||||
|
"gameId": req.GameID,
|
||||||
|
"language": req.Language,
|
||||||
|
"deviceType": req.DeviceType,
|
||||||
|
"ip": req.IP,
|
||||||
|
"brandId": req.BrandID,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Call external API
|
||||||
|
var res domain.GameStartResponse
|
||||||
|
if err := s.client.post(ctx, "/unified-api/public/start-demo-game", req, sigParams, &res); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to start demo game with provider %s: %w", req.ProviderID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Service) GetBalance(ctx context.Context, req domain.BalanceRequest) (*domain.BalanceResponse, error) {
|
func (s *Service) GetBalance(ctx context.Context, req domain.BalanceRequest) (*domain.BalanceResponse, error) {
|
||||||
// Retrieve player's real balance from wallet Service
|
// Retrieve player's real balance from wallet Service
|
||||||
playerIDInt64, err := strconv.ParseInt(req.PlayerID, 10, 64)
|
playerIDInt64, err := strconv.ParseInt(req.PlayerID, 10, 64)
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ func (h *Handler) CreateBetWithFastCode(c *fiber.Ctx) error {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create bet:"+err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, "Failed to create bet:"+err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
wallet, err := h.walletSvc.GetCustomerWallet(c.Context(), bet.UserID)
|
wallet, _ := h.walletSvc.GetCustomerWallet(c.Context(), bet.UserID)
|
||||||
|
|
||||||
// amount added for fast code owner can be fetched from settings in db
|
// amount added for fast code owner can be fetched from settings in db
|
||||||
settingList, err := h.settingSvc.GetSettingList(c.Context())
|
settingList, err := h.settingSvc.GetSettingList(c.Context())
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/virtualGame/veli"
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/services/virtualGame/veli"
|
||||||
|
|
@ -70,6 +71,7 @@ func (h *Handler) GetGamesByProvider(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default brand if not provided
|
||||||
if req.BrandID == "" {
|
if req.BrandID == "" {
|
||||||
req.BrandID = h.Cfg.VeliGames.BrandID
|
req.BrandID = h.Cfg.VeliGames.BrandID
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +79,16 @@ func (h *Handler) GetGamesByProvider(c *fiber.Ctx) error {
|
||||||
res, err := h.veliVirtualGameSvc.GetGames(context.Background(), req)
|
res, err := h.veliVirtualGameSvc.GetGames(context.Background(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("GetGames error:", err)
|
log.Println("GetGames error:", err)
|
||||||
|
|
||||||
|
// Handle provider disabled case specifically
|
||||||
|
if strings.Contains(err.Error(), "is disabled") {
|
||||||
|
return c.Status(fiber.StatusForbidden).JSON(domain.ErrorResponse{
|
||||||
|
Message: "Provider is disabled",
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for other errors
|
||||||
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
||||||
Message: "Failed to retrieve games",
|
Message: "Failed to retrieve games",
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
|
|
@ -91,6 +103,7 @@ func (h *Handler) GetGamesByProvider(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// StartGame godoc
|
// StartGame godoc
|
||||||
// @Summary Start a real game session
|
// @Summary Start a real game session
|
||||||
// @Description Starts a real VeliGames session with the given player and game info
|
// @Description Starts a real VeliGames session with the given player and game info
|
||||||
|
|
@ -119,7 +132,10 @@ func (h *Handler) StartGame(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Attach user ID to request
|
||||||
req.PlayerID = fmt.Sprintf("%d", userId)
|
req.PlayerID = fmt.Sprintf("%d", userId)
|
||||||
|
|
||||||
|
// Default brand if not provided
|
||||||
if req.BrandID == "" {
|
if req.BrandID == "" {
|
||||||
req.BrandID = h.Cfg.VeliGames.BrandID
|
req.BrandID = h.Cfg.VeliGames.BrandID
|
||||||
}
|
}
|
||||||
|
|
@ -127,6 +143,16 @@ func (h *Handler) StartGame(c *fiber.Ctx) error {
|
||||||
res, err := h.veliVirtualGameSvc.StartGame(context.Background(), req)
|
res, err := h.veliVirtualGameSvc.StartGame(context.Background(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("StartGame error:", err)
|
log.Println("StartGame error:", err)
|
||||||
|
|
||||||
|
// Handle provider disabled case specifically
|
||||||
|
if strings.Contains(err.Error(), "is disabled") {
|
||||||
|
return c.Status(fiber.StatusForbidden).JSON(domain.ErrorResponse{
|
||||||
|
Message: "Provider is disabled",
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for other errors
|
||||||
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
||||||
Message: "Failed to start game",
|
Message: "Failed to start game",
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
|
|
@ -141,6 +167,7 @@ func (h *Handler) StartGame(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// StartDemoGame godoc
|
// StartDemoGame godoc
|
||||||
// @Summary Start a demo game session
|
// @Summary Start a demo game session
|
||||||
// @Description Starts a demo session of the specified game (must support demo mode)
|
// @Description Starts a demo session of the specified game (must support demo mode)
|
||||||
|
|
@ -161,6 +188,7 @@ func (h *Handler) StartDemoGame(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default brand if not provided
|
||||||
if req.BrandID == "" {
|
if req.BrandID == "" {
|
||||||
req.BrandID = h.Cfg.VeliGames.BrandID
|
req.BrandID = h.Cfg.VeliGames.BrandID
|
||||||
}
|
}
|
||||||
|
|
@ -168,6 +196,16 @@ func (h *Handler) StartDemoGame(c *fiber.Ctx) error {
|
||||||
res, err := h.veliVirtualGameSvc.StartDemoGame(context.Background(), req)
|
res, err := h.veliVirtualGameSvc.StartDemoGame(context.Background(), req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("StartDemoGame error:", err)
|
log.Println("StartDemoGame error:", err)
|
||||||
|
|
||||||
|
// Handle provider disabled case specifically
|
||||||
|
if strings.Contains(err.Error(), "is disabled") {
|
||||||
|
return c.Status(fiber.StatusForbidden).JSON(domain.ErrorResponse{
|
||||||
|
Message: "Provider is disabled",
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for other errors
|
||||||
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
return c.Status(fiber.StatusBadGateway).JSON(domain.ErrorResponse{
|
||||||
Message: "Failed to start demo game",
|
Message: "Failed to start demo game",
|
||||||
Error: err.Error(),
|
Error: err.Error(),
|
||||||
|
|
@ -182,6 +220,7 @@ func (h *Handler) StartDemoGame(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (h *Handler) GetBalance(c *fiber.Ctx) error {
|
func (h *Handler) GetBalance(c *fiber.Ctx) error {
|
||||||
var req domain.BalanceRequest
|
var req domain.BalanceRequest
|
||||||
if err := c.BodyParser(&req); err != nil {
|
if err := c.BodyParser(&req); err != nil {
|
||||||
|
|
|
||||||
BIN
static/logos/popok-dark.png
Normal file
BIN
static/logos/popok-dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.4 KiB |
BIN
static/logos/popok-light.png
Normal file
BIN
static/logos/popok-light.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.0 KiB |
Loading…
Reference in New Issue
Block a user