-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathAgentFlowService.cs
More file actions
48 lines (40 loc) · 1.37 KB
/
AgentFlowService.cs
File metadata and controls
48 lines (40 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using MaIN.Domain.Entities.Agents.AgentSource;
using MaIN.Domain.Exceptions;
using MaIN.Infrastructure.Models;
using MaIN.Infrastructure.Repositories.Abstract;
using MaIN.Services.Mappers;
using MaIN.Services.Services.Abstract;
namespace MaIN.Services.Services;
public class AgentFlowService(IAgentFlowRepository flowRepository, IAgentService agentService) : IAgentFlowService
{
public async Task<AgentFlow> GetFlowById(string id)
{
var flow = await flowRepository.GetFlowById(id);
if (flow is null)
{
throw new AgentFlowNotFoundException(id);
}
return flow.ToDomain();
}
public async Task<List<AgentFlow>> GetAllFlows()
=> (await flowRepository.GetAllFlows()).Select(x => x.ToDomain()).ToList();
public async Task<AgentFlow> CreateFlow(AgentFlow flow)
{
flow.Id ??= Guid.NewGuid().ToString();
await flowRepository.AddFlow(flow.ToDocument());
foreach (var agent in flow.Agents)
{
await agentService.CreateAgent(agent, true);
}
return flow;
}
public async Task DeleteFlow(string id)
{
var flow = await flowRepository.GetFlowById(id);
foreach (var agent in flow?.Agents!)
{
await agentService.DeleteAgent(agent.Id);
}
await flowRepository.DeleteFlow(id);
}
}