Compare commits
1 Commits
d5f94845e8
...
feat/user-
| Author | SHA1 | Date | |
|---|---|---|---|
| 774d5acbd2 |
@@ -9,7 +9,7 @@ import (
|
|||||||
"git.schreifuchs.ch/lou-taylor/accounting/pkg/invoice/report"
|
"git.schreifuchs.ch/lou-taylor/accounting/pkg/invoice/report"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) Generate(creditor model.Entity, deptor *model.Entity, rate float64, repos []Repo, config *Options) (document io.ReadCloser, r report.Report, err error) {
|
func (s *Service) Generate(creditor model.Entity, debtor *model.Entity, rate float64, repos []Repo, config *Options) (document io.ReadCloser, r report.Report, err error) {
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &DefaultOptions
|
config = &DefaultOptions
|
||||||
}
|
}
|
||||||
@@ -32,12 +32,21 @@ func (s *Service) Generate(creditor model.Entity, deptor *model.Entity, rate flo
|
|||||||
is = append(is, iss...)
|
is = append(is, iss...)
|
||||||
}
|
}
|
||||||
|
|
||||||
is = filter(is, config.IssueFilter)
|
{
|
||||||
|
issueURLs := make([]string, 0, len(is))
|
||||||
|
for _, issue := range is {
|
||||||
|
issueURLs = append(issueURLs, issue.HTMLURL)
|
||||||
|
}
|
||||||
|
s.log.Debug("loaded all issues", "issueURLs", issueURLs)
|
||||||
|
}
|
||||||
|
|
||||||
|
is = s.filterIssues(is, config.IssueFilter)
|
||||||
|
|
||||||
issues := issue.FromGiteas(is, config.Mindur)
|
issues := issue.FromGiteas(is, config.Mindur)
|
||||||
r = report.New(
|
r = report.New(
|
||||||
issues,
|
issues,
|
||||||
creditor,
|
creditor,
|
||||||
deptor,
|
debtor,
|
||||||
rate,
|
rate,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -53,12 +62,14 @@ func (s *Service) Generate(creditor model.Entity, deptor *model.Entity, rate flo
|
|||||||
return document, r, err
|
return document, r, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func filter[T any](slice []T, ok func(T) bool) []T {
|
func (s *Service) filterIssues(slice []*gitea.Issue, ok func(*gitea.Issue) bool) []*gitea.Issue {
|
||||||
out := make([]T, 0, len(slice))
|
out := make([]*gitea.Issue, 0, len(slice))
|
||||||
|
|
||||||
for _, item := range slice {
|
for _, issue := range slice {
|
||||||
if ok(item) {
|
if ok(issue) {
|
||||||
out = append(out, item)
|
out = append(out, issue)
|
||||||
|
} else {
|
||||||
|
s.log.Debug("filter out issue", "issueURL", issue.HTMLURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func TestGenerate(t *testing.T) {
|
|||||||
creditor := model.Entity{
|
creditor := model.Entity{
|
||||||
Name: "creditor",
|
Name: "creditor",
|
||||||
}
|
}
|
||||||
deptor := model.Entity{
|
debtor := model.Entity{
|
||||||
Name: "deptor",
|
Name: "deptor",
|
||||||
}
|
}
|
||||||
rate := 100.0
|
rate := 100.0
|
||||||
@@ -140,7 +140,7 @@ pdfGenerator := new(MockPdfGenerator)
|
|||||||
tc.setupMocks(giteaClient, pdfGenerator)
|
tc.setupMocks(giteaClient, pdfGenerator)
|
||||||
|
|
||||||
service := New(slog.Default(), giteaClient, pdfGenerator)
|
service := New(slog.Default(), giteaClient, pdfGenerator)
|
||||||
doc, _, err := service.Generate(creditor, &deptor, rate, repos, tc.config)
|
doc, _, err := service.Generate(creditor, &debtor, rate, repos, tc.config)
|
||||||
|
|
||||||
if tc.expectedError != "" {
|
if tc.expectedError != "" {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -160,3 +160,4 @@ pdfGenerator := new(MockPdfGenerator)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user