diff --git a/README.md b/README.md index 88af9dc..c2bec06 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,8 @@ _[]AnimeUserExtended_ (GET) "updated": "2022-05-15T20:44:35Z" } ], - "data": { --SEE ANIME GET (Anime object)-- } + "data": { --SEE ANIME GET (Anime object)-- }, + "appointments": { --SEE APPOINTMENT GET (Appointment list)-- } }, { "anime": 40356, @@ -227,7 +228,8 @@ _[]AnimeUserExtended_ (GET) "updated": "2022-04-25T18:11:27Z" } ], - "data": { --SEE ANIME GET (Anime object)-- } + "data": { --SEE ANIME GET (Anime object)-- }, + "appointments": { --SEE APPOINTMENT GET (Appointment list)-- } } ] ``` diff --git a/ober.go b/ober.go index 10b8c3e..5767378 100644 --- a/ober.go +++ b/ober.go @@ -316,10 +316,16 @@ func WatchExtendedGet(ctx *fasthttp.RequestCtx) { addErrorToCtx(ctx, err) return } + apps, err := SearchAppointments(a.Anime) + if err != nil { + addErrorToCtx(ctx, err) + return + } animeUsersExtended = append(animeUsersExtended, AnimeUserExtended{ - Anime: a.Anime, - Users: a.Users, - Data: *data, + Anime: a.Anime, + Users: a.Users, + Data: *data, + Appointments: apps, }) } diff --git a/schaffer.go b/schaffer.go index 6c00830..2e39550 100644 --- a/schaffer.go +++ b/schaffer.go @@ -6,6 +6,8 @@ import ( "fmt" "strings" "time" + + "github.com/xujiajun/nutsdb" ) func JikanConvert(jik *SeasonAnimeJikan) Anime { @@ -160,6 +162,24 @@ func SearchAnime(animeId int64) (*Anime, error) { return anime, err } +func SearchAppointments(animeId int64) ([]Appointment, error) { + appointments, err := ReadAppointments() + if err != nil { + if strings.Contains(err.Error(), "not found") || err == nutsdb.ErrBucketEmpty { + return make([]Appointment, 0), nil + } else { + return appointments, err + } + } + result := make([]Appointment, 0) + for _, a := range appointments { + if animeId == a.Anime { + result = append(result, a) + } + } + return result, nil +} + func FetchProgress(animeId, userId int64, username string, progress int) (int, time.Time, string, error) { // check watching first newProgress, updated, err := fetchProgressOnState(animeId, userId, progress, username, malApiStatusW)