From 0077008105c12f9fb8d8e9f22c1140d1ec2da126 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 10 Nov 2026 17:29:59 +0330 Subject: [PATCH] last ... --- Controllers/XAiServiceControllerBase.cs | 97 +++++++++++++++++++++---- Interfaces/IXAiServiceBase.cs | 10 ++- Providers/XAIServiceBase.cs | 28 +++---- 3 files changed, 104 insertions(+), 31 deletions(-) diff --git a/Controllers/XAiServiceControllerBase.cs b/Controllers/XAiServiceControllerBase.cs index 0497a23..2acd9e9 100644 --- a/Controllers/XAiServiceControllerBase.cs +++ b/Controllers/XAiServiceControllerBase.cs @@ -636,7 +636,7 @@ namespace xAiApi.Controllers [Authorize(Policy = XPolicies.EnabledUser)] [HttpGet("Projects/{projectId}/Conversations")] public async Task>> LoadConversations( - [FromRoute] Guid projectId, + [FromRoute] Guid? projectId, CancellationToken cancellationToken = default ) { @@ -644,12 +644,44 @@ namespace xAiApi.Controllers try { // - // Validate ... - if (projectId.IsDefaultGuid()) - { - XException.InvalidArgs.Throw(); - } + var userInfo = await GetUserInfo(); + var connectionId = GetConnectionId(); + // + var result = await aiService.LoadConversations( + projectId: projectId, + ownerId: userInfo.UserId, + connectionId: connectionId, + cancellationToken: cancellationToken + ); + + // + return Ok(result); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Retrieve Specified AI Project's Conversations ... + /// + /// + /// + /// + [Authorize(Policy = XPolicies.EnabledUser)] + [HttpGet("Projects/Conversations")] + public async Task>> LoadProjectConversations( + [FromQuery] Guid? projectId, + CancellationToken cancellationToken = default + ) + { + // + try + { // var userInfo = await GetUserInfo(); var connectionId = GetConnectionId(); @@ -657,6 +689,7 @@ namespace xAiApi.Controllers // var result = await aiService.LoadConversations( projectId: projectId, + ownerId: userInfo.UserId, connectionId: connectionId, cancellationToken: cancellationToken ); @@ -681,7 +714,7 @@ namespace xAiApi.Controllers [Authorize(Policy = XPolicies.EnabledUser)] [HttpGet("Conversations/{conversationId}/Messages")] public async Task>> LoadMessages( - [FromRoute] Guid conversationId, + [FromRoute] Guid? conversationId, CancellationToken cancellationToken = default ) { @@ -689,14 +722,52 @@ namespace xAiApi.Controllers try { // - // Validate ... - if (conversationId.IsDefaultGuid()) - { - XException.InvalidArgs.Throw(); - } - + var userInfo = await GetUserInfo(); + var connectionId = GetConnectionId(); + // var result = await aiService.LoadMessages( + ownerId: userInfo.UserId, + connectionId: connectionId, + conversationId: conversationId, + cancellationToken: cancellationToken + ); + + // + return Ok(result); + } + catch (Exception ex) + { + // + var result = GetExceptionActionResult(ex); + return result; + } + } + + /// + /// Retrieve Specified AI Conversation's Messages ... + /// + /// + /// + /// + [Authorize(Policy = XPolicies.EnabledUser)] + [HttpGet("Conversations/Messages")] + public async Task>> LoadConversationMessages( + [FromQuery] Guid? conversationId, + CancellationToken cancellationToken = default + ) + { + // + try + { + // + var userInfo = await GetUserInfo(); + var connectionId = GetConnectionId(); + + // + var result = await aiService.LoadMessages( + ownerId: userInfo.UserId, + connectionId: connectionId, conversationId: conversationId, cancellationToken: cancellationToken ); diff --git a/Interfaces/IXAiServiceBase.cs b/Interfaces/IXAiServiceBase.cs index 46a48cc..6b54fad 100644 --- a/Interfaces/IXAiServiceBase.cs +++ b/Interfaces/IXAiServiceBase.cs @@ -206,11 +206,13 @@ namespace xAiApi.Interfaces /// Load Conversations of Specified AI Project ... /// /// + /// /// /// /// Task> LoadConversations( - Guid projectId, + Guid? projectId, + string ownerId = null, string connectionId = null, CancellationToken cancellationToken = default ); @@ -219,10 +221,14 @@ namespace xAiApi.Interfaces /// Load Messages of Specified Conversation ... /// /// + /// + /// /// /// Task> LoadMessages( - Guid conversationId, + Guid? conversationId, + string ownerId = null, + string connectionId = null, CancellationToken cancellationToken = default ); #endregion diff --git a/Providers/XAIServiceBase.cs b/Providers/XAIServiceBase.cs index b5a75ed..cd5d1ab 100644 --- a/Providers/XAIServiceBase.cs +++ b/Providers/XAIServiceBase.cs @@ -27,6 +27,7 @@ using System.Collections.Generic; using Microsoft.Extensions.Logging; using xAiApi.Interfaces.Extractors; using System.Runtime.CompilerServices; +using MongoDB.Driver.Core.Connections; namespace xAiApi.Providers { @@ -836,24 +837,20 @@ namespace xAiApi.Providers /// Load Conversations of Specified AI Project ... /// /// + /// /// /// /// public virtual async Task> LoadConversations( - Guid projectId, + Guid? projectId, + string ownerId = null, string connectionId = null, CancellationToken cancellationToken = default ) { - // - // Validate Args ... - if (projectId.IsDefaultGuid()) - { - XException.InvalidArgs.Throw(); - } - // var result = await dataProvider.LoadConversations( + ownerId: ownerId, fillMessages: false, projectId: projectId, connectionId: connectionId, @@ -868,22 +865,21 @@ namespace xAiApi.Providers /// Load Messages of Specified Conversation ... /// /// + /// + /// /// /// public virtual async Task> LoadMessages( - Guid conversationId, + Guid? conversationId, + string ownerId = null, + string connectionId = null, CancellationToken cancellationToken = default ) { - // - // Validate Args ... - if (conversationId.IsDefaultGuid()) - { - XException.InvalidArgs.Throw(); - } - // var result = await dataProvider.LoadMessages( + ownerId: ownerId, + connectionId: connectionId, conversationId: conversationId, cancellationToken: cancellationToken );