Implement appointment reading

This commit is contained in:
daru
2022-05-14 13:55:22 +02:00
parent bbf99fadb4
commit 50e0defc28
6 changed files with 74 additions and 9 deletions

39
nuss.go
View File

@@ -253,6 +253,39 @@ func ReadAnimeUsers() ([]AnimeUser, error) {
return animes, err
}
func ReadAppointments() ([]Appointment, error) {
var appoints []Appointment
err := db.View(
func(tx *nutsdb.Tx) error {
entries, err := tx.GetAll(bucketAppoint)
if err != nil {
return err
}
appoints = make([]Appointment, 0)
// iterate entries
for _, e := range entries {
// decode appointment list
animeId, date, err := BytesToInt64AndDate(e.Key)
if err != nil {
return err
}
// parse user list
appointmentUsers, err := parseAppointmentUserList(e.Value)
if err != nil {
return err
}
appointment := Appointment{
Anime: animeId,
Time: date,
Users: appointmentUsers,
}
appoints = append(appoints, appointment)
}
return nil
})
return appoints, err
}
func DbClean() error {
return db.Update(
func(tx *nutsdb.Tx) error {
@@ -297,3 +330,9 @@ func parseWatchUserList(data []byte) ([]WatchUser, error) {
err := json.Unmarshal(data, &users)
return users, err
}
func parseAppointmentUserList(data []byte) ([]string, error) {
var users []string
err := json.Unmarshal(data, &users)
return users, err
}