0.2.0 #4
@ -6,6 +6,7 @@ namespace Contracts.Repositories;
|
||||
public interface ISpendingGroupRepo
|
||||
{
|
||||
Task<SpendingGroupDto?> Get(SpendingGroupSearch search);
|
||||
Task<SpendingGroupDto?> GetByPlan(SpendingPlanSearch search);
|
||||
Task<IEnumerable<SpendingGroupDto>> GetList(SpendingGroupSearch? search = null);
|
||||
Task<SpendingGroupDto> Create(SpendingGroupDto spendingGroup);
|
||||
Task<SpendingGroupDto?> Delete(SpendingGroupSearch search);
|
||||
|
9
back/Contracts/Services/IReportOffsetFromPlanService.cs
Normal file
9
back/Contracts/Services/IReportOffsetFromPlanService.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
|
||||
namespace Contracts.Services;
|
||||
|
||||
public interface IReportOffsetFromPlanService
|
||||
{
|
||||
public Task<SpendingGroupViewModel> GetReportData(SpendingPlanSearch search);
|
||||
}
|
@ -54,6 +54,30 @@ public class SpendingGroupRepo : ISpendingGroupRepo
|
||||
return group?.ToDto();
|
||||
}
|
||||
|
||||
public async Task<SpendingGroupDto?> GetByPlan(SpendingPlanSearch search)
|
||||
{
|
||||
using var context = _factory.CreateDbContext();
|
||||
var plan = await context.SpendingPlans
|
||||
.FirstOrDefaultAsync(x => x.Id == search.Id);
|
||||
|
||||
if (plan == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var group = await context.SpendingGroups
|
||||
.Where(x => x.Id == plan.SpendingGroupId)
|
||||
.Include(x => x.ChangeRecords != null
|
||||
? x.ChangeRecords
|
||||
.Where(cg => cg.ChangedAt >= plan.StartAt && cg.ChangedAt <= plan.EndAt)
|
||||
.OrderBy(cg => cg.ChangedAt)
|
||||
: null)
|
||||
.LastAsync();
|
||||
group.SpendingPlans = [plan];
|
||||
|
||||
return group.ToDto();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SpendingGroupDto>> GetList(SpendingGroupSearch? search = null)
|
||||
{
|
||||
using var context = _factory.CreateDbContext();
|
||||
|
32
back/Services/Reports/ReportOffsetFromPlanService.cs
Normal file
32
back/Services/Reports/ReportOffsetFromPlanService.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using Contracts.Mappers;
|
||||
using Contracts.Repositories;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.Services;
|
||||
using Contracts.ViewModels;
|
||||
using Services.Support.Exceptions;
|
||||
|
||||
namespace Services.Reports;
|
||||
|
||||
public class ReportOffsetFromPlanService : IReportOffsetFromPlanService
|
||||
{
|
||||
private readonly ISpendingGroupRepo _spendingGroupRepo;
|
||||
|
||||
public ReportOffsetFromPlanService(ISpendingGroupRepo spendingGroupRepo)
|
||||
{
|
||||
_spendingGroupRepo = spendingGroupRepo;
|
||||
}
|
||||
|
||||
public async Task<SpendingGroupViewModel> GetReportData(SpendingPlanSearch search)
|
||||
{
|
||||
var group = await _spendingGroupRepo.GetByPlan(search);
|
||||
if (group == null)
|
||||
{
|
||||
throw new EntityNotFoundException("Не удалось найти группу по такому плану");
|
||||
}
|
||||
if (!group.ChangeRecords.Any())
|
||||
{
|
||||
throw new ReportDataNotFoundException("Данные об изменении баланса отсутствуют");
|
||||
}
|
||||
return group.ToView();
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
namespace Services.Support.Exceptions;
|
||||
|
||||
public class ReportDataNotFoundException : EntityNotFoundException
|
||||
{
|
||||
public ReportDataNotFoundException(string message)
|
||||
: base(message) { }
|
||||
public ReportDataNotFoundException(string message, Exception innerException)
|
||||
: base(message, innerException) { }
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user