Beispiel #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))
		}
	}
}
Beispiel #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))
		}
	}
}
Beispiel #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))
		}
	}
}
Beispiel #4
0
func getGame(c common.Context) {
	c.RenderJSON(models.GetGameById(c, common.MustDecodeKey(c.Vars["game_id"])))
}
Beispiel #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))
}
Beispiel #6
0
func getAIs(c common.Context) {
	c.RenderJSON(models.GetAllAIs(c))
}
Beispiel #7
0
func getUser(c common.Context) {
	c.RenderJSON(c.User)
}