0.2.0 #4
@ -5,6 +5,7 @@ public class ChangeRecordDto
|
|||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
public Guid? SpendingGroupId { get; set; }
|
public Guid? SpendingGroupId { get; set; }
|
||||||
|
public string SpendingGroupName { get; set; } = string.Empty;
|
||||||
public decimal Sum { get; set; }
|
public decimal Sum { get; set; }
|
||||||
public DateTime ChangedAt { get; set; }
|
public DateTime ChangedAt { get; set; }
|
||||||
}
|
}
|
@ -8,8 +8,9 @@ public static class ChangeRecordMapper
|
|||||||
public static ChangeRecordViewModel ToView(this ChangeRecordDto dto)
|
public static ChangeRecordViewModel ToView(this ChangeRecordDto dto)
|
||||||
=> new()
|
=> new()
|
||||||
{
|
{
|
||||||
Id = dto.Id,
|
Id = dto.Id,
|
||||||
Sum = dto.Sum,
|
Sum = dto.Sum,
|
||||||
ChangedAt = dto.ChangedAt
|
ChangedAt = dto.ChangedAt,
|
||||||
|
SpendingGroupName = dto.SpendingGroupName
|
||||||
};
|
};
|
||||||
}
|
}
|
8
back/Contracts/Services/IReportPeriodService.cs
Normal file
8
back/Contracts/Services/IReportPeriodService.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using Contracts.ViewModels;
|
||||||
|
|
||||||
|
namespace Contracts.Services;
|
||||||
|
|
||||||
|
public interface IReportPeriodService
|
||||||
|
{
|
||||||
|
Task<IEnumerable<ChangeRecordViewModel>> GetReportData(DateTime from, DateTime to);
|
||||||
|
}
|
@ -5,4 +5,5 @@ public class ChangeRecordViewModel
|
|||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public decimal Sum { get; set; }
|
public decimal Sum { get; set; }
|
||||||
public DateTime ChangedAt { get; set; }
|
public DateTime ChangedAt { get; set; }
|
||||||
|
public string SpendingGroupName { get; set; } = string.Empty;
|
||||||
}
|
}
|
37
back/Controllers/Controllers/ReportController.cs
Normal file
37
back/Controllers/Controllers/ReportController.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Contracts.Services;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Services.Support;
|
||||||
|
|
||||||
|
namespace Controllers.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class ReportController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IReportPeriodService _reportPeriodService;
|
||||||
|
|
||||||
|
public ReportController(IReportPeriodService reportPeriodService)
|
||||||
|
{
|
||||||
|
_reportPeriodService = reportPeriodService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("period")]
|
||||||
|
public async Task<ActionResult<IEnumerable<ChangeRecordViewModel>>> GetReportData(
|
||||||
|
[FromQuery] DateTime from, [FromQuery] DateTime to)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var periodData = await _reportPeriodService.GetReportData(from, to);
|
||||||
|
return Ok(periodData);
|
||||||
|
}
|
||||||
|
catch (ReportDataNotFoundException ex)
|
||||||
|
{
|
||||||
|
return NotFound(ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using Contracts.Services;
|
using Contracts.Services;
|
||||||
using Services.Domain;
|
using Services.Domain;
|
||||||
|
using Services.Reports;
|
||||||
|
|
||||||
namespace Controllers.Extensions;
|
namespace Controllers.Extensions;
|
||||||
|
|
||||||
@ -9,11 +10,10 @@ public static class AddDomainServicesExtension
|
|||||||
{
|
{
|
||||||
services.AddTransient<IAuthService, AuthService>();
|
services.AddTransient<IAuthService, AuthService>();
|
||||||
services.AddTransient<IUserService, UserService>();
|
services.AddTransient<IUserService, UserService>();
|
||||||
|
|
||||||
services.AddTransient<ISpendingGroupService, SpendingGroupService>();
|
services.AddTransient<ISpendingGroupService, SpendingGroupService>();
|
||||||
|
|
||||||
services.AddTransient<IChangeRecordService, ChangeRecordService>();
|
services.AddTransient<IChangeRecordService, ChangeRecordService>();
|
||||||
|
|
||||||
services.AddTransient<ISpendingPlanService, SpendingPlanService>();
|
services.AddTransient<ISpendingPlanService, SpendingPlanService>();
|
||||||
|
|
||||||
|
services.AddTransient<IReportPeriodService, ReportPeriodService>();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -46,6 +46,7 @@ public class ChangeRecordRepo : IChangeRecordRepo
|
|||||||
using var context = _factory.CreateDbContext();
|
using var context = _factory.CreateDbContext();
|
||||||
|
|
||||||
var record = await context.ChangeRecords
|
var record = await context.ChangeRecords
|
||||||
|
.Include(x => x.SpendingGroup)
|
||||||
.FirstOrDefaultAsync(x => x.Id == search.Id);
|
.FirstOrDefaultAsync(x => x.Id == search.Id);
|
||||||
if (record == null)
|
if (record == null)
|
||||||
{
|
{
|
||||||
@ -71,7 +72,7 @@ public class ChangeRecordRepo : IChangeRecordRepo
|
|||||||
query = query.Where(x => x.ChangedAt >= search.From && x.ChangedAt <= search.To);
|
query = query.Where(x => x.ChangedAt >= search.From && x.ChangedAt <= search.To);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await query.Select(x => x.ToDto()).ToListAsync();
|
return await query.Include(x => x.SpendingGroup).Select(x => x.ToDto()).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ChangeRecordDto?> Update(ChangeRecordDto changeRecord)
|
public async Task<ChangeRecordDto?> Update(ChangeRecordDto changeRecord)
|
||||||
|
29
back/Services/Reports/ReportPeriodService.cs
Normal file
29
back/Services/Reports/ReportPeriodService.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using Contracts.Mappers;
|
||||||
|
using Contracts.Repositories;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
using Contracts.Services;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using Services.Support;
|
||||||
|
|
||||||
|
namespace Services.Reports;
|
||||||
|
|
||||||
|
public class ReportPeriodService : IReportPeriodService
|
||||||
|
{
|
||||||
|
private readonly IChangeRecordRepo _changeRecordRepo;
|
||||||
|
|
||||||
|
public ReportPeriodService(IChangeRecordRepo changeRecordRepo)
|
||||||
|
{
|
||||||
|
_changeRecordRepo = changeRecordRepo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<ChangeRecordViewModel>> GetReportData(DateTime from, DateTime to)
|
||||||
|
{
|
||||||
|
var records = await _changeRecordRepo.GetList(new ChangeRecordSearch() { From = from, To = to });
|
||||||
|
|
||||||
|
if (!records.Any())
|
||||||
|
{
|
||||||
|
throw new ReportDataNotFoundException("Нет данных за указанный период");
|
||||||
|
}
|
||||||
|
return records.Select(x => x.ToView()).ToList();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user