72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
package orchestration
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
|
)
|
|
|
|
func (s *Service) AddFavoriteGame(ctx context.Context, userID, gameID int64, providerID string) error {
|
|
return s.repo.AddFavoriteGame(ctx, userID, gameID, providerID)
|
|
}
|
|
|
|
func (s *Service) RemoveFavoriteGame(ctx context.Context, userID, gameID int64, providerID string) error {
|
|
return s.repo.RemoveFavoriteGame(ctx, userID, gameID, providerID)
|
|
}
|
|
|
|
func (s *Service) ListFavoriteGames(
|
|
ctx context.Context,
|
|
userID int64,
|
|
providerID *string,
|
|
limit, offset int32,
|
|
) ([]domain.UnifiedGame, error) {
|
|
|
|
// Fetch favorite games directly from repository
|
|
games, err := s.repo.ListFavoriteGames(ctx, userID, providerID, limit, offset)
|
|
if err != nil {
|
|
// s.logger.Error("Failed to list favorite games", "userID", userID, "error", err)
|
|
return nil, err
|
|
}
|
|
|
|
// If no favorites, return empty list
|
|
if len(games) == 0 {
|
|
return []domain.UnifiedGame{}, nil
|
|
}
|
|
|
|
favorites := make([]domain.UnifiedGame, 0, len(games))
|
|
|
|
for _, g := range games {
|
|
var rtpPtr *float64
|
|
if g.Rtp.Valid {
|
|
if f, err := g.Rtp.Float64Value(); err == nil {
|
|
rtpPtr = new(float64)
|
|
*rtpPtr = f.Float64
|
|
}
|
|
}
|
|
|
|
bets := make([]float64, len(g.Bets))
|
|
for i, b := range g.Bets {
|
|
bets[i] = float64(b.Exp)
|
|
}
|
|
|
|
favorites = append(favorites, domain.UnifiedGame{
|
|
GameID: g.GameID, // assuming g.GameID is string
|
|
ProviderID: g.ProviderID, // provider id
|
|
Provider: g.ProviderID, // you can map a full name if needed
|
|
Name: g.Name,
|
|
Category: g.Category.String, // nullable
|
|
DeviceType: g.DeviceType.String, // nullable
|
|
Volatility: g.Volatility.String, // nullable
|
|
RTP: rtpPtr,
|
|
HasDemo: g.HasDemo.Bool,
|
|
HasFreeBets: g.HasFreeBets.Bool,
|
|
Bets: bets,
|
|
Thumbnail: g.Thumbnail.String,
|
|
Status: int(g.Status.Int32),
|
|
// DemoURL: g..String,
|
|
})
|
|
}
|
|
|
|
return favorites, nil
|
|
}
|