2016-11-09 11:32:19 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2016-11-09 13:11:49 +00:00
|
|
|
"github.com/aerogo/aero"
|
2016-11-09 11:32:19 +00:00
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
app.Get("/all/anime", func(ctx *aero.Context) string {
|
|
|
|
start := time.Now()
|
|
|
|
var titles []string
|
|
|
|
|
|
|
|
results := make(chan *arn.Anime)
|
|
|
|
arn.Scan("Anime", results)
|
|
|
|
|
|
|
|
for anime := range results {
|
|
|
|
titles = append(titles, anime.Title.Romaji)
|
|
|
|
}
|
|
|
|
sort.Strings(titles)
|
|
|
|
|
|
|
|
return ctx.Text(s(len(titles)) + " anime fetched in " + s(time.Since(start)) + "\n\n" + strings.Join(titles, "\n"))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.Get("/api/anime/:id", func(ctx *aero.Context) string {
|
2016-11-09 13:11:49 +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")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.JSON(anime)
|
|
|
|
})
|
|
|
|
|
|
|
|
app.Get("/api/users/:nick", func(ctx *aero.Context) string {
|
|
|
|
nick := ctx.Get("nick")
|
|
|
|
user, err := arn.GetUserByNick(nick)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Text("User not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.JSON(user)
|
|
|
|
})
|
|
|
|
}
|