From 82e04efa78610b7d59542274b3e7c32b27b155da Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Fri, 6 Oct 2023 14:25:04 +0300 Subject: [PATCH] Fix --- .../Controllers/ReportController.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/BUTR.CrashReportServer/Controllers/ReportController.cs b/src/BUTR.CrashReportServer/Controllers/ReportController.cs index c28b570..2104446 100644 --- a/src/BUTR.CrashReportServer/Controllers/ReportController.cs +++ b/src/BUTR.CrashReportServer/Controllers/ReportController.cs @@ -27,6 +27,11 @@ namespace BUTR.CrashReportServer.Controllers; [Route("/report")] public class ReportController : ControllerBase { + public sealed record GetNewCrashReportsBody + { + public required DateTime DateTime { get; init; } + } + private readonly ILogger _logger; private readonly AppDbContext _dbContext; private readonly GZipCompressor _gZipCompressor; @@ -161,15 +166,19 @@ public ActionResult> GetFilenameDates(ICollection> GetNewCrashReportsDates([FromQuery] DateTime date, CancellationToken ct) + public ActionResult> GetNewCrashReportsDates([FromBody] GetNewCrashReportsBody body, CancellationToken ct) { + var diff = DateTime.UtcNow - body.DateTime; + if (diff.Ticks < 0 || DateTime.UtcNow - body.DateTime > TimeSpan.FromDays(7)) + return BadRequest(); + return Ok(_dbContext.Set() - .Where(x => x.Created >= date) + .Where(x => x.Created >= body.DateTime) .Select(x => new { x.FileId, x.CrashReportId, x.Version, x.Created }) .AsAsyncEnumerable() .Select(x => new FileMetadata(x.FileId, x.CrashReportId, x.Version, x.Created.ToUniversalTime())));