2023-08-19 00:15:02 +00:00
|
|
|
using BotSharp.Abstraction.ApiAdapters;
|
|
|
|
|
using BotSharp.OpenAPI.ViewModels.Agents;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.OpenAPI.Controllers;
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class AgentController : ControllerBase, IApiAdapter
|
|
|
|
|
{
|
|
|
|
|
private readonly IAgentService _agentService;
|
|
|
|
|
public AgentController(IAgentService agentService)
|
|
|
|
|
{
|
|
|
|
|
_agentService = agentService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("/agent")]
|
|
|
|
|
public async Task<AgentViewModel> CreateAgent(AgentCreationModel agent)
|
|
|
|
|
{
|
|
|
|
|
var createdAgent = await _agentService.CreateAgent(agent.ToAgent());
|
|
|
|
|
return AgentViewModel.FromAgent(createdAgent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("/agent/{agentId}")]
|
|
|
|
|
public async Task UpdateAgent([FromRoute] string agentId,
|
|
|
|
|
[FromBody] AgentUpdateModel agent)
|
|
|
|
|
{
|
|
|
|
|
var model = agent.ToAgent();
|
|
|
|
|
model.Id = agentId;
|
|
|
|
|
await _agentService.UpdateAgent(model);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-13 22:34:19 +00:00
|
|
|
[HttpPut("/agent/file/{agentId}")]
|
|
|
|
|
public async Task UpdateAgentFromFile([FromRoute] string agentId)
|
|
|
|
|
{
|
|
|
|
|
await _agentService.UpdateAgentFromFile(agentId);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-19 00:15:02 +00:00
|
|
|
[HttpGet("/agents")]
|
|
|
|
|
public async Task<List<AgentViewModel>> GetAgents()
|
|
|
|
|
{
|
|
|
|
|
var agents = await _agentService.GetAgents();
|
|
|
|
|
return agents.Select(x => AgentViewModel.FromAgent(x)).ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|