mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-30 01:25:30 +00:00
provided models for the whole document
This commit is contained in:
44
providers/categories.go
Normal file
44
providers/categories.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type CategoryProvider struct {
|
||||
XMLProvider[Categories]
|
||||
}
|
||||
|
||||
type Categories struct {
|
||||
XMLName xml.Name `xml:"kategorien"`
|
||||
Category []Category `xml:"kategorie"`
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
ID string `xml:"id,attr"`
|
||||
Names []string `xml:"name"`
|
||||
SortName string `xml:"sortiername"`
|
||||
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