56 lines
1.1 KiB
Go
Raw Normal View History

2016-11-09 11:32:19 +00:00
package main
import (
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() {
2016-11-19 14:54:31 +00:00
// app.Get("/all/anime", func(ctx *aero.Context) string {
// var titles []string
2016-11-09 11:32:19 +00:00
2016-11-19 14:54:31 +00:00
// results := make(chan *arn.Anime)
// arn.Scan("Anime", results)
2016-11-09 11:32:19 +00:00
2016-11-19 14:54:31 +00:00
// for anime := range results {
// titles = append(titles, anime.Title.Romaji)
// }
// sort.Strings(titles)
2016-11-09 11:32:19 +00:00
2016-11-19 14:54:31 +00:00
// return ctx.Text(toString(len(titles)) + "\n\n" + strings.Join(titles, "\n"))
// })
2016-11-09 11:32:19 +00:00
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)
})
2016-11-18 17:58:00 +00:00
app.Get("/api/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")
}
return ctx.JSON(thread)
})
2016-11-09 11:32:19 +00:00
}