Exemplo n.º 1
0
func (gs GameService) addGamesLinks(games *domain.Games, leagueID int64, currentPage, recordsPerPage, totalGameCount int, c *gin.Context) {
	gamesURL := fmt.Sprintf("/api/leagues/%d/games", leagueID)
	addPaginationLinks(games, gamesURL, currentPage, recordsPerPage, totalGameCount)
	if isAuthenticated(c) {
		games.AddLink(domain.RelCreate, gamesURL)
	}

	// Create a unique list of player id's from all the games returned
	playerIDSet := utils.NewInt64Set()
	for _, game := range games.Games {
		gs.addPlayerIdsFromGameTeam(playerIDSet, game.Team1)
		gs.addPlayerIdsFromGameTeam(playerIDSet, game.Team2)
	}
	addGetPlayerListByIDLinks(games, playerIDSet.Values(), c)
}
Exemplo n.º 2
0
func addGetPlayerListByIDLinks(games *domain.Games, playerIds []int64, c *gin.Context) {
	playerListURL, err := url.Parse("/api/players")

	if err != nil {
		utils.GetGaeContext(c).Errorf("Error parsing URL: %v", err)
		c.AbortWithError(500, err)
		return
	}

	q := playerListURL.Query()
	for _, playerID := range playerIds {
		q.Add("id", fmt.Sprintf("%d", playerID))
	}
	playerListURL.RawQuery = q.Encode()

	games.AddLink(relPlayerList, playerListURL.String())
}