Files
apskel-pos-backend/internal/processor/customer_points_processor.go
T

81 lines
2.4 KiB
Go
Raw Normal View History

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 {
walletQuery *WalletQueryProcessor
2025-09-17 19:30:17 +07:00
}
func NewCustomerPointsProcessor(walletQuery *WalletQueryProcessor) *CustomerPointsProcessor {
2025-09-17 19:30:17 +07:00
return &CustomerPointsProcessor{
walletQuery: walletQuery,
2025-09-17 19:30:17 +07:00
}
}
// The endpoints below are the customer app's balance screens. They read the
// EnakPoint & EnakCoin wallet; customer_points and customer_tokens are no longer used
// for balances (docs/prd-point-coin.md §9).
2025-09-18 02:01:50 +07:00
func (p *CustomerPointsProcessor) GetCustomerTotalPointsAPI(ctx context.Context, customerID string) (*models.GetCustomerPointsResponse, error) {
id, err := parseWalletCustomerID(customerID)
2025-09-17 19:30:17 +07:00
if err != nil {
return nil, err
2025-09-17 19:30:17 +07:00
}
data, err := p.walletQuery.LegacyPoints(ctx, id)
2025-09-18 02:01:50 +07:00
if err != nil {
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.",
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) {
id, err := parseWalletCustomerID(customerID)
2025-09-17 19:30:17 +07:00
if err != nil {
return nil, err
2025-09-17 19:30:17 +07:00
}
data, err := p.walletQuery.Summary(ctx, id)
2025-09-17 19:30:17 +07:00
if err != nil {
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.",
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
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)
}