Get agent list.

This commit is contained in:
Haiping Chen 2023-06-16 06:36:03 -05:00
parent 2dd93aef42
commit 578ba15ef5
3 changed files with 17 additions and 0 deletions

View file

@ -8,6 +8,7 @@ namespace BotSharp.Abstraction.Agents;
public interface IAgentService
{
Task<Agent> CreateAgent(Agent agent);
Task<List<Agent>> GetAgents();
Task<bool> DeleteAgent(string id);
Task UpdateAgent(Agent agent);
}

View file

@ -22,4 +22,11 @@ public class AgentController : ControllerBase, IApiAdapter
var createdAgent = await _agentService.CreateAgent(agent.ToAgent());
return AgentViewModel.FromAgent(createdAgent);
}
[HttpGet("/agents")]
public async Task<List<AgentViewModel>> GetAgents()
{
var agents = await _agentService.GetAgents();
return agents.Select(x => AgentViewModel.FromAgent(x)).ToList();
}
}

View file

@ -43,6 +43,15 @@ public class AgentService : IAgentService
throw new NotImplementedException();
}
public async Task<List<Agent>> GetAgents()
{
var db = _services.GetRequiredService<AgentDbContext>();
var query = from agent in db.Agent
where agent.OwnerId == _user.Id
select agent.ToAgent();
return query.ToList();
}
public Task UpdateAgent(Agent agent)
{
throw new NotImplementedException();