backend: Add management statistics endpoints
This commit is contained in:
1 parent
1ff4a0a814
commit
b1e0638979
6 files changed
+240
No files matched your search
@@ -0,0 +1,61 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Helpdesk.Api.Infrastructure;
|
||||
using Helpdesk.Application.Statistics;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Helpdesk.Api.Controllers;
|
||||
|
||||
/// <summary>Statistiky pro vedení školy. Období v UTC zahrnuje začátek a vylučuje konec.</summary>
|
||||
[ApiController]
|
||||
[Authorize(Roles = Roles.Management)]
|
||||
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
|
||||
[Route("api/statistics")]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType<ProblemDetails>(StatusCodes.Status403Forbidden)]
|
||||
public sealed class StatisticsController(StatisticsService statistics) : ControllerBase
|
||||
{
|
||||
/// <summary>Počty podle aktuálního stavu a průměrné časy pro závady nahlášené v období.</summary>
|
||||
[HttpGet("overview")]
|
||||
public Task<StatisticsOverview> GetOverview([FromQuery] StatisticsQuery query, CancellationToken ct) =>
|
||||
statistics.GetOverviewAsync(query.ToPeriod(), ct);
|
||||
|
||||
/// <summary>Počty nahlášených závad a průměrná doba vyřešení podle kategorie.</summary>
|
||||
[HttpGet("issues/by-category")]
|
||||
public Task<IReadOnlyList<IssueCategoryStatistics>> GetByCategory([FromQuery] StatisticsQuery query, CancellationToken ct) =>
|
||||
statistics.GetByCategoryAsync(query.ToPeriod(), ct);
|
||||
|
||||
/// <summary>Počty nahlášených závad podle budovy včetně závad bez budovy.</summary>
|
||||
[HttpGet("issues/by-building")]
|
||||
public Task<IReadOnlyList<IssueBuildingStatistics>> GetByBuilding([FromQuery] StatisticsQuery query, CancellationToken ct) =>
|
||||
statistics.GetByBuildingAsync(query.ToPeriod(), ct);
|
||||
|
||||
/// <summary>Otevřené, vyřešené a zamítnuté závady podle aktuálního řešitele.</summary>
|
||||
[HttpGet("issues/by-assignee")]
|
||||
public Task<IReadOnlyList<IssueAssigneeStatistics>> GetByAssignee([FromQuery] StatisticsQuery query, CancellationToken ct) =>
|
||||
statistics.GetByAssigneeAsync(query.ToPeriod(), ct);
|
||||
|
||||
/// <summary>Počty vytvoření a uzavření závad po měsících podle data události.</summary>
|
||||
[HttpGet("issues/trend")]
|
||||
public Task<IReadOnlyList<IssueTrendPoint>> GetTrend([FromQuery] StatisticsQuery query, CancellationToken ct,
|
||||
[FromQuery, AllowedValues("month")] string granularity = "month") =>
|
||||
statistics.GetTrendAsync(query.ToPeriod(), ct);
|
||||
|
||||
/// <summary>Návrhy podané v období podle aktuálního skóre, počtu hlasů pro a data podání.</summary>
|
||||
[HttpGet("proposals/top")]
|
||||
public Task<IReadOnlyList<TopProposal>> GetTopProposals([FromQuery] StatisticsQuery query, CancellationToken ct,
|
||||
[FromQuery, Range(1, 100)] int limit = 10) =>
|
||||
statistics.GetTopProposalsAsync(query.ToPeriod(), limit, ct);
|
||||
}
|
||||
|
||||
public sealed class StatisticsQuery
|
||||
{
|
||||
[FromQuery(Name = "from")]
|
||||
public DateTimeOffset? From { get; init; }
|
||||
|
||||
[FromQuery(Name = "to")]
|
||||
public DateTimeOffset? To { get; init; }
|
||||
|
||||
internal StatisticsPeriod ToPeriod() => new(From, To);
|
||||
}
|
||||
Reference in new issue
Block a user