Ejemplo n.º 1
0
func getAIErrors(c common.Context) {
	if c.Authenticated() {
		if ai := models.GetAIById(c, common.MustDecodeKey(c.Vars["ai_id"])); ai != nil && ai.Owner == c.User.Email {
			c.RenderJSON(ai.GetErrors(c))
		}
	}
}
Ejemplo n.º 2
0
func createGame(c common.Context) {
	if c.Authenticated() {
		var game models.Game
		aiCommon.MustDecodeJSON(c.Req.Body, &game)
		if len(game.Players) > 0 {
			c.RenderJSON(game.Save(c))
		}
	}
}
Ejemplo n.º 3
0
func createAI(c common.Context) {
	if c.Authenticated() {
		var ai models.AI
		aiCommon.MustDecodeJSON(c.Req.Body, &ai)
		if ai.Name != "" && ai.URL != "" {
			ai.Owner = c.User.Email
			ai.Id = nil
			c.RenderJSON(ai.Save(c))
		}
	}
}
Ejemplo n.º 4
0
func getGame(c common.Context) {
	c.RenderJSON(models.GetGameById(c, common.MustDecodeKey(c.Vars["game_id"])))
}
Ejemplo n.º 5
0
func getGames(c common.Context) {
	limit := aiCommon.TryParseInt(c.Req.URL.Query().Get("limit"), 10)
	offset := aiCommon.TryParseInt(c.Req.URL.Query().Get("offset"), 0)
	c.RenderJSON(models.GetGamePage(c, offset, limit))
}
Ejemplo n.º 6
0
func getAIs(c common.Context) {
	c.RenderJSON(models.GetAllAIs(c))
}
Ejemplo n.º 7
0
func getUser(c common.Context) {
	c.RenderJSON(c.User)
}