diff --git a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs index 172d4a01..37f8685c 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs @@ -50,7 +50,7 @@ public interface IBotSharpRepository : IHaveServiceProvider => throw new NotImplementedException(); void UpdateUserName(string userId, string userName) => throw new NotImplementedException(); - Dashboard? GetDashboard(string id = null) + Dashboard? GetDashboard(string userId = null) => throw new NotImplementedException(); void CreateUser(User user) => throw new NotImplementedException(); diff --git a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs index f92d7225..8563b215 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs @@ -33,8 +33,8 @@ public interface IUserService Task UpdatePassword(string newPassword, string verificationCode); Task GetUserTokenExpires(); Task UpdateUsersIsDisable(List userIds, bool isDisable); - Task AddDashboardConversation(string userId, string conversationId); - Task RemoveDashboardConversation(string userId, string conversationId); - Task UpdateDashboardConversation(string userId, DashboardConversation dashConv); - Task GetDashboard(string userId); + Task AddDashboardConversation(string conversationId); + Task RemoveDashboardConversation(string conversationId); + Task UpdateDashboardConversation(DashboardConversation dashConv); + Task GetDashboard(); } \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs index 9d5b42be..5c984684 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.User.cs @@ -53,7 +53,7 @@ public partial class FileRepository return Users.FirstOrDefault(x => x.UserName == userName.ToLower()); } - public Dashboard? GetDashboard(string id = null) + public Dashboard? GetDashboard(string userId = null) { return Dashboards.FirstOrDefault(); } diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index 73053063..18bf96eb 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -810,40 +810,47 @@ public class UserService : IUserService return true; } - public async Task AddDashboardConversation(string userId, string conversationId) + public async Task AddDashboardConversation(string conversationId) { + var user = await GetUser(_user.Id); var db = _services.GetRequiredService(); - db.AddDashboardConversation(userId, conversationId); - + db.AddDashboardConversation(user?.Id, conversationId); await Task.CompletedTask; return true; } - public async Task RemoveDashboardConversation(string userId, string conversationId) + public async Task RemoveDashboardConversation(string conversationId) { + var user = await GetUser(_user.Id); var db = _services.GetRequiredService(); - db.RemoveDashboardConversation(userId, conversationId); - + db.RemoveDashboardConversation(user?.Id, conversationId); await Task.CompletedTask; return true; } - public async Task UpdateDashboardConversation(string userId, DashboardConversation newDashConv) + public async Task UpdateDashboardConversation(DashboardConversation newDashConv) { var db = _services.GetRequiredService(); - var dashConv = db.GetDashboard(userId)?.ConversationList.FirstOrDefault(x => string.Equals(x.ConversationId, newDashConv.ConversationId)); + + var user = await GetUser(_user.Id); + var dashConv = db.GetDashboard(user?.Id)? + .ConversationList + .FirstOrDefault(x => string.Equals(x.ConversationId, newDashConv.ConversationId)); if (dashConv == null) return; + dashConv.Name = newDashConv.Name ?? dashConv.Name; dashConv.Instruction = newDashConv.Instruction ?? dashConv.Instruction; - db.UpdateDashboardConversation(userId, dashConv); + db.UpdateDashboardConversation(user?.Id, dashConv); await Task.CompletedTask; return; } - public async Task GetDashboard(string userId) + public async Task GetDashboard() { var db = _services.GetRequiredService(); - var dash = db.GetDashboard(); + + var user = await GetUser(_user.Id); + var dash = db.GetDashboard(user?.Id); await Task.CompletedTask; return dash; } diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 4a05b121..5704655f 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -66,16 +66,16 @@ public class AgentController : ControllerBase return targetAgent; } - [HttpGet("/agents")] - public async Task> GetAgents([FromQuery] AgentFilter filter, [FromQuery] bool checkAuth = false) + [HttpPost("/agents")] + public async Task> GetAgents([FromBody] AgentQueryRequest request) { var agentSetting = _services.GetRequiredService(); var userService = _services.GetRequiredService(); List agents; - var pagedAgents = await _agentService.GetAgents(filter); + var pagedAgents = await _agentService.GetAgents(request.Filter); - if (!checkAuth) + if (!request.CheckAuth) { agents = pagedAgents?.Items?.Select(x => AgentViewModel.FromAgent(x))?.ToList() ?? []; return new PagedItems diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs index 266c5ac5..b2defb2e 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/ConversationController.cs @@ -535,14 +535,12 @@ public class ConversationController : ControllerBase } #endregion - #region miscellaneous + #region Dashboard [HttpPut("/agent/{agentId}/conversation/{conversationId}/dashboard")] public async Task PinConversationToDashboard([FromRoute] string agentId, [FromRoute] string conversationId) { var userService = _services.GetRequiredService(); - - var user = await userService.GetUser(_user.Id); - var pinned = await userService.AddDashboardConversation(user.Id, conversationId); + var pinned = await userService.AddDashboardConversation(conversationId); return pinned; } @@ -550,9 +548,7 @@ public class ConversationController : ControllerBase public async Task UnpinConversationFromDashboard([FromRoute] string agentId, [FromRoute] string conversationId) { var userService = _services.GetRequiredService(); - - var user = await userService.GetUser(_user.Id); - var unpinned = await userService.RemoveDashboardConversation(user.Id, conversationId); + var unpinned = await userService.RemoveDashboardConversation(conversationId); return unpinned; } #endregion diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs index 0534b01d..c95d819d 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/DashboardController.cs @@ -19,11 +19,12 @@ public class DashboardController : ControllerBase } #region User Components [HttpGet("/dashboard/components")] - public async Task GetComponents(string userId) + public async Task GetComponents() { var userService = _services.GetRequiredService(); - var dashboardProfile = await userService.GetDashboard(userId); + var dashboardProfile = await userService.GetDashboard(); if (dashboardProfile == null) return new UserDashboardModel(); + var result = new UserDashboardModel { ConversationList = dashboardProfile.ConversationList.Select( @@ -39,7 +40,7 @@ public class DashboardController : ControllerBase } [HttpPost("/dashboard/component/conversation")] - public async Task UpdateDashboardConversationInstruction(string userId, UserDashboardConversationModel dashConv) + public async Task UpdateDashboardConversationInstruction(UserDashboardConversationModel dashConv) { if (string.IsNullOrEmpty(dashConv.Name) && string.IsNullOrEmpty(dashConv.Instruction)) { @@ -60,7 +61,7 @@ public class DashboardController : ControllerBase } var userService = _services.GetRequiredService(); - await userService.UpdateDashboardConversation(userId, newDashConv); + await userService.UpdateDashboardConversation(newDashConv); return; } #endregion diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentQueryRequest.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentQueryRequest.cs new file mode 100644 index 00000000..4d53b60c --- /dev/null +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentQueryRequest.cs @@ -0,0 +1,7 @@ +namespace BotSharp.OpenAPI.ViewModels.Agents; + +public class AgentQueryRequest +{ + public AgentFilter Filter { get; set; } = AgentFilter.Empty(); + public bool CheckAuth { get; set; } +}