feat(api, bll): StatHostController, StatApplicationController добавлена статистика за период. ICalendarService - публичный метод для получения списка дат, метод получения даты с учетом часового пояса.
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests.BaseRequests;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Contracts.V1.Responses.Statistics;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.BLL.Services.Interfaces;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
@@ -17,10 +19,12 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
public class StatApplicationController : BaseApiController
|
||||
{
|
||||
private readonly IApplicationService applicationService;
|
||||
private readonly ICalendarService calendarService;
|
||||
|
||||
public StatApplicationController(IApplicationService applicationService)
|
||||
public StatApplicationController(IApplicationService applicationService, ICalendarService calendarService)
|
||||
{
|
||||
this.applicationService = applicationService;
|
||||
this.calendarService = calendarService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,5 +45,50 @@ namespace PARR.API.Controllers.V1.Statistics
|
||||
|
||||
return Ok(new Response<StatApplicationResponse>(response, true));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить статистику за период
|
||||
/// </summary>
|
||||
/// <param name="timeZoneQuery"></param>
|
||||
/// <param name="startPeriodDays"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.StatApplication.GetForPeriod)]
|
||||
public async Task<IActionResult> GetForPeriod([FromQuery] TimeZoneOffsetClient timeZoneQuery, [FromQuery] int startPeriodDays = 3)
|
||||
{
|
||||
var endPeriod = calendarService.GetDateWithTimeZoneOffset(DateTimeOffset.UtcNow, timeZoneQuery.TimeZoneOffsetHours);
|
||||
var startPeriod = endPeriod.AddDays(-startPeriodDays);
|
||||
|
||||
var query = applicationService.Get()
|
||||
.Where(t => t.DateCreated.DateTime.Date >= startPeriod.Date && t.DateCreated.DateTime.Date <= endPeriod.Date)
|
||||
.GroupBy(t => t.DateCreated.Date)
|
||||
.Select(t => new
|
||||
{
|
||||
Date = t.Key,
|
||||
ApplicationCount = t.Count()
|
||||
});
|
||||
|
||||
var result = await query.ToListAsync();
|
||||
|
||||
var daysList = calendarService.GetDatesForPeriod(startPeriod, endPeriod);
|
||||
|
||||
var response = new List<StatApplicationPeriodResponse>();
|
||||
|
||||
daysList.ForEach(date =>
|
||||
{
|
||||
response.Add(new StatApplicationPeriodResponse
|
||||
{
|
||||
Date = date,
|
||||
CreatedApplicationsCount = result.FirstOrDefault(t => DateOnly.FromDateTime(t.Date) == date)?.ApplicationCount ?? 0
|
||||
});
|
||||
});
|
||||
|
||||
response = response.OrderBy(t => t.Date).ToList();
|
||||
|
||||
return Ok(new Response<List<StatApplicationPeriodResponse>>(response, true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user