view changes

This commit is contained in:
Simon Martens
2024-11-22 23:47:36 +01:00
parent 3e4cafb5ee
commit 7a6edbf668
11 changed files with 185 additions and 88 deletions

44
viewmodels/issuevm.go Normal file
View File

@@ -0,0 +1,44 @@
package viewmodels
import (
"errors"
"time"
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
)
const TLAYOUT = "2006-01-02"
type IssueViewModel struct {
xmlprovider.Issue
Day int
Month int
Year int
}
func IssueView(y string, No string, lib *xmlprovider.Library) (*IssueViewModel, error) {
issue := lib.Issues.Item(y + "-" + No)
if issue == nil {
return nil, errors.New("Issue not found")
}
return FromIssue(*issue)
}
func FromIssue(i xmlprovider.Issue) (*IssueViewModel, error) {
t, err := time.Parse(TLAYOUT, i.Datum.When)
if err != nil {
return nil, err
}
ivm := IssueViewModel{
Issue: i,
Day: t.Day(),
Month: int(t.Month()),
Year: t.Year(),
}
return &ivm, nil
}