39 lines
803 B
Go
Raw Normal View History

2017-07-13 06:23:20 +00:00
package character
import (
"net/http"
2017-11-20 08:01:28 +00:00
"sort"
2017-07-13 06:23:20 +00:00
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
2017-11-19 14:15:44 +00:00
"github.com/animenotifier/notify.moe/utils"
2017-07-13 06:23:20 +00:00
)
// Get character.
func Get(ctx *aero.Context) string {
2017-11-19 14:15:44 +00:00
user := utils.GetUser(ctx)
2017-07-13 06:23:20 +00:00
id := ctx.Get("id")
character, err := arn.GetCharacter(id)
if err != nil {
return ctx.Error(http.StatusNotFound, "Character not found", err)
}
2017-11-20 08:01:28 +00:00
characterAnime := character.Anime()
sort.Slice(characterAnime, func(i, j int) bool {
if characterAnime[i].StartDate == "" {
return false
}
if characterAnime[j].StartDate == "" {
return true
}
return characterAnime[i].StartDate < characterAnime[j].StartDate
})
return ctx.HTML(components.CharacterDetails(character, characterAnime, user))
2017-07-13 06:23:20 +00:00
}