62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
using Contracts.Services;
|
|
using Contracts.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Services.Support.Exceptions;
|
|
|
|
namespace Controllers.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class ReportController : ControllerBase
|
|
{
|
|
private readonly IReportPeriodService _reportPeriodService;
|
|
private readonly IReportOffsetFromPlanService _reportOffsetFromPlanService;
|
|
|
|
public ReportController(IReportPeriodService reportPeriodService,
|
|
IReportOffsetFromPlanService reportOffsetFromPlanService)
|
|
{
|
|
_reportPeriodService = reportPeriodService;
|
|
_reportOffsetFromPlanService = reportOffsetFromPlanService;
|
|
}
|
|
|
|
[HttpGet("period/{id}")]
|
|
public async Task<ActionResult<IEnumerable<ChangeRecordViewModel>>> GetReportData(
|
|
[FromQuery] DateTime from, [FromQuery] DateTime to, Guid id)
|
|
{
|
|
try
|
|
{
|
|
var periodData = await _reportPeriodService.GetReportData(from, to, id);
|
|
return Ok(periodData);
|
|
}
|
|
catch (ReportDataNotFoundException ex)
|
|
{
|
|
return NotFound(ex.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, ex.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet("plan/{id}")]
|
|
public async Task<ActionResult<SpendingGroupViewModel>> GetReportOffsetFromPlan(Guid id)
|
|
{
|
|
try
|
|
{
|
|
var offset = await _reportOffsetFromPlanService.GetReportData(new() { Id = id });
|
|
return Ok(offset);
|
|
}
|
|
catch (ReportDataNotFoundException ex)
|
|
{
|
|
return NotFound(ex.Message);
|
|
}
|
|
catch (EntityNotFoundException ex)
|
|
{
|
|
return NotFound(ex.Message);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, ex.Message);
|
|
}
|
|
}
|
|
} |