Skip to content

Commit 1790b46

Browse files
committed
Add practice collections filter to reports
1 parent 99ae82d commit 1790b46

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Linq;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Gameboard.Api.Data;
5+
using Gameboard.Api.Features.Users;
6+
using Gameboard.Api.Structure.MediatR;
7+
using MediatR;
8+
using Microsoft.EntityFrameworkCore;
9+
10+
namespace Gameboard.Api.Features.Reports;
11+
12+
public record GetPracticeCollectionsParameterOptionsQuery() : IRequest<SimpleEntity[]>;
13+
14+
internal sealed class GetPracticeCollectionsParameterOptionsHandler
15+
(
16+
IStore store,
17+
IValidatorService validator
18+
) : IRequestHandler<GetPracticeCollectionsParameterOptionsQuery, SimpleEntity[]>
19+
{
20+
public async Task<SimpleEntity[]> Handle(GetPracticeCollectionsParameterOptionsQuery request, CancellationToken cancellationToken)
21+
{
22+
// validate
23+
await validator
24+
.Auth(c => c.Require(PermissionKey.Reports_View))
25+
.Validate(cancellationToken);
26+
27+
return await store
28+
.WithNoTracking<PracticeChallengeGroup>()
29+
.Where(g => g.ParentGroupId == null)
30+
.Select(g => new SimpleEntity
31+
{
32+
Id = g.Id,
33+
Name = g.Name
34+
})
35+
.OrderBy(g => g.Name)
36+
.ToArrayAsync(cancellationToken);
37+
}
38+
}

src/Gameboard.Api/Features/Reports/ReportsController.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using Gameboard.Api.Features.Challenges;
5+
using Gameboard.Api.Features.Practice;
56
using MediatR;
67
using Microsoft.AspNetCore.Authorization;
78
using Microsoft.AspNetCore.Mvc;
@@ -11,9 +12,10 @@ namespace Gameboard.Api.Features.Reports;
1112
[ApiController]
1213
[Authorize]
1314
[Route("/api/reports")]
14-
public class ReportsController(IMediator mediator, IReportsService service) : ControllerBase
15+
public class ReportsController(IMediator mediator, IPracticeService practiceService, IReportsService service) : ControllerBase
1516
{
1617
private readonly IMediator _mediator = mediator;
18+
private readonly IPracticeService _practiceService = practiceService;
1719
private readonly IReportsService _service = service;
1820

1921
[HttpGet]
@@ -96,6 +98,10 @@ public Task<IEnumerable<SimpleEntity>> GetChallengeSpecs(string gameId = null)
9698
public Task<string[]> GetChallengeTags(CancellationToken cancellationToken)
9799
=> _service.ListChallengeTags(cancellationToken);
98100

101+
[HttpGet("parameter/collections")]
102+
public Task<SimpleEntity[]> GetCollections(CancellationToken cancellationToken)
103+
=> _mediator.Send(new GetPracticeCollectionsParameterOptionsQuery(), cancellationToken);
104+
99105
[HttpGet("parameter/games")]
100106
public Task<IEnumerable<SimpleEntity>> GetGames()
101107
=> _service.ListGames();

0 commit comments

Comments
 (0)