test wheels

This commit is contained in:
Aditya Siregar
2025-09-18 12:01:20 +07:00
parent f64fec1fe2
commit be92ec8b23
21 changed files with 420 additions and 85 deletions
+24
View File
@@ -86,3 +86,27 @@ func (r *GameRepository) GetActiveGames(ctx context.Context) ([]entities.Game, e
}
return games, nil
}
func (r *GameRepository) GetActiveSpinGames(ctx context.Context) ([]entities.Game, error) {
var games []entities.Game
err := r.db.WithContext(ctx).
Preload("Prizes").
Where("is_active = ? AND type = ?", true, entities.GameTypeSpin).
Find(&games).Error
if err != nil {
return nil, err
}
return games, nil
}
func (r *GameRepository) GetFerrisWheelGame(ctx context.Context) (*entities.Game, error) {
var game entities.Game
err := r.db.WithContext(ctx).
Preload("Prizes").
Where("is_active = ? AND LOWER(name) LIKE ?", true, "%ferris wheel%").
First(&game).Error
if err != nil {
return nil, err
}
return &game, nil
}
+13
View File
@@ -15,6 +15,7 @@ type OtpRepository interface {
GetOtpSessionByToken(ctx context.Context, token string) (*entities.OtpSession, error)
GetOtpSessionByPhoneAndPurpose(ctx context.Context, phoneNumber string, purpose string) (*entities.OtpSession, error)
GetLastOtpSessionByPhoneAndPurpose(ctx context.Context, phoneNumber string, purpose string) (*entities.OtpSession, error)
GetOtpSessionByRegistrationToken(ctx context.Context, registrationToken string) (*entities.OtpSession, error)
UpdateOtpSession(ctx context.Context, otpSession *entities.OtpSession) error
DeleteOtpSession(ctx context.Context, token string) error
DeleteExpiredOtpSessions(ctx context.Context) error
@@ -73,6 +74,18 @@ func (r *otpRepository) GetLastOtpSessionByPhoneAndPurpose(ctx context.Context,
return &otpSession, nil
}
func (r *otpRepository) GetOtpSessionByRegistrationToken(ctx context.Context, registrationToken string) (*entities.OtpSession, error) {
var otpSession entities.OtpSession
if err := r.db.WithContext(ctx).Where("metadata->>'registration_token' = ? AND purpose = ?",
registrationToken, "registration").First(&otpSession).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, nil // OTP session not found
}
return nil, fmt.Errorf("failed to get OTP session by registration token: %w", err)
}
return &otpSession, nil
}
func (r *otpRepository) UpdateOtpSession(ctx context.Context, otpSession *entities.OtpSession) error {
if err := r.db.WithContext(ctx).Save(otpSession).Error; err != nil {
return fmt.Errorf("failed to update OTP session: %w", err)