backend: from to
This commit is contained in:
1 parent
bbbbca95fa
commit
b402d9f92c
3 files changed
+17
-3
No files matched your search
@@ -17,9 +17,15 @@ namespace Helpdesk.Api.Controllers;
|
|||||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
[ProducesResponseType<ProblemDetails>(StatusCodes.Status409Conflict)]
|
||||||
public sealed class ProposalsController(ProposalService proposals) : ControllerBase
|
public sealed class ProposalsController(ProposalService proposals) : ControllerBase
|
||||||
{
|
{
|
||||||
|
/// <summary>Seznam návrhů s volitelným filtrem podle data podání.</summary>
|
||||||
|
/// <param name="query">Filtry, řazení a stránkování.</param>
|
||||||
|
/// <param name="from">Dolní hranice data podání včetně.</param>
|
||||||
|
/// <param name="to">Horní hranice data podání bez uvedeného okamžiku.</param>
|
||||||
|
/// <param name="ct">Token pro zrušení požadavku.</param>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public Task<PagedResult<ProposalSummary>> List([FromQuery] ProposalQuery query, CancellationToken ct) =>
|
public Task<PagedResult<ProposalSummary>> List([FromQuery] ProposalQuery query,
|
||||||
proposals.ListAsync(query, ct);
|
[FromQuery] DateTimeOffset? from, [FromQuery] DateTimeOffset? to, CancellationToken ct) =>
|
||||||
|
proposals.ListAsync(query, from, to, ct);
|
||||||
|
|
||||||
[HttpGet("{id:int}")]
|
[HttpGet("{id:int}")]
|
||||||
public Task<ProposalDetail> Get(int id, CancellationToken ct) => proposals.GetAsync(id, ct);
|
public Task<ProposalDetail> Get(int id, CancellationToken ct) => proposals.GetAsync(id, ct);
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ namespace Helpdesk.Application.Proposals;
|
|||||||
|
|
||||||
public sealed partial class ProposalService
|
public sealed partial class ProposalService
|
||||||
{
|
{
|
||||||
public async Task<PagedResult<ProposalSummary>> ListAsync(ProposalQuery filters, CancellationToken ct)
|
public async Task<PagedResult<ProposalSummary>> ListAsync(
|
||||||
|
ProposalQuery filters, DateTimeOffset? from, DateTimeOffset? to, CancellationToken ct)
|
||||||
{
|
{
|
||||||
await GetActorRoleAsync(ct);
|
await GetActorRoleAsync(ct);
|
||||||
var proposals = db.Proposals.AsNoTracking();
|
var proposals = db.Proposals.AsNoTracking();
|
||||||
@@ -20,6 +21,12 @@ public sealed partial class ProposalService
|
|||||||
proposals = proposals.Where(p => p.CategoryId == categoryId);
|
proposals = proposals.Where(p => p.CategoryId == categoryId);
|
||||||
if (filters.AuthorId is int authorId)
|
if (filters.AuthorId is int authorId)
|
||||||
proposals = proposals.Where(p => p.AuthorId == 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))
|
if (!string.IsNullOrWhiteSpace(filters.Q))
|
||||||
{
|
{
|
||||||
var term = filters.Q.Trim();
|
var term = filters.Q.Trim();
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
CREATE INDEX ix_proposal_created_at ON proposal (created_at);
|
||||||
Reference in new issue
Block a user