apskel-pos-backend/internal/service/customer_points_service.go
Aditya Siregar be92ec8b23 test wheels
2025-09-18 12:01:20 +07:00

85 lines
2.7 KiB
Go

package service
import (
"context"
"fmt"
"apskel-pos-be/internal/models"
"apskel-pos-be/internal/processor"
)
type CustomerPointsService interface {
GetCustomerPoints(ctx context.Context, customerID string) (*models.GetCustomerPointsResponse, error)
GetCustomerTokens(ctx context.Context, customerID string) (*models.GetCustomerTokensResponse, error)
GetCustomerWallet(ctx context.Context, customerID string) (*models.GetCustomerWalletResponse, error)
GetCustomerGames(ctx context.Context) (*models.GetCustomerGamesResponse, error)
GetFerrisWheelGame(ctx context.Context) (*models.GetFerrisWheelGameResponse, error)
}
type customerPointsService struct {
customerPointsProcessor *processor.CustomerPointsProcessor
}
func NewCustomerPointsService(customerPointsProcessor *processor.CustomerPointsProcessor) CustomerPointsService {
return &customerPointsService{
customerPointsProcessor: customerPointsProcessor,
}
}
func (s *customerPointsService) GetCustomerPoints(ctx context.Context, customerID string) (*models.GetCustomerPointsResponse, error) {
if customerID == "" {
return nil, fmt.Errorf("customer ID is required")
}
response, err := s.customerPointsProcessor.GetCustomerTotalPointsAPI(ctx, customerID)
if err != nil {
return nil, fmt.Errorf("failed to get customer points: %w", err)
}
return response, nil
}
func (s *customerPointsService) GetCustomerTokens(ctx context.Context, customerID string) (*models.GetCustomerTokensResponse, error) {
if customerID == "" {
return nil, fmt.Errorf("customer ID is required")
}
response, err := s.customerPointsProcessor.GetCustomerTotalTokensAPI(ctx, customerID)
if err != nil {
return nil, fmt.Errorf("failed to get customer tokens: %w", err)
}
return response, nil
}
func (s *customerPointsService) GetCustomerWallet(ctx context.Context, customerID string) (*models.GetCustomerWalletResponse, error) {
if customerID == "" {
return nil, fmt.Errorf("customer ID is required")
}
response, err := s.customerPointsProcessor.GetCustomerWalletAPI(ctx, customerID)
if err != nil {
return nil, fmt.Errorf("failed to get customer wallet: %w", err)
}
return response, nil
}
func (s *customerPointsService) GetCustomerGames(ctx context.Context) (*models.GetCustomerGamesResponse, error) {
response, err := s.customerPointsProcessor.GetCustomerGamesAPI(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get customer games: %w", err)
}
return response, nil
}
func (s *customerPointsService) GetFerrisWheelGame(ctx context.Context) (*models.GetFerrisWheelGameResponse, error) {
response, err := s.customerPointsProcessor.GetFerrisWheelGameAPI(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get Ferris Wheel game: %w", err)
}
return response, nil
}