feat: add amount of episodes
This commit is contained in:
@@ -270,6 +270,7 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) {
|
|||||||
recommendations []jikan.RecommendationEntry
|
recommendations []jikan.RecommendationEntry
|
||||||
watchlist []database.GetUserWatchListRow
|
watchlist []database.GetUserWatchListRow
|
||||||
status string
|
status string
|
||||||
|
episodesCount int
|
||||||
)
|
)
|
||||||
|
|
||||||
g, gCtx := errgroup.WithContext(r.Context())
|
g, gCtx := errgroup.WithContext(r.Context())
|
||||||
@@ -277,6 +278,26 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) {
|
|||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
var err error
|
var err error
|
||||||
anime, err = h.jikanClient.GetAnimeByID(gCtx, id)
|
anime, err = h.jikanClient.GetAnimeByID(gCtx, id)
|
||||||
|
if err == nil && anime.Airing {
|
||||||
|
// If airing, we want to know how many episodes are released so far.
|
||||||
|
// The episodes endpoint with page 1 gives us the last visible page in pagination.
|
||||||
|
eps, err := h.jikanClient.GetEpisodes(gCtx, id, 1)
|
||||||
|
if err == nil {
|
||||||
|
if eps.Pagination.LastVisiblePage > 1 {
|
||||||
|
// Fetch last page to get the true count
|
||||||
|
lastEps, err := h.jikanClient.GetEpisodes(gCtx, id, eps.Pagination.LastVisiblePage)
|
||||||
|
if err == nil && len(lastEps.Data) > 0 {
|
||||||
|
lastEp := lastEps.Data[len(lastEps.Data)-1]
|
||||||
|
count, _ := strconv.Atoi(lastEp.Episode)
|
||||||
|
episodesCount = count
|
||||||
|
}
|
||||||
|
} else if len(eps.Data) > 0 {
|
||||||
|
lastEp := eps.Data[len(eps.Data)-1]
|
||||||
|
count, _ := strconv.Atoi(lastEp.Episode)
|
||||||
|
episodesCount = count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -336,6 +357,7 @@ func (h *Handler) HandleAnimeDetails(w http.ResponseWriter, r *http.Request) {
|
|||||||
"Status": status,
|
"Status": status,
|
||||||
"CurrentPath": r.URL.Path,
|
"CurrentPath": r.URL.Path,
|
||||||
"WatchlistIDs": watchlistIDs,
|
"WatchlistIDs": watchlistIDs,
|
||||||
|
"EpisodesCount": episodesCount,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Printf("render error: %v", err)
|
log.Printf("render error: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
|||||||
@@ -303,7 +303,8 @@ type SearchResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Pagination struct {
|
type Pagination struct {
|
||||||
HasNextPage bool `json:"has_next_page"`
|
LastVisiblePage int `json:"last_visible_page"`
|
||||||
|
HasNextPage bool `json:"has_next_page"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TopAnimeResponse struct {
|
type TopAnimeResponse struct {
|
||||||
|
|||||||
@@ -35,7 +35,11 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if $anime.Type}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Type}}</span>{{end}}
|
{{if $anime.Type}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Type}}</span>{{end}}
|
||||||
{{if $anime.Episodes}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Episodes}} episodes</span>{{end}}
|
{{if and $anime.Airing .EpisodesCount}}
|
||||||
|
<span class="flex items-center gap-1.5"><span>•</span>{{.EpisodesCount}}{{if $anime.Episodes}}/{{$anime.Episodes}}{{end}} episodes</span>
|
||||||
|
{{else if $anime.Episodes}}
|
||||||
|
<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Episodes}} episodes</span>
|
||||||
|
{{end}}
|
||||||
{{if $anime.Status}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Status}}</span>{{end}}
|
{{if $anime.Status}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Status}}</span>{{end}}
|
||||||
{{if $anime.Season}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Premiered}}</span>{{end}}
|
{{if $anime.Season}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.Premiered}}</span>{{end}}
|
||||||
{{if $anime.ShortRating}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.ShortRating}}</span>{{end}}
|
{{if $anime.ShortRating}}<span class="flex items-center gap-1.5"><span>•</span>{{$anime.ShortRating}}</span>{{end}}
|
||||||
|
|||||||
Reference in New Issue
Block a user