52 lines
1.2 KiB
Go
Raw Normal View History

2017-06-19 18:59:02 +00:00
package animelistitem
import (
2017-06-20 10:41:26 +00:00
"errors"
2017-06-19 18:59:02 +00:00
"net/http"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2017-06-19 18:59:02 +00:00
"github.com/animenotifier/notify.moe/components"
)
// Get anime page.
2019-06-01 04:55:49 +00:00
func Get(ctx aero.Context) error {
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2017-06-19 18:59:02 +00:00
nick := ctx.Get("nick")
viewUser, err := arn.GetUserByNick(nick)
if err != nil {
return ctx.Error(http.StatusNotFound, "User not found", err)
}
animeList := viewUser.AnimeList()
if animeList == nil {
return ctx.Error(http.StatusNotFound, "Anime list not found", err)
}
animeID := ctx.Get("id")
item := animeList.Find(animeID)
if item == nil {
2017-06-20 10:41:26 +00:00
return ctx.Error(http.StatusNotFound, "List item not found", errors.New("This anime does not exist in "+viewUser.Nick+"'s anime list"))
2017-06-19 18:59:02 +00:00
}
anime := item.Anime()
return ctx.HTML(components.AnimeListItem(animeList.User(), item, anime, user))
2017-06-19 18:59:02 +00:00
}
// t := reflect.TypeOf(item).Elem()
// v := reflect.ValueOf(item).Elem()
// for i := 0; i < t.NumField(); i++ {
// fieldInfo := t.Field(i)
// if fieldInfo.Anonymous || unicode.IsLower([]rune(fieldInfo.Name)[0]) {
// continue
// }
// fmt.Println(fieldInfo.Name, v.Field(i).Interface())
// }