diff --git a/README.md b/README.md index 8465831..4df9a1f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ _X-HUSO-AUTH_ -> _secret_ des users | GET | /api/season | Aktuelle Season holen | []Anime JSON | | | | | GET | /api/nextseason | Nächste Season holen | []Anime JSON | | | | | GET | /api/nextnextseason | Übernächste Season holen | []Anime JSON | | | | +| GET | /api/lastseason | Letzte Season holen | []Anime JSON | | | | | GET | /api/anime/{id} | Einzelnen Anime holen | Anime JSON | {id} = MAL Anime id | | | | GET | /api/animesearch | Anime auf MAL suchen | []Anime JSON | Query parameter {q} = Suchtext | | | diff --git a/knecht.go b/knecht.go index 47c38ac..97da047 100644 --- a/knecht.go +++ b/knecht.go @@ -274,3 +274,19 @@ func GetNextNextSeasonString() string { return fmt.Sprintf("%04d", now.Year()) } } + +func GetLastSeasonString() string { + var now = time.Now() + switch now.Month() { + case time.January, time.February, time.March: + return fmt.Sprintf("%04d/fall", now.Year()-1) + case time.April, time.May, time.June: + return fmt.Sprintf("%04d/winter", now.Year()) + case time.July, time.August, time.September: + return fmt.Sprintf("%04d/spring", now.Year()) + case time.October, time.November, time.December: + return fmt.Sprintf("%04d/summer", now.Year()) + default: + return fmt.Sprintf("%04d", now.Year()) + } +} diff --git a/ober.go b/ober.go index a182b48..6a1fb1e 100644 --- a/ober.go +++ b/ober.go @@ -20,6 +20,7 @@ func RunWebserv() { r.GET("/api/season", Headers(Season)) r.GET("/api/nextseason", Headers(SeasonNext)) r.GET("/api/nextnextseason", Headers(SeasonNextNext)) + r.GET("/api/lastseason", Headers(SeasonLast)) r.GET("/api/auth/{user}", Headers(AuthTest)) r.GET("/api/anime/{id}", Headers(AnimeGet)) r.GET("/api/animesearch", Headers(AnimeSearchGet)) @@ -128,6 +129,23 @@ func SeasonNextNext(ctx *fasthttp.RequestCtx) { ctx.SetStatusCode(fasthttp.StatusOK) } +func SeasonLast(ctx *fasthttp.RequestCtx) { + data, err := seasoncache.Get(GetLastSeasonString()) + if err != nil { + addErrorToCtx(ctx, err) + return + } + + err = writeResponseBody(ctx, data) + if err != nil { + addErrorToCtx(ctx, err) + return + } + + ctx.SetContentType("application/json; charset=utf-8") + ctx.SetStatusCode(fasthttp.StatusOK) +} + func AnimeGet(ctx *fasthttp.RequestCtx) { idVal := ctx.UserValue("id") if idVal == nil { diff --git a/praktikant.go b/praktikant.go index 775adaf..892b61d 100644 --- a/praktikant.go +++ b/praktikant.go @@ -171,6 +171,13 @@ func LangeArbeit() { logOut.WriteError(err) } + // last season data + err = refreshSeason(GetLastSeasonString()) + if err != nil { + color.Errorln(err.Error()) + logOut.WriteError(err) + } + // refresh anime cache with watched count := 0 animesUsers, err := ReadAnimeUsers() diff --git a/schaffer.go b/schaffer.go index 1444d67..87340f1 100644 --- a/schaffer.go +++ b/schaffer.go @@ -151,6 +151,15 @@ func SearchSeasons(animeId int64) (*Anime, error) { return &a, err } } + season, err = GetSeasonCache(GetLastSeasonString()) + if err != nil { + return nil, err + } + for _, a := range season { + if a.Anime == animeId { + return &a, err + } + } return nil, errors.New("anime not found") }