feat(api,core,dal,domain): Сохранение снапшотов состояния роботов.

This commit is contained in:
Mikhail Trubnikov
2026-06-10 16:48:16 +10:00
parent a64ab59de1
commit d736208a46
22 changed files with 4194 additions and 1 deletions

View File

@@ -0,0 +1,9 @@
using PARR.Domain.DTOs.RobotSnapshotDTO;
namespace PARR.Core.Services.RobotSnapshotServices
{
public interface IRobotSnapshotService
{
Task<RobotSnapshotItem> CreateAsync(CreateRobotSnapshot robotSnapshot);
}
}

View File

@@ -0,0 +1,46 @@
using AutoMapper;
using PARR.Core.Repositories.Interfaces.RobotRepositories;
using PARR.Domain.DTOs.RobotSnapshotDTO;
using PARR.Domain.Entities.RobotEntities;
using PARR.Domain.Exceptions;
namespace PARR.Core.Services.RobotSnapshotServices
{
internal class RobotSnapshotService : IRobotSnapshotService
{
private readonly IRobotSnapshotRepository robotSnapshotRepository;
private readonly IMapper mapper;
public RobotSnapshotService(
IRobotSnapshotRepository robotSnapshotRepository,
IMapper mapper
)
{
this.robotSnapshotRepository = robotSnapshotRepository;
this.mapper = mapper;
}
public async Task<RobotSnapshotItem> CreateAsync(CreateRobotSnapshot robotSnapshot)
{
var snapshot = new RobotSnapshot
{
Id = Guid.NewGuid(),
TemplateRobotsCount = robotSnapshot.TemplateRobotsCount,
ScheduleRobotsCount = robotSnapshot.ScheduleRobotsCount,
MaxRobots = robotSnapshot.MaxRobots,
Ip = robotSnapshot.Ip
};
var createdResult = await robotSnapshotRepository.CreateAsync(snapshot);
var commitResult = await robotSnapshotRepository.CommitAsync();
if (!createdResult || !commitResult)
throw new DbErrorException("Ошибка сохранения в БД");
return mapper.Map<RobotSnapshotItem>(snapshot);
}
}
}