2016-11-20 19:26:11 +09:00
|
|
|
package profile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2017-06-08 14:46:38 +02:00
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
2016-11-20 19:26:11 +09:00
|
|
|
)
|
|
|
|
|
2017-06-08 14:46:38 +02:00
|
|
|
const maxPosts = 5
|
|
|
|
|
2016-11-20 19:26:11 +09:00
|
|
|
// Get ...
|
|
|
|
func Get(ctx *aero.Context) string {
|
|
|
|
nick := ctx.Get("nick")
|
2017-06-08 14:46:38 +02:00
|
|
|
viewUser, err := arn.GetUserByNick(nick)
|
|
|
|
user := utils.GetUser(ctx)
|
2016-11-20 19:26:11 +09:00
|
|
|
|
|
|
|
if err != nil {
|
2016-11-23 14:26:59 +09:00
|
|
|
return ctx.Error(404, "User not found", err)
|
2016-11-20 19:26:11 +09:00
|
|
|
}
|
|
|
|
|
2017-06-08 14:46:38 +02:00
|
|
|
threads := viewUser.Threads()
|
|
|
|
|
|
|
|
arn.SortThreadsByDate(threads)
|
|
|
|
|
|
|
|
if len(threads) > maxPosts {
|
|
|
|
threads = threads[:maxPosts]
|
|
|
|
}
|
|
|
|
|
2017-06-08 21:54:39 +02:00
|
|
|
animeList := viewUser.AnimeList()
|
|
|
|
|
|
|
|
return ctx.HTML(components.Profile(viewUser, user, animeList, threads))
|
2016-11-20 19:26:11 +09:00
|
|
|
}
|