mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 12:19:54 +01:00
Implement appointment reading
This commit is contained in:
39
nuss.go
39
nuss.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user