danylokhodus's picture
init
b9c7f0e
Raw
History Blame Contribute Delete
1.62 kB
using FlowAPI.Application.DTOs.Edge;
using FlowAPI.Application.Interfaces;
using FlowAPI.Domain.Entities;
namespace FlowAPI.Application.Services
{
public class EdgeService : IEdgeService
{
private readonly IEdgeRepository _repo;
public EdgeService(IEdgeRepository repo)
{
_repo = repo;
}
public async Task<IEnumerable<EdgeResponseDto>> GetAllByGraphIdAsync(Guid graphId)
{
var edges = await _repo.GetAllByGraphIdAsync(graphId);
return edges.Select(MapToDto);
}
public async Task<EdgeResponseDto?> GetByIdAsync(Guid id)
{
var edge = await _repo.GetByIdAsync(id);
return edge is null ? null : MapToDto(edge);
}
public async Task<EdgeResponseDto> CreateAsync(CreateEdgeDto dto)
{
var edge = new Edge
{
Id = Guid.NewGuid(),
GraphId = dto.GraphId,
FromNodeId = dto.FromNodeId,
ToNodeId = dto.ToNodeId,
Condition = dto.Condition
};
var created = await _repo.CreateAsync(edge);
return MapToDto(created);
}
public async Task<bool> DeleteAsync(Guid id)
{
return await _repo.DeleteAsync(id);
}
private static EdgeResponseDto MapToDto(Edge edge) => new()
{
Id = edge.Id,
GraphId = edge.GraphId,
FromNodeId = edge.FromNodeId,
ToNodeId = edge.ToNodeId,
Condition = edge.Condition
};
}
}