2024-02-02 22:36:05 +00:00
|
|
|
using BotSharp.Abstraction.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.OpenAPI.Controllers;
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class AgentTaskController : ControllerBase
|
|
|
|
|
{
|
2024-02-04 05:42:13 +00:00
|
|
|
private readonly IAgentTaskService _agentTaskService;
|
2024-02-02 22:36:05 +00:00
|
|
|
private readonly IServiceProvider _services;
|
|
|
|
|
|
2024-02-04 05:42:13 +00:00
|
|
|
public AgentTaskController(IAgentTaskService agentTaskService, IServiceProvider services)
|
2024-02-02 22:36:05 +00:00
|
|
|
{
|
2024-02-04 05:42:13 +00:00
|
|
|
_agentTaskService = agentTaskService;
|
2024-02-02 22:36:05 +00:00
|
|
|
_services = services;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-04 05:42:13 +00:00
|
|
|
[HttpGet("/agent/{agentId}/task/{taskId}")]
|
2024-02-04 22:57:47 +00:00
|
|
|
public async Task<AgentTaskViewModel> GetAgentTask([FromRoute] string agentId, [FromRoute] string taskId)
|
2024-02-02 22:36:05 +00:00
|
|
|
{
|
2024-02-04 05:42:13 +00:00
|
|
|
var task = await _agentTaskService.GetTask(agentId, taskId);
|
|
|
|
|
if (task == null) return null;
|
|
|
|
|
|
|
|
|
|
return AgentTaskViewModel.From(task);
|
2024-02-02 22:36:05 +00:00
|
|
|
}
|
2024-02-04 22:57:47 +00:00
|
|
|
|
2024-02-02 22:36:05 +00:00
|
|
|
[HttpGet("/agent/tasks")]
|
2024-02-04 22:57:47 +00:00
|
|
|
public async Task<PagedItems<AgentTaskViewModel>> GetAgentTasks([FromQuery] AgentTaskFilter filter)
|
2024-02-02 22:36:05 +00:00
|
|
|
{
|
2024-02-04 05:42:13 +00:00
|
|
|
var tasks = await _agentTaskService.GetTasks(filter);
|
2024-02-02 22:36:05 +00:00
|
|
|
return new PagedItems<AgentTaskViewModel>
|
|
|
|
|
{
|
|
|
|
|
Items = tasks.Items.Select(x => AgentTaskViewModel.From(x)),
|
|
|
|
|
Count = tasks.Count
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-02-04 05:42:13 +00:00
|
|
|
|
|
|
|
|
[HttpPost("/agent/{agentId}/task")]
|
|
|
|
|
public async Task CreateAgentTask([FromRoute] string agentId, [FromBody] AgentTaskCreateModel task)
|
|
|
|
|
{
|
|
|
|
|
var agentTask = task.ToAgentTask();
|
|
|
|
|
agentTask.AgentId = agentId;
|
|
|
|
|
await _agentTaskService.CreateTask(agentTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPut("/agent/{agentId}/task/{taskId}")]
|
2024-02-04 20:01:56 +00:00
|
|
|
public async Task UpdateAgentTask([FromRoute] string agentId, [FromRoute] string taskId, [FromBody] AgentTaskUpdateModel task)
|
2024-02-04 05:42:13 +00:00
|
|
|
{
|
2024-02-04 20:01:56 +00:00
|
|
|
var agentTask = task.ToAgentTask();
|
|
|
|
|
agentTask.AgentId = agentId;
|
|
|
|
|
agentTask.Id = taskId;
|
|
|
|
|
await _agentTaskService.UpdateTask(agentTask, AgentTaskField.All);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPatch("/agent/{agentId}/task/{taskId}/{field}")]
|
|
|
|
|
public async Task PatchAgentTaskByField([FromRoute] string agentId, [FromRoute] string taskId, [FromRoute] AgentTaskField field, [FromBody] AgentTaskUpdateModel task)
|
|
|
|
|
{
|
|
|
|
|
var agentTask = task.ToAgentTask();
|
|
|
|
|
agentTask.AgentId = agentId;
|
|
|
|
|
agentTask.Id = taskId;
|
|
|
|
|
await _agentTaskService.UpdateTask(agentTask, field);
|
2024-02-04 05:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("/agent/{agentId}/task/{taskId}")]
|
|
|
|
|
public async Task<bool> DeleteAgentTask([FromRoute] string agentId, [FromRoute] string taskId)
|
|
|
|
|
{
|
|
|
|
|
return await _agentTaskService.DeleteTask(agentId, taskId);
|
|
|
|
|
}
|
2024-02-02 22:36:05 +00:00
|
|
|
}
|