namespace MyOffice.Web.Controllers; using AutoMapper; using Core.Extensions; using Infrastructure.Attributes; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using MyOffice.Web.Models.Dashboard; using Services.Dashboard; [Authorize] [ApiController] [Route("api/dashboard")] [DefaultFromBody] public class DashboardController : BaseApiController { private readonly ILogger _logger; private readonly DashboardService _dashboardService; private readonly IMapper _mapper; public DashboardController( ILogger logger, DashboardService dashboardService, IMapper mapper ) { _logger = logger; _dashboardService = dashboardService; _mapper = mapper; } [HttpGet] public async Task Index(CancellationToken cancellationToken) { var data = await _dashboardService.GetDashboardRestDataAsync(UserId, cancellationToken); return OkResponse(_mapper.Map(data)); } [HttpGet("income")] public async Task Income( DateTime from, DateTime to, [AsGuid(true)] string? category, CancellationToken cancellationToken ) { var data = await _dashboardService.GetDashboardIncomeDataAsync( UserId, from.StartOfDay(), to.EndOfDay(), category?.AsGuidNull(), cancellationToken); return OkResponse(_mapper.Map(data)); } [HttpGet("outcome")] public async Task Outcome( DateTime from, DateTime to, [AsGuid(true)] string? category, CancellationToken cancellationToken ) { var data = await _dashboardService.GetDashboardOutcomeDataAsync( UserId, from.StartOfDay(), to.EndOfDay(), category?.AsGuidNull(), cancellationToken); return OkResponse(_mapper.Map(data)); } }