fix dashboard
This commit is contained in:
parent
8fd0b6092c
commit
d6ebf80a7b
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ public interface IUserService
|
|||
Task<bool> UpdatePassword(string newPassword, string verificationCode);
|
||||
Task<DateTime> GetUserTokenExpires();
|
||||
Task<bool> UpdateUsersIsDisable(List<string> userIds, bool isDisable);
|
||||
Task<bool> AddDashboardConversation(string userId, string conversationId);
|
||||
Task<bool> RemoveDashboardConversation(string userId, string conversationId);
|
||||
Task UpdateDashboardConversation(string userId, DashboardConversation dashConv);
|
||||
Task<Dashboard?> GetDashboard(string userId);
|
||||
Task<bool> AddDashboardConversation(string conversationId);
|
||||
Task<bool> RemoveDashboardConversation(string conversationId);
|
||||
Task UpdateDashboardConversation(DashboardConversation dashConv);
|
||||
Task<Dashboard?> GetDashboard();
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -810,40 +810,47 @@ public class UserService : IUserService
|
|||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> AddDashboardConversation(string userId, string conversationId)
|
||||
public async Task<bool> AddDashboardConversation(string conversationId)
|
||||
{
|
||||
var user = await GetUser(_user.Id);
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
db.AddDashboardConversation(userId, conversationId);
|
||||
|
||||
db.AddDashboardConversation(user?.Id, conversationId);
|
||||
await Task.CompletedTask;
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveDashboardConversation(string userId, string conversationId)
|
||||
public async Task<bool> RemoveDashboardConversation(string conversationId)
|
||||
{
|
||||
var user = await GetUser(_user.Id);
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
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<IBotSharpRepository>();
|
||||
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<Dashboard?> GetDashboard(string userId)
|
||||
public async Task<Dashboard?> GetDashboard()
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var dash = db.GetDashboard();
|
||||
|
||||
var user = await GetUser(_user.Id);
|
||||
var dash = db.GetDashboard(user?.Id);
|
||||
await Task.CompletedTask;
|
||||
return dash;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,16 +66,16 @@ public class AgentController : ControllerBase
|
|||
return targetAgent;
|
||||
}
|
||||
|
||||
[HttpGet("/agents")]
|
||||
public async Task<PagedItems<AgentViewModel>> GetAgents([FromQuery] AgentFilter filter, [FromQuery] bool checkAuth = false)
|
||||
[HttpPost("/agents")]
|
||||
public async Task<PagedItems<AgentViewModel>> GetAgents([FromBody] AgentQueryRequest request)
|
||||
{
|
||||
var agentSetting = _services.GetRequiredService<AgentSettings>();
|
||||
var userService = _services.GetRequiredService<IUserService>();
|
||||
|
||||
List<AgentViewModel> 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<AgentViewModel>
|
||||
|
|
|
|||
|
|
@ -535,14 +535,12 @@ public class ConversationController : ControllerBase
|
|||
}
|
||||
#endregion
|
||||
|
||||
#region miscellaneous
|
||||
#region Dashboard
|
||||
[HttpPut("/agent/{agentId}/conversation/{conversationId}/dashboard")]
|
||||
public async Task<bool> PinConversationToDashboard([FromRoute] string agentId, [FromRoute] string conversationId)
|
||||
{
|
||||
var userService = _services.GetRequiredService<IUserService>();
|
||||
|
||||
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<bool> UnpinConversationFromDashboard([FromRoute] string agentId, [FromRoute] string conversationId)
|
||||
{
|
||||
var userService = _services.GetRequiredService<IUserService>();
|
||||
|
||||
var user = await userService.GetUser(_user.Id);
|
||||
var unpinned = await userService.RemoveDashboardConversation(user.Id, conversationId);
|
||||
var unpinned = await userService.RemoveDashboardConversation(conversationId);
|
||||
return unpinned;
|
||||
}
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -19,11 +19,12 @@ public class DashboardController : ControllerBase
|
|||
}
|
||||
#region User Components
|
||||
[HttpGet("/dashboard/components")]
|
||||
public async Task<UserDashboardModel> GetComponents(string userId)
|
||||
public async Task<UserDashboardModel> GetComponents()
|
||||
{
|
||||
var userService = _services.GetRequiredService<IUserService>();
|
||||
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<IUserService>();
|
||||
await userService.UpdateDashboardConversation(userId, newDashConv);
|
||||
await userService.UpdateDashboardConversation(newDashConv);
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
namespace BotSharp.OpenAPI.ViewModels.Agents;
|
||||
|
||||
public class AgentQueryRequest
|
||||
{
|
||||
public AgentFilter Filter { get; set; } = AgentFilter.Empty();
|
||||
public bool CheckAuth { get; set; }
|
||||
}
|
||||
Loading…
Reference in a new issue