Add appointment to watchext

This commit is contained in:
daru
2022-05-28 14:52:32 +02:00
parent 5b029ee835
commit 97f94e5e2f
3 changed files with 33 additions and 5 deletions

View File

@@ -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)-- }
}
]
```

12
ober.go
View File

@@ -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,
})
}

View File

@@ -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)