2024-11-07 15:12:10 +00:00
|
|
|
using BotSharp.Abstraction.Options;
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.OpenAPI.Controllers;
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class DashboardController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _services;
|
|
|
|
|
private readonly IUserIdentity _user;
|
|
|
|
|
|
|
|
|
|
public DashboardController(IServiceProvider services,
|
|
|
|
|
IUserIdentity user,
|
|
|
|
|
BotSharpOptions options)
|
|
|
|
|
{
|
|
|
|
|
_services = services;
|
|
|
|
|
_user = user;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#region User Components
|
|
|
|
|
[HttpGet("/dashboard/components")]
|
2025-01-31 20:49:38 +00:00
|
|
|
public async Task<UserDashboardModel> GetComponents()
|
2024-11-07 15:12:10 +00:00
|
|
|
{
|
|
|
|
|
var userService = _services.GetRequiredService<IUserService>();
|
2025-01-31 20:49:38 +00:00
|
|
|
var dashboardProfile = await userService.GetDashboard();
|
2024-11-07 15:12:10 +00:00
|
|
|
if (dashboardProfile == null) return new UserDashboardModel();
|
2025-01-31 20:49:38 +00:00
|
|
|
|
2024-11-07 15:12:10 +00:00
|
|
|
var result = new UserDashboardModel
|
|
|
|
|
{
|
|
|
|
|
ConversationList = dashboardProfile.ConversationList.Select(
|
|
|
|
|
x => new UserDashboardConversationModel
|
|
|
|
|
{
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
ConversationId = x.ConversationId,
|
|
|
|
|
Instruction = x.Instruction
|
|
|
|
|
}
|
|
|
|
|
).ToList()
|
|
|
|
|
};
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2024-11-21 19:07:00 +00:00
|
|
|
|
|
|
|
|
[HttpPost("/dashboard/component/conversation")]
|
2025-01-31 20:49:38 +00:00
|
|
|
public async Task UpdateDashboardConversationInstruction(UserDashboardConversationModel dashConv)
|
2024-11-21 19:07:00 +00:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(dashConv.Name) && string.IsNullOrEmpty(dashConv.Instruction))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var newDashConv = new DashboardConversation
|
|
|
|
|
{
|
|
|
|
|
Id = Guid.Empty.ToString(),
|
|
|
|
|
ConversationId = dashConv.ConversationId
|
|
|
|
|
};
|
|
|
|
|
if (!string.IsNullOrEmpty(dashConv.Name))
|
|
|
|
|
{
|
|
|
|
|
newDashConv.Name = dashConv.Name;
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrEmpty(dashConv.Instruction))
|
|
|
|
|
{
|
|
|
|
|
newDashConv.Instruction = dashConv.Instruction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userService = _services.GetRequiredService<IUserService>();
|
2025-01-31 20:49:38 +00:00
|
|
|
await userService.UpdateDashboardConversation(newDashConv);
|
2024-11-21 19:07:00 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2024-11-07 15:12:10 +00:00
|
|
|
#endregion
|
|
|
|
|
}
|