func (gs GameService) addGameLinks(leagueID int64, game *domain.Game, c *gin.Context) {
	gameURL := fmt.Sprintf("/api/leagues/%d/games/%d", leagueID, game.ID)

	game.AddLink(domain.RelSelf, gameURL)

	if isAuthenticated(c) {
		game.AddLink(domain.RelUpdate, gameURL)
	}
}
func (gs GameService) createGame(c *gin.Context) {
	leagueID := getLeagueIDFromURL(c)

	var game domain.Game

	c.Bind(&game)

	game.ID = 0
	game.LeagueID = leagueID

	gs.doSaveGame(game, c)
}
Beispiel #3
0
func (dao *GameDao) SaveGame(game domain.Game) (*domain.Game, error) {
	if game.ID == 0 {
		gameID, _, _ := datastore.AllocateIDs(dao.Context, EntityGame, nil, 1)
		game.ID = gameID
	}

	leagueKey := datastore.NewKey(dao.Context, EntityLeague, "", game.LeagueID, nil)
	game.League = leagueKey
	key := datastore.NewKey(dao.Context, EntityGame, "", game.ID, leagueKey)

	g, err := dao.save(key, &game)

	if err != nil {
		return nil, err
	}

	savedGame := g.(*domain.Game)

	return savedGame, err
}