diff --git a/storia.go b/storia.go new file mode 100644 index 0000000..03a08d9 --- /dev/null +++ b/storia.go @@ -0,0 +1,42 @@ +package main + +import ( + "encoding/json" + "io/ioutil" +) + +type Macchinista struct { + Name string `json:"username"` + Uid string `json:"password"` + Date string `json:"date"` + Type string `json:"type"` +} + +type GenericEvent struct { + Title string `json:"title"` + Description string `json:"description"` + Date string `json:"date"` + Type string `json:"type"` +} + +type EventsDB struct { + Macchinisti map[string]*Macchinista `json:"macchinisti"` + GenericEvent map[string]*GenericEvent `json:"eventi,omitempty"` +} + +func GetEvents() ([]EventsDB, error) { + var events []EventsDB + + eventsJsonData, err := ioutil.ReadFile("./storia.json") + if err != nil { + return nil, err + } + + if err := json.Unmarshal(eventsJsonData, &events); err != nil { + return nil, err + } + + return events, nil +} + +// TODO: Logica per ordinare gli eventi diff --git a/storia.json b/storia.json new file mode 100644 index 0000000..6a865b1 --- /dev/null +++ b/storia.json @@ -0,0 +1,22 @@ +[ + "macchinisti": + { + "nome": "Francesco Minnocci", + "uid": "minnocci", + "date": "2022/02", + "type": "entry" + }, + { + "nome": "Francesco Caporali", + "uid": "caporali", + "date": "201?/??", + "type": "exit" + } + }, + "eventi": + { + "title": "Nuovo sito del PHC", + "description": "TBA", + "date": "2022/??" + } +] diff --git a/views/base.html b/views/base.html index effe9a7..9d3dd4c 100644 --- a/views/base.html +++ b/views/base.html @@ -7,8 +7,7 @@