130 lines
4.1 KiB
Go
130 lines
4.1 KiB
Go
package distribution
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
var ErrDependencyUnavailable = errors.New("distribution dependency unavailable")
|
|
|
|
type Service struct{ repo *Repository }
|
|
|
|
func NewService(repo *Repository) *Service { return &Service{repo: repo} }
|
|
|
|
func (s *Service) available() error {
|
|
if s == nil || s.repo == nil {
|
|
return ErrDependencyUnavailable
|
|
}
|
|
return nil
|
|
}
|
|
func (s *Service) ListSites(ctx context.Context) ([]SiteDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.ListSites(ctx)
|
|
}
|
|
func (s *Service) FindSite(ctx context.Context, id uint64) (*SiteDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.FindSite(ctx, id)
|
|
}
|
|
func (s *Service) CreateSite(ctx context.Context, req CreateSiteRequest) (*SiteDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.CreateSite(ctx, req)
|
|
}
|
|
func (s *Service) UpdateSite(ctx context.Context, id uint64, req UpdateSiteRequest) (*SiteDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.UpdateSite(ctx, id, req)
|
|
}
|
|
func (s *Service) ListRules(ctx context.Context, siteID *uint64, mode string) ([]RuleDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.ListRules(ctx, siteID, mode)
|
|
}
|
|
func (s *Service) CreateRule(ctx context.Context, adminID uint64, req CreateRuleRequest) (*RuleDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.CreateRule(ctx, adminID, req)
|
|
}
|
|
func (s *Service) UpdateRuleStatus(ctx context.Context, id uint64, status string) (*RuleDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.UpdateRuleStatus(ctx, id, status)
|
|
}
|
|
|
|
func (s *Service) ListOrders(ctx context.Context, query DistributionOrderListQuery) (*DistributionOrderPage, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.ListOrders(ctx, query)
|
|
}
|
|
func (s *Service) FindOrder(ctx context.Context, id uint64) (*DistributionOrderDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.FindOrder(ctx, id)
|
|
}
|
|
func (s *Service) ListAccountDisplays(ctx context.Context, siteID uint64, status string) ([]AccountDisplayDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.ListAccountDisplays(ctx, siteID, status)
|
|
}
|
|
func (s *Service) UpdateAccountDisplay(ctx context.Context, id uint64, status string) (*AccountDisplayDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.UpdateAccountDisplay(ctx, id, status)
|
|
}
|
|
func (s *Service) ListPaymentChannels(ctx context.Context, siteID uint64) ([]PaymentChannelDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.ListPaymentChannels(ctx, siteID)
|
|
}
|
|
func (s *Service) BindPaymentChannel(ctx context.Context, siteID uint64, req BindPaymentChannelRequest) (*PaymentChannelDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.BindPaymentChannel(ctx, siteID, req)
|
|
}
|
|
func (s *Service) UnbindPaymentChannel(ctx context.Context, id uint64) error {
|
|
if err := s.available(); err != nil {
|
|
return err
|
|
}
|
|
return s.repo.UnbindPaymentChannel(ctx, id)
|
|
}
|
|
func (s *Service) ListSettlementBatches(ctx context.Context, siteID uint64) ([]SettlementBatchDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.ListSettlementBatches(ctx, siteID)
|
|
}
|
|
func (s *Service) CreateSettlementBatch(ctx context.Context, adminID uint64, req CreateSettlementBatchRequest) (*SettlementBatchDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.CreateSettlementBatch(ctx, adminID, req)
|
|
}
|
|
func (s *Service) MarkSettlementBatch(ctx context.Context, id uint64) (*SettlementBatchDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.MarkSettlementBatch(ctx, id)
|
|
}
|
|
|
|
func (s *Service) CreateFinancialSnapshot(ctx context.Context, orderID uint64, req CreateFinancialSnapshotRequest) (*DistributionOrderDTO, error) {
|
|
if err := s.available(); err != nil {
|
|
return nil, err
|
|
}
|
|
return s.repo.CreateFinancialSnapshot(ctx, orderID, req)
|
|
}
|