-
Notifications
You must be signed in to change notification settings - Fork 0
/
invoices_checker.go
43 lines (33 loc) · 963 Bytes
/
invoices_checker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package units
import (
"context"
"github.com/devdammit/shekel/cmd/unit/internal/entities"
port "github.com/devdammit/shekel/cmd/unit/internal/ports/use-cases"
)
type InvoicesRepository interface {
GetAllByPeriodID(periodID uint64) ([]entities.Invoice, error)
}
type InvoicesChecker struct {
repo InvoicesRepository
}
func NewInvoicesChecker(repo InvoicesRepository) *InvoicesChecker {
return &InvoicesChecker{repo: repo}
}
func (u *InvoicesChecker) GetName() string {
return "invoices_extender"
}
func (u *InvoicesChecker) Handle(ctx context.Context, request *Request, payload *Payload) (*Payload, error) {
if payload == nil || payload.ActivePeriod == nil {
return nil, nil
}
invoices, err := u.repo.GetAllByPeriodID(payload.ActivePeriod.ID)
if err != nil {
return nil, err
}
for _, invoice := range invoices {
if invoice.Status == entities.InvoiceStatusPending {
return nil, port.ErrorInvoiceNotPaid
}
}
return payload, nil
}