mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 17:15:31 +00:00
view changes
This commit is contained in:
44
viewmodels/issuevm.go
Normal file
44
viewmodels/issuevm.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user