Skip to content

Commit

Permalink
New endpoint and changes to observe by team
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-jbritton committed May 6, 2022
1 parent bcd44d4 commit 078d036
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Gameboard.Api/Features/Challenge/Challenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public class ObserveChallenge
public string Id { get; set; }
public string TeamId { get; set; }
public string Name { get; set; }
public string Tag { get; set; }
public string PlayerId { get; set; }
public string PlayerName { get; set; }
public long Duration { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/Gameboard.Api/Features/Challenge/ChallengeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public ChallengeMapper()
.ForMember(d => d.isActive, opt => opt.MapFrom(s =>
JsonSerializer.Deserialize<TopoMojo.Api.Client.GameState>(s.State, JsonOptions).IsActive)
)
.ForMember(d => d.Duration, opt => opt.MapFrom(s => s.Duration))
;

CreateMap<TopoMojo.Api.Client.VmState, ObserveVM>()
Expand Down
1 change: 1 addition & 0 deletions src/Gameboard.Api/Features/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public class TeamAdvancement
public class Team
{
public string TeamId { get; set; }
public string ApprovedName { get; set; }
public string GameId { get; set; }
public string Sponsor { get; set; }
public DateTimeOffset SessionBegin { get; set; }
Expand Down
16 changes: 16 additions & 0 deletions src/Gameboard.Api/Features/Player/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ public async Task<TeamSummary[]> GetTeams([FromRoute] string id)
return await PlayerService.LoadTeams(id, Actor.IsRegistrar);
}

/// <summary>
/// Get a Game's Teams with Members
/// </summary>
/// <param name="id">Game Id</param>
/// <returns>Team[]</returns>
[HttpGet("/api/teams/observe/{id}")]
[Authorize]
public async Task<Team[]> ObserveTeams([FromRoute] string id)
{
AuthorizeAny(
() => Actor.IsObserver
);

return await PlayerService.ObserveTeams(id);
}

/// <summary>
/// Get Player Team
/// </summary>
Expand Down
38 changes: 38 additions & 0 deletions src/Gameboard.Api/Features/Player/PlayerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,44 @@ public async Task<TeamSummary[]> LoadTeams(string id, bool sudo)

}

public async Task<Team[]> ObserveTeams(string id)
{
var players = await Store.List()
.Where(p => p.GameId == id)
.Include(p => p.User)
.ToArrayAsync()
;

var teams = players
.Where(p => p.IsLive)
.GroupBy(p => p.TeamId)
.Select(g => new Team {
TeamId = g.Key,
ApprovedName = g.First().ApprovedName,
Sponsor = g.First().Sponsor,
GameId = g.First().GameId,
SessionBegin = g.First().SessionBegin,
SessionEnd = g.First().SessionEnd,
Rank = g.First().Rank,
Score = g.First().Score,
Time = g.First().Time,
CorrectCount = g.First().CorrectCount,
PartialCount = g.First().PartialCount,
Advanced = g.First().Advanced,
Members = g.Select(i => new TeamMember{
Id = i.UserId,
ApprovedName = i.User.ApprovedName,
Role = i.Role
}).OrderBy(t => t.ApprovedName).ToArray()
})
.OrderBy(g => g.ApprovedName)
.ToArray()
;

return teams;

}

public async Task AdvanceTeams(TeamAdvancement model)
{
var game = await GameStore.Retrieve(model.NextGameId);
Expand Down

0 comments on commit 078d036

Please sign in to comment.