Files
apskel-pos-backend/internal/service/customer_points_service.go
T
efrilmandClaude Opus 5.5 c988a79d3b refactor(loyalty): remove what is left of tokens
Tokens are EnakCoin and no app uses the token names any more, so their
compatibility layer goes:

- GET /customer/tokens and its handler, service, processor and response
  types.
- total_tokens and tokens_history on GET /customer/wallet; last_updated
  now comes from the most recent row of either currency.
- token_used and tokens_remaining on game and spin responses, and
  sort_by=token_used on the game play list.
- TOKENS as a campaign type and reward type, with the mapping to COINS:
  migration 000092 already renamed the stored values.

The customer_tokens table and its entity stay, as cmd/wallet-migrate still
reads them, and LEGACY_TOKENS stays as the reference of the MIGRATION rows
it wrote. The docs list the removed names and their replacements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 16:55:27 +07:00

87 lines
3.2 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)
GetCustomerWallet(ctx context.Context, customerID string) (*models.GetCustomerWalletResponse, error)
GetCustomerWalletTransactions(ctx context.Context, customerID string, query models.ListCustomerWalletTransactionsQuery) (*models.PaginatedResponse[models.CustomerWalletTransaction], error)
GetCustomerWalletExpiring(ctx context.Context, customerID string) (*models.CustomerWalletExpiringList, 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) 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
}
func (s *customerPointsService) GetCustomerWalletTransactions(ctx context.Context, customerID string, query models.ListCustomerWalletTransactionsQuery) (*models.PaginatedResponse[models.CustomerWalletTransaction], error) {
if customerID == "" {
return nil, fmt.Errorf("customer ID is required")
}
return s.customerPointsProcessor.GetCustomerWalletTransactionsAPI(ctx, customerID, query)
}
func (s *customerPointsService) GetCustomerWalletExpiring(ctx context.Context, customerID string) (*models.CustomerWalletExpiringList, error) {
if customerID == "" {
return nil, fmt.Errorf("customer ID is required")
}
return s.customerPointsProcessor.GetCustomerWalletExpiringAPI(ctx, customerID)
}