2025-09-17 19:30:17 +07:00
|
|
|
package processor
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-18 02:01:50 +07:00
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2025-09-17 19:30:17 +07:00
|
|
|
"apskel-pos-be/internal/models"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type CustomerPointsProcessor struct {
|
2026-09-30 15:31:44 +07:00
|
|
|
walletQuery *WalletQueryProcessor
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
|
2026-10-07 21:31:56 +07:00
|
|
|
func NewCustomerPointsProcessor(walletQuery *WalletQueryProcessor) *CustomerPointsProcessor {
|
2025-09-17 19:30:17 +07:00
|
|
|
return &CustomerPointsProcessor{
|
2026-09-30 15:31:44 +07:00
|
|
|
walletQuery: walletQuery,
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 16:55:27 +07:00
|
|
|
// The endpoints below are the customer app's balance screens. They read the
|
2026-09-30 15:31:44 +07:00
|
|
|
// EnakPoint & EnakCoin wallet; customer_points and customer_tokens are no longer used
|
|
|
|
|
// for balances (docs/prd-point-coin.md §9).
|
2026-09-30 09:15:26 +07:00
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) GetCustomerTotalPointsAPI(ctx context.Context, customerID string) (*models.GetCustomerPointsResponse, error) {
|
2026-09-30 15:31:44 +07:00
|
|
|
id, err := parseWalletCustomerID(customerID)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 15:31:44 +07:00
|
|
|
return nil, err
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2026-09-30 15:31:44 +07:00
|
|
|
data, err := p.walletQuery.LegacyPoints(ctx, id)
|
2025-09-18 02:01:50 +07:00
|
|
|
if err != nil {
|
2026-09-30 15:31:44 +07:00
|
|
|
return nil, fmt.Errorf("failed to get customer points: %w", err)
|
2025-09-18 02:01:50 +07:00
|
|
|
}
|
|
|
|
|
return &models.GetCustomerPointsResponse{
|
|
|
|
|
Status: "SUCCESS",
|
|
|
|
|
Message: "Customer points retrieved successfully.",
|
2026-09-30 15:31:44 +07:00
|
|
|
Data: data,
|
2025-09-17 19:30:17 +07:00
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 02:01:50 +07:00
|
|
|
func (p *CustomerPointsProcessor) GetCustomerWalletAPI(ctx context.Context, customerID string) (*models.GetCustomerWalletResponse, error) {
|
2026-09-30 15:31:44 +07:00
|
|
|
id, err := parseWalletCustomerID(customerID)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 15:31:44 +07:00
|
|
|
return nil, err
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2026-09-30 15:31:44 +07:00
|
|
|
data, err := p.walletQuery.Summary(ctx, id)
|
2025-09-17 19:30:17 +07:00
|
|
|
if err != nil {
|
2026-09-30 15:31:44 +07:00
|
|
|
return nil, fmt.Errorf("failed to get customer wallet: %w", err)
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2025-09-18 02:01:50 +07:00
|
|
|
return &models.GetCustomerWalletResponse{
|
|
|
|
|
Status: "SUCCESS",
|
|
|
|
|
Message: "Customer wallet retrieved successfully.",
|
2026-09-30 15:31:44 +07:00
|
|
|
Data: data,
|
2025-09-18 02:01:50 +07:00
|
|
|
}, nil
|
2025-09-17 19:30:17 +07:00
|
|
|
}
|
2025-09-18 12:01:20 +07:00
|
|
|
|
2026-09-30 15:31:44 +07:00
|
|
|
func (p *CustomerPointsProcessor) GetCustomerWalletTransactionsAPI(ctx context.Context, customerID string, query models.ListCustomerWalletTransactionsQuery) (*models.PaginatedResponse[models.CustomerWalletTransaction], error) {
|
|
|
|
|
id, err := parseWalletCustomerID(customerID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return p.walletQuery.Transactions(ctx, id, query)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseWalletCustomerID(customerID string) (uuid.UUID, error) {
|
|
|
|
|
id, err := uuid.Parse(customerID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return uuid.Nil, fmt.Errorf("%w: invalid customer id", ErrInvalidWalletQuery)
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *CustomerPointsProcessor) GetCustomerWalletExpiringAPI(ctx context.Context, customerID string) (*models.CustomerWalletExpiringList, error) {
|
|
|
|
|
id, err := parseWalletCustomerID(customerID)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return p.walletQuery.Expiring(ctx, id)
|
|
|
|
|
}
|