mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-29 09:05:30 +00:00
restructured viewmodels, better serialization
This commit is contained in:
45
providers/xmlprovider/categories.go
Normal file
45
providers/xmlprovider/categories.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package xmlprovider
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CategoryProvider struct {
|
||||
XMLProvider[Categories]
|
||||
}
|
||||
|
||||
type Categories struct {
|
||||
XMLName xml.Name `xml:"kategorien"`
|
||||
Category []Category `xml:"kategorie"`
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
XMLName xml.Name `xml:"kategorie"`
|
||||
Names []string `xml:"name"`
|
||||
SortName string `xml:"sortiername"`
|
||||
Identifier
|
||||
AnnotationNote
|
||||
}
|
||||
|
||||
func (c Categories) Append(data Categories) Categories {
|
||||
c.Category = append(c.Category, data.Category...)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Categories) String() string {
|
||||
var res []string
|
||||
for _, category := range c.Category {
|
||||
res = append(res, category.String())
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Categories: %v", res)
|
||||
}
|
||||
|
||||
func (c *Category) String() string {
|
||||
return fmt.Sprintf("ID: %s\nNames: %v\nSortName: %s\nAnnotations: %v\nNotes: %v\n", c.ID, c.Names, c.SortName, c.Annotations, c.Notes)
|
||||
}
|
||||
|
||||
func NewCategoryProvider(paths []string) *CategoryProvider {
|
||||
return &CategoryProvider{XMLProvider: XMLProvider[Categories]{paths: paths}}
|
||||
}
|
||||
Reference in New Issue
Block a user