add conv user endpoint
This commit is contained in:
parent
d305e42cac
commit
6fba6c8e76
|
|
@ -1,8 +1,6 @@
|
||||||
using BotSharp.Abstraction.Routing;
|
using BotSharp.Abstraction.Routing;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using BotSharp.Abstraction.Files.Models;
|
|
||||||
using BotSharp.Abstraction.Files;
|
|
||||||
|
|
||||||
namespace BotSharp.OpenAPI.Controllers;
|
namespace BotSharp.OpenAPI.Controllers;
|
||||||
|
|
||||||
|
|
@ -138,6 +136,34 @@ public class ConversationController : ControllerBase
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet("/conversation/{conversationId}/user")]
|
||||||
|
public async Task<UserViewModel> GetConversationUser([FromRoute] string conversationId)
|
||||||
|
{
|
||||||
|
var service = _services.GetRequiredService<IConversationService>();
|
||||||
|
var conversations = await service.GetConversations(new ConversationFilter
|
||||||
|
{
|
||||||
|
Id = conversationId
|
||||||
|
});
|
||||||
|
|
||||||
|
var userService = _services.GetRequiredService<IUserService>();
|
||||||
|
var conversation = conversations?.Items?.FirstOrDefault();
|
||||||
|
var userId = conversation == null ? _user.Id : conversation.UserId;
|
||||||
|
var user = await userService.GetUser(userId);
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return new UserViewModel
|
||||||
|
{
|
||||||
|
Id = _user.Id,
|
||||||
|
FirstName = _user.FirstName,
|
||||||
|
LastName = _user.LastName,
|
||||||
|
Email = _user.Email,
|
||||||
|
Source = "Unknown"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return UserViewModel.FromUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
[HttpDelete("/conversation/{conversationId}")]
|
[HttpDelete("/conversation/{conversationId}")]
|
||||||
public async Task<bool> DeleteConversation([FromRoute] string conversationId)
|
public async Task<bool> DeleteConversation([FromRoute] string conversationId)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue