Skip to content

Commit

Permalink
Resolve #549
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-bstein committed Nov 19, 2024
1 parent 75789b0 commit a554d7e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,22 @@ namespace Gameboard.Api.Features.Admin;

public record GetGameCenterContextQuery(string GameId) : IRequest<GameCenterContext>;

internal class GetGameCenterContextHandler : IRequestHandler<GetGameCenterContextQuery, GameCenterContext>
internal class GetGameCenterContextHandler
(
EntityExistsValidator<GetGameCenterContextQuery, Data.Game> gameExists,
INowService now,
IStore store,
ITeamService teamService,
TicketService ticketService,
IValidatorService<GetGameCenterContextQuery> validator
) : IRequestHandler<GetGameCenterContextQuery, GameCenterContext>
{
private readonly EntityExistsValidator<GetGameCenterContextQuery, Data.Game> _gameExists;
private readonly INowService _now;
private readonly IStore _store;
private readonly ITeamService _teamService;
private readonly TicketService _ticketService;
private readonly IValidatorService<GetGameCenterContextQuery> _validator;

public GetGameCenterContextHandler
(
EntityExistsValidator<GetGameCenterContextQuery, Data.Game> gameExists,
INowService now,
IStore store,
ITeamService teamService,
TicketService ticketService,
IValidatorService<GetGameCenterContextQuery> validator
)
{
_gameExists = gameExists;
_now = now;
_store = store;
_teamService = teamService;
_ticketService = ticketService;
_validator = validator;
}
private readonly EntityExistsValidator<GetGameCenterContextQuery, Data.Game> _gameExists = gameExists;
private readonly INowService _now = now;
private readonly IStore _store = store;
private readonly ITeamService _teamService = teamService;
private readonly TicketService _ticketService = ticketService;
private readonly IValidatorService<GetGameCenterContextQuery> _validator = validator;

public async Task<GameCenterContext> Handle(GetGameCenterContextQuery request, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -86,8 +76,11 @@ await _validator
})
.SingleOrDefaultAsync(cancellationToken);

var openTicketCount = await _ticketService
.GetGameOpenTickets(request.GameId)
var gameTotalTicketCount = await _ticketService
.GetGameTicketsQuery(request.GameId)
.CountAsync(cancellationToken);
var gameOpenTicketCount = await _ticketService
.GetGameOpenTicketsQuery(request.GameId)
.CountAsync(cancellationToken);

var topScore = await _store
Expand Down Expand Up @@ -185,7 +178,8 @@ await _validator
// aggregates
ChallengeCount = challengeData?.ChallengeCount ?? 0,
PointsAvailable = challengeData?.PointsAvailable ?? 0,
OpenTicketCount = openTicketCount
OpenTicketCount = gameTotalTicketCount,
TotalTicketCount = gameTotalTicketCount
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public sealed class GameCenterContext

public required int ChallengeCount { get; set; }
public required int OpenTicketCount { get; set; }
public required int TotalTicketCount { get; set; }

public required bool HasScoreboard { get; set; }
public required bool IsExternal { get; set; }
Expand Down
12 changes: 6 additions & 6 deletions src/Gameboard.Api/Features/Ticket/TicketService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ await _mediator.Publish(new TicketCreatedNotification
return createdTicketModel;
}

public IQueryable<Data.Ticket> GetGameOpenTickets(string gameId)
{
return _store
public IQueryable<Data.Ticket> GetGameTicketsQuery(string gameId)
=> _store
.WithNoTracking<Data.Ticket>()
.Where(t => t.Challenge.GameId == gameId || t.Player.Challenges.Any(c => c.GameId == gameId))
.Where(t => t.Status != "Closed");
}
.Where(t => t.Challenge.GameId == gameId || t.Player.Challenges.Any(c => c.GameId == gameId));

public IQueryable<Data.Ticket> GetGameOpenTicketsQuery(string gameId)
=> GetGameTicketsQuery(gameId).Where(t => t.Status != "Closed");

public IQueryable<Data.Ticket> GetTeamTickets(IEnumerable<string> teamIds)
=> _store
Expand Down

0 comments on commit a554d7e

Please sign in to comment.