feat(api,core,dal,domain): Сохранение снапшотов состояния роботов.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using PARR.Domain.DTOs.RobotSnapshotDTO;
|
||||
|
||||
namespace PARR.Core.Services.RobotSnapshotServices
|
||||
{
|
||||
public interface IRobotSnapshotService
|
||||
{
|
||||
Task<RobotSnapshotItem> CreateAsync(CreateRobotSnapshot robotSnapshot);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user