Add functionality to display the total number of anime a user has completed for a genre on its page

This commit is contained in:
Ashley Allen
2018-07-26 17:06:47 +01:00
parent 6a83042953
commit f94a5d3d8b
3 changed files with 29 additions and 6 deletions

View File

@ -24,6 +24,7 @@ func Get(ctx *aero.Context) string {
}
userScore := averageScore(user, animes)
userCompleted := totalCompleted(user, animes)
arn.SortAnimeByQuality(animes)
@ -31,7 +32,7 @@ func Get(ctx *aero.Context) string {
animes = animes[:animePerPage]
}
return ctx.HTML(components.Genre(genreName, animes, user, userScore))
return ctx.HTML(components.Genre(genreName, animes, user, userScore, userCompleted))
}
// containsLowerCase tells you whether the given element exists when all elements are lowercased.
@ -71,3 +72,24 @@ func averageScore(user *arn.User, animes []*arn.Anime) float64 {
return scores / count
}
// totalCompleted counts the number of animes the user has completed from a given list of anime
func totalCompleted(user *arn.User, animes []*arn.Anime) int {
if user == nil {
return 0
}
count := 0
completedList := user.AnimeList().FilterStatus(arn.AnimeListStatusCompleted)
for _, anime := range animes {
userAnime := completedList.Find(anime.ID)
if userAnime != nil {
count++;
}
}
return count;
}