79 lines
1.6 KiB
Go
Raw Normal View History

2016-11-09 11:32:19 +00:00
package main
import (
2016-11-19 08:49:00 +00:00
"sort"
2016-11-09 13:11:49 +00:00
"github.com/aerogo/aero"
2016-11-09 11:32:19 +00:00
"github.com/animenotifier/arn"
2016-11-12 16:40:16 +00:00
"github.com/animenotifier/notify.moe/components"
2016-11-09 11:32:19 +00:00
)
func init() {
app.Ajax("/", func(ctx *aero.Context) string {
2016-11-12 16:40:16 +00:00
return ctx.HTML(components.Dashboard())
2016-11-09 11:32:19 +00:00
})
app.Ajax("/anime/:id", func(ctx *aero.Context) string {
2016-11-12 16:45:13 +00:00
id, _ := ctx.GetInt("id")
2016-11-09 11:32:19 +00:00
anime, err := arn.GetAnime(id)
if err != nil {
return ctx.Text("Anime not found")
}
2016-11-12 16:40:16 +00:00
return ctx.HTML(components.Anime(anime))
2016-11-09 11:32:19 +00:00
})
app.Ajax("/genres", func(ctx *aero.Context) string {
2016-11-12 16:40:16 +00:00
return ctx.HTML(components.GenreOverview())
2016-11-09 11:32:19 +00:00
})
app.Ajax("/genres/:name", func(ctx *aero.Context) string {
genreName := ctx.Get("name")
genreInfo := new(arn.Genre)
err := arn.GetObject("Genres", genreName, genreInfo)
if err != nil {
return err.Error()
}
2016-11-12 16:40:16 +00:00
return ctx.HTML(components.AnimeInGenre(genreInfo.Genre, genreInfo.AnimeList))
2016-11-09 11:32:19 +00:00
})
2016-11-18 17:58:00 +00:00
const threadsPerPage = 12
forumHandler := func(ctx *aero.Context) string {
tag := ctx.Get("tag")
threads, _ := arn.GetThreadsByTag(tag)
2016-11-19 08:49:00 +00:00
sort.Sort(threads)
2016-11-18 17:58:00 +00:00
if len(threads) > threadsPerPage {
threads = threads[:threadsPerPage]
}
for _, thread := range threads {
thread.Author, _ = arn.GetUser(thread.AuthorID)
}
return ctx.HTML(components.Forum(threads))
}
app.Ajax("/forum", forumHandler)
app.Ajax("/forum/:tag", forumHandler)
2016-11-19 08:49:00 +00:00
app.Ajax("/threads/:id", func(ctx *aero.Context) string {
id := ctx.Get("id")
thread, err := arn.GetThread(id)
if err != nil {
return ctx.Text("Thread not found")
}
thread.Author, _ = arn.GetUser(thread.AuthorID)
return ctx.HTML(components.Thread(thread))
})
2016-11-09 11:32:19 +00:00
}