Ejemplo n.º 1
0
func (gs GameService) getGame(c *gin.Context) {
	leagueID := getLeagueIDFromURL(c)

	if leagueID <= 0 {
		c.Redirect(302, "/api/leagues")
		return
	}

	gameID := getGameIDFromURL(c)

	if gameID <= 0 {
		c.Redirect(302, fmt.Sprintf("/api/leagues/%d/games", leagueID))
		return
	}

	gameDao := dao.CreateGameDao(c)

	game, err := gameDao.GetGame(leagueID, gameID)

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

	gs.addGameLinks(leagueID, game, c)
	c.JSON(200, game)
}
Ejemplo n.º 2
0
func (us UserService) startLoginProcess(c *gin.Context) {
	gaeCtx := utils.GetGaeRootContext(c)

	loginURL, err := appengineuser.LoginURL(gaeCtx, "")

	if err != nil {
		c.AbortWithError(500, err)
		return
	}

	c.Redirect(302, loginURL)
}
Ejemplo n.º 3
0
func (ls LeagueService) getLeague(c *gin.Context) {
	leagueID := getLeagueIDFromURL(c)

	if leagueID <= 0 {
		c.Redirect(304, "/api/leagues")
		return
	}

	leagueDao := dao.CreateLeagueDao(c)

	league, err := leagueDao.GetLeague(leagueID)

	if err != nil {
		c.AbortWithError(500, err)
		return
	}

	addLeagueLinks(league, c)
	c.JSON(200, league)
}
Ejemplo n.º 4
0
func (ps PlayerService) getPlayer(c *gin.Context) {
	playerID := getPlayerIDFromURL(c)

	if playerID <= 0 {
		c.Redirect(304, "/api/players")
		return
	}

	playerDao := dao.CreatePlayerDao(c)

	player, err := playerDao.GetPlayer(playerID)

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

	addPlayerLinks(player, c)
	c.JSON(200, player)
}
Ejemplo n.º 5
0
func (gs GameService) getGames(c *gin.Context) {
	leagueID := getLeagueIDFromURL(c)

	if leagueID <= 0 {
		c.Redirect(302, "/api/leagues")
		return
	}

	currentPage := getCurrentPage(c)
	recordsPerPage := 50
	start := getStartRecord(currentPage, recordsPerPage)

	gameDao := dao.CreateGameDao(c)

	gameArray, totalGameCount, err := gameDao.GetGames(start, recordsPerPage, leagueID)

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

	if gameArray == nil {
		gameArray = []domain.Game{}
	}

	for index := range gameArray {
		gs.addGameLinks(leagueID, &gameArray[index], c)
	}

	games := &domain.Games{
		Games: gameArray,
		Total: totalGameCount,
	}

	gs.addGamesLinks(games, leagueID, currentPage, recordsPerPage, totalGameCount, c)

	c.JSON(200, games)
}