mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzo-fi/go-libs/v5/pkg/storage/bun/paginate"
|
|
"github.com/hanzo-fi/payments/pkg/domain/models"
|
|
"github.com/hanzo-fi/payments/internal/storage"
|
|
)
|
|
|
|
func (s *Service) PaymentInitiationAdjustmentsList(ctx context.Context, id models.PaymentInitiationID, query storage.ListPaymentInitiationAdjustmentsQuery) (*paginate.Cursor[models.PaymentInitiationAdjustment], error) {
|
|
cursor, err := s.storage.PaymentInitiationAdjustmentsList(ctx, id, query)
|
|
return cursor, newStorageError(err, "cannot list payment initiation adjustments")
|
|
}
|
|
|
|
func (s *Service) PaymentInitiationAdjustmentsListAll(ctx context.Context, id models.PaymentInitiationID) ([]models.PaymentInitiationAdjustment, error) {
|
|
q := storage.NewListPaymentInitiationAdjustmentsQuery(
|
|
paginate.NewPaginatedQueryOptions(storage.PaymentInitiationAdjustmentsQuery{}).
|
|
WithPageSize(50),
|
|
)
|
|
var next string
|
|
adjustments := []models.PaymentInitiationAdjustment{}
|
|
for {
|
|
if next != "" {
|
|
err := paginate.UnmarshalCursor(next, &q)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
cursor, err := s.storage.PaymentInitiationAdjustmentsList(ctx, id, q)
|
|
if err != nil {
|
|
return nil, newStorageError(err, "cannot list payment initiation adjustments")
|
|
}
|
|
|
|
adjustments = append(adjustments, cursor.Data...)
|
|
|
|
if cursor.Next == "" {
|
|
break
|
|
}
|
|
}
|
|
|
|
return adjustments, nil
|
|
}
|