Started working on episode pages
This commit is contained in:
43
pages/episode/episode.go
Normal file
43
pages/episode/episode.go
Normal file
@ -0,0 +1,43 @@
|
||||
package episode
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// Get renders the anime episode.
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
id := ctx.Get("id")
|
||||
episodeNumber, err := ctx.GetInt("episode-number")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusBadRequest, "Episode is not a number", err)
|
||||
}
|
||||
|
||||
// Get anime
|
||||
anime, err := arn.GetAnime(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||
}
|
||||
|
||||
// Get anime episodes
|
||||
animeEpisodes, err := arn.GetAnimeEpisodes(id)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime episodes not found", err)
|
||||
}
|
||||
|
||||
episode := animeEpisodes.Find(episodeNumber)
|
||||
|
||||
if episode == nil {
|
||||
return ctx.Error(http.StatusNotFound, "Anime episode not found", nil)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.AnimeEpisode(anime, episode, user))
|
||||
}
|
Reference in New Issue
Block a user