feat: add universities and restaurants
This commit is contained in:
35
model/external/stwbremen/restaurant.go
vendored
Normal file
35
model/external/stwbremen/restaurant.go
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
package stwbremen
|
||||
|
||||
type RestaurantList struct {
|
||||
Items []string `json:"items"`
|
||||
}
|
||||
|
||||
type Restaurant struct {
|
||||
Title string `json:"title"`
|
||||
ID string `json:"id"`
|
||||
Image string `json:"image"`
|
||||
Address string `json:"address"`
|
||||
|
||||
OpeningHours
|
||||
}
|
||||
|
||||
type OpeningHours struct {
|
||||
OpeningTimes []OpeningTime `json:"openingTimes"`
|
||||
OffseasonOpeningTimes []OpeningTime `json:"offseasonOpeningTimes"`
|
||||
OffseasonStart DateOnly `json:"offseasonStart"`
|
||||
OffseasonEnd DateOnly `json:"offseasonEnd"`
|
||||
ChangedTimes []ChangedTime `json:"changedTimes"`
|
||||
}
|
||||
|
||||
type OpeningTime struct {
|
||||
Weekday string `json:"weekday"`
|
||||
OpeningTime TimeOnly `json:"openingTime"`
|
||||
ClosingTime TimeOnly `json:"closingTime"`
|
||||
}
|
||||
|
||||
type ChangedTime struct {
|
||||
StartDate DateOnly `json:"startDate"`
|
||||
EndDate DateOnly `json:"endDate"`
|
||||
OpeningTime TimeOnly `json:"openingTime"`
|
||||
ClosingTime TimeOnly `json:"closingTime"`
|
||||
}
|
||||
53
model/external/stwbremen/types.go
vendored
Normal file
53
model/external/stwbremen/types.go
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
package stwbremen
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TimeOnly struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
// UnmarshalJSON parses a JSON string in HH:MM:SS format into a TimeOnly
|
||||
func (t *TimeOnly) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
parsed, err := time.Parse(time.TimeOnly, s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.Time = parsed
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON converts the TimeOnly to a JSON string in HH:MM:SS format
|
||||
func (t TimeOnly) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.Format(time.TimeOnly))
|
||||
}
|
||||
|
||||
type DateOnly struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
// UnmarshalJSON parses a JSON string in YYYY-MM-DD format into a DateOnly
|
||||
func (d *DateOnly) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
parsed, err := time.Parse(time.DateOnly, s)
|
||||
if err != nil {
|
||||
d.Time = time.Time{}
|
||||
} else {
|
||||
d.Time = parsed
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON converts the DateOnly to a JSON string in YYYY-MM-DD format
|
||||
func (d DateOnly) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(d.Format(time.DateOnly))
|
||||
}
|
||||
Reference in New Issue
Block a user