public SeasonTeamMatchesResource GetTeamMatches(string seasonId, string teamId) { RequestHelper.ValidateId(seasonId); RequestHelper.ValidateId(teamId); // Check team exists and belongs to user. var teamService = ServiceFactory.CreateTeamService(); var team = teamService.GetTeam(teamId); Game teamGame = null; bool gameBelongsToUser = team != null && TryFindGameForCurrentUser(team.GameId, out teamGame); if (!gameBelongsToUser) { throw ResponseHelper.Get404NotFound($"Team with ID '{teamId}' not found"); } // Check season exists and belongs to user. var seasonGame = GetGameFromSeasonId(seasonId); // Determine both season and team belong to the same game. if (seasonGame.Id != teamGame.Id) { throw ResponseHelper.Get404NotFound($"Season with ID '{seasonId}' and/or Team with ID '{teamId}' not found"); } var matchService = ServiceFactory.CreateMatchService(seasonGame); var matches = matchService.GetBySeasonAndTeam(seasonId, teamId).ToList(); if (!matches.Any()) { throw ResponseHelper.Get404NotFound($"No matches found for seasonId '{seasonId}' and teamId '{teamId}'"); } var matchResources = matches.Select(GetMatchResource).ToList(); var links = new SeasonTeamMatchesLinks(seasonId, teamId); var teamMatches = new SeasonTeamMatchesResource(matchResources, links); return teamMatches; }
public SeasonTeamMatchesResource(List<MatchResource> matches, SeasonTeamMatchesLinks links) : base(links) { Matches = matches; }