Parselog & Issue start

This commit is contained in:
Simon Martens
2024-11-22 15:45:16 +01:00
parent bc244fbad4
commit 3e4cafb5ee
14 changed files with 417 additions and 130 deletions

View File

@@ -2,6 +2,7 @@ package viewmodels
import (
"strconv"
"strings"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
@@ -24,30 +25,19 @@ func NewSingleIssueView(y string, No string, lib *xmlprovider.Library) (*SingleI
}
sivm := SingleIssueViewModel{IssueViewModel: *ivm}
logging.Info(strconv.Itoa(len(lib.Pieces.All())) + "pieces in library")
logging.Info(strconv.Itoa(len(lib.Pieces.Everything())) + "pieces in library")
lookfor := y + "-" + No
lib.Pieces.Items.Range(func(key, value interface{}) bool {
a := value.(xmlprovider.Piece)
for _, r := range a.IssueRefs {
if r.Datum == y && r.Nr == No {
p, err := NewPieceView(a)
if err != nil {
logging.ObjErr(&a, err)
continue
}
sivm.Pieces = append(sivm.Pieces, p)
}
}
for _, r := range a.AdditionalRef {
if r.Datum == y && r.Nr == No {
p, err := NewPieceView(a)
if err != nil {
logging.ObjErr(&a, err)
continue
}
sivm.Additionals = append(sivm.Additionals, p)
k := key.(string)
if strings.HasPrefix(k, lookfor) {
a := value.(xmlprovider.Piece)
p, err := NewPieceView(a)
if err != nil {
logging.ObjErr(&a, err)
return true
}
sivm.Pieces = append(sivm.Pieces, p)
}
return true
})

View File

@@ -23,18 +23,19 @@ func YearView(year string, lib *xmlprovider.Library) (*YearViewModel, error) {
last := ""
lib.Issues.Items.Range(func(key, value interface{}) bool {
issue := value.(xmlprovider.Issue)
if len(issue.Datum.When) < 4 {
k := key.(string)
if len(k) < 4 {
return true
}
date := issue.Datum.When[0:4]
date := k[0:4]
if date != last {
res.PushAvailable(date)
last = date
}
if date == year {
issue := value.(xmlprovider.Issue)
res.PushIssue(issue)
}
return true