diff --git a/backend/src/Helpdesk.Api/Controllers/ProposalsController.cs b/backend/src/Helpdesk.Api/Controllers/ProposalsController.cs index bac69e0..77a36ed 100644 --- a/backend/src/Helpdesk.Api/Controllers/ProposalsController.cs +++ b/backend/src/Helpdesk.Api/Controllers/ProposalsController.cs @@ -17,9 +17,15 @@ namespace Helpdesk.Api.Controllers; [ProducesResponseType(StatusCodes.Status409Conflict)] public sealed class ProposalsController(ProposalService proposals) : ControllerBase { + /// Seznam návrhů s volitelným filtrem podle data podání. + /// Filtry, řazení a stránkování. + /// Dolní hranice data podání včetně. + /// Horní hranice data podání bez uvedeného okamžiku. + /// Token pro zrušení požadavku. [HttpGet] - public Task> List([FromQuery] ProposalQuery query, CancellationToken ct) => - proposals.ListAsync(query, ct); + public Task> List([FromQuery] ProposalQuery query, + [FromQuery] DateTimeOffset? from, [FromQuery] DateTimeOffset? to, CancellationToken ct) => + proposals.ListAsync(query, from, to, ct); [HttpGet("{id:int}")] public Task Get(int id, CancellationToken ct) => proposals.GetAsync(id, ct); diff --git a/backend/src/Helpdesk.Application/Proposals/ProposalService.Reads.cs b/backend/src/Helpdesk.Application/Proposals/ProposalService.Reads.cs index 577243d..24ab52b 100644 --- a/backend/src/Helpdesk.Application/Proposals/ProposalService.Reads.cs +++ b/backend/src/Helpdesk.Application/Proposals/ProposalService.Reads.cs @@ -7,7 +7,8 @@ namespace Helpdesk.Application.Proposals; public sealed partial class ProposalService { - public async Task> ListAsync(ProposalQuery filters, CancellationToken ct) + public async Task> ListAsync( + ProposalQuery filters, DateTimeOffset? from, DateTimeOffset? to, CancellationToken ct) { await GetActorRoleAsync(ct); var proposals = db.Proposals.AsNoTracking(); @@ -20,6 +21,12 @@ public sealed partial class ProposalService proposals = proposals.Where(p => p.CategoryId == categoryId); if (filters.AuthorId is int authorId) proposals = proposals.Where(p => p.AuthorId == authorId); + if (from >= to) + throw new BadRequestException("Začátek období musí předcházet jeho konci."); + if (from?.UtcDateTime is DateTime fromUtc) + proposals = proposals.Where(p => p.CreatedAt >= fromUtc); + if (to?.UtcDateTime is DateTime toUtc) + proposals = proposals.Where(p => p.CreatedAt < toUtc); if (!string.IsNullOrWhiteSpace(filters.Q)) { var term = filters.Q.Trim(); diff --git a/db/migrations/V004__proposal_created_at_index.sql b/db/migrations/V004__proposal_created_at_index.sql new file mode 100644 index 0000000..1fb0d14 --- /dev/null +++ b/db/migrations/V004__proposal_created_at_index.sql @@ -0,0 +1 @@ +CREATE INDEX ix_proposal_created_at ON proposal (created_at);