From 578ba15ef55fb6c7df8cd90ae0e89873c313abc9 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Fri, 16 Jun 2023 06:36:03 -0500 Subject: [PATCH] Get agent list. --- .../BotSharp.Abstraction/Agents/IAgentService.cs | 1 + .../BotSharp.Core/Agents/AgentController.cs | 7 +++++++ .../BotSharp.Core/Agents/Services/AgentService.cs | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs index a914ce42..abef9c46 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentService.cs @@ -8,6 +8,7 @@ namespace BotSharp.Abstraction.Agents; public interface IAgentService { Task CreateAgent(Agent agent); + Task> GetAgents(); Task DeleteAgent(string id); Task UpdateAgent(Agent agent); } diff --git a/src/Infrastructure/BotSharp.Core/Agents/AgentController.cs b/src/Infrastructure/BotSharp.Core/Agents/AgentController.cs index 0db3a1de..fbff072c 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/AgentController.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/AgentController.cs @@ -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> GetAgents() + { + var agents = await _agentService.GetAgents(); + return agents.Select(x => AgentViewModel.FromAgent(x)).ToList(); + } } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs index 4a521a75..c7fdce39 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.cs @@ -43,6 +43,15 @@ public class AgentService : IAgentService throw new NotImplementedException(); } + public async Task> GetAgents() + { + var db = _services.GetRequiredService(); + 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();