diff --git a/Interfaces/IXAiDataProvider.cs b/Interfaces/IXAiDataProvider.cs index 217374a..eea4246 100644 --- a/Interfaces/IXAiDataProvider.cs +++ b/Interfaces/IXAiDataProvider.cs @@ -1,4 +1,5 @@ using System; +using xModels.Dtos; using System.Threading; using xAiModels.Models.Dtos; using System.Threading.Tasks; @@ -251,5 +252,51 @@ namespace xAiModels.Interfaces CancellationToken cancellationToken = default ); #endregion + + // + #region Query ... + /// + /// Query Projects ... + /// + /// + /// + /// + /// + Task> QueryProjects( + string ownerId, + XQuery query, + CancellationToken cancellationToken = default + ); + + /// + /// Query Conversations ... + /// + /// + /// + /// + /// + /// + Task> QueryConversations( + string ownerId, + Guid projectId, + XQuery query, + CancellationToken cancellationToken = default + ); + + /// + /// Query Messages ... + /// + /// + /// + /// + /// + /// + Task> QueryMessages( + string ownerId, + Guid conversationId, + XQuery query, + CancellationToken cancellationToken = default + ); + #endregion } } \ No newline at end of file diff --git a/Providers/Enrichers/XAiConversationEnricher.cs b/Providers/Enrichers/XAiConversationEnricher.cs index 9293f52..fb46308 100644 --- a/Providers/Enrichers/XAiConversationEnricher.cs +++ b/Providers/Enrichers/XAiConversationEnricher.cs @@ -134,7 +134,9 @@ namespace xAiModels.Providers.Enrichers result.Owner = owner; result.TitleResource = titleResource; result.ProjectTitleResource = projectTitleResource; + result.ProjectTitle = projectTitleResource.Resource; result.ProjectDescriptionResource = projectDescriptionResource; + result.ProjectDescription = projectDescriptionResource.Resource; // return result; diff --git a/Providers/XAiDataProvider.cs b/Providers/XAiDataProvider.cs index e0c6cb3..d5dadc5 100644 --- a/Providers/XAiDataProvider.cs +++ b/Providers/XAiDataProvider.cs @@ -10,9 +10,12 @@ using xAiModels.Models.Dtos; using xExceptions.Constants; using System.Threading.Tasks; using xCommons.Configurations; +using System.Linq.Expressions; +using xDataService.Extensions; using xAiModels.Providers.Hubs; using xAiModels.Interfaces.Dtos; using xStringService.Interfaces; +using xAiModels.Models.Entities; using System.Collections.Generic; using Microsoft.AspNetCore.SignalR; using xAiModels.Interfaces.Enrichers; @@ -1097,6 +1100,193 @@ namespace xAiModels.Providers } #endregion + // + #region Query ... + /// + /// Query Projects ... + /// + /// + /// + /// + /// + public async Task> QueryProjects( + string ownerId, + XQuery query, + CancellationToken cancellationToken = default + ) + { + // + Expression> predicate = null; + if (ownerId.IsNullOrEmpty()) + { + predicate = x => x.OwnerId == ownerId; + } + + // + var result = await projectRepositoryService.QueryAsync( + query: query, + predicate: predicate, + includeBuilder: null, + ignoreSoftDeleteds: true, + cancellationToken: cancellationToken, + orderBuilder: x => x.OrderBy(y => y.CreatedOn) + ); + if (!result.IsNullOrDefault() && + result.Items.HasChild()) + { + // + result.Items = [..await EnrichRange( + sources: result.Items, + fillConversations: false, + fillConversationMessages: false, + cancellationToken: cancellationToken + )]; + } + + // + return result; + } + + /// + /// Query Conversations ... + /// + /// + /// + /// + /// + /// + public async Task> QueryConversations( + string ownerId, + Guid projectId, + XQuery query, + CancellationToken cancellationToken = default + ) + { + // + // Validate ... + if (projectId.IsDefaultGuid()) + { + XException.InvalidArgs.Throw(); + } + + // + // Retrieve Project ... + var project = await projectRepositoryService.GetAsync( + id: projectId, + includeBuilder: null, + ignoreSoftDeleteds: true, + cancellationToken: cancellationToken + ); + if (project.IsNullOrDefault()) + { + XException.NotFound.Throw(); + } + + // + Expression> predicate = x => + x.ProjectId == projectId; + if (ownerId.IsNullOrEmpty()) + { + // + predicate = x => + x.OwnerId == ownerId && + x.ProjectId == projectId; + } + + // + var result = await conversationRepositoryService.QueryAsync( + query: query, + predicate: predicate, + includeBuilder: null, + ignoreSoftDeleteds: true, + cancellationToken: cancellationToken, + orderBuilder: x => x.OrderBy(y => y.CreatedOn) + ); + if (!result.IsNullOrDefault() && + result.Items.HasChild()) + { + // + result.Items = [..await EnrichRange( + fillMessages: false, + sources: result.Items, + cancellationToken: cancellationToken + )]; + } + + // + return result; + } + + /// + /// Query Messages ... + /// + /// + /// + /// + /// + /// + public async Task> QueryMessages( + string ownerId, + Guid conversationId, + XQuery query, + CancellationToken cancellationToken = default + ) + { + // + // Validate ... + if (conversationId.IsDefaultGuid()) + { + XException.InvalidArgs.Throw(); + } + + // + // Retrieve Conversation ... + var conversation = await conversationRepositoryService.GetAsync( + id: conversationId, + includeBuilder: null, + ignoreSoftDeleteds: true, + cancellationToken: cancellationToken + ); + if (conversation.IsNullOrDefault()) + { + XException.NotFound.Throw(); + } + + // + Expression> predicate = x => + x.ConversationId == conversationId; + if (ownerId.IsNullOrEmpty()) + { + // + predicate = x => + x.OwnerId == ownerId && + x.ConversationId == conversationId; + } + + // + var result = await messageRepositoryService.QueryAsync( + query: query, + predicate: predicate, + includeBuilder: null, + ignoreSoftDeleteds: true, + cancellationToken: cancellationToken, + orderBuilder: x => x.OrderBy(y => y.CreatedOn) + ); + if (!result.IsNullOrDefault() && + result.Items.HasChild()) + { + // + result.Items = [..await EnrichRange( + sources: result.Items, + cancellationToken: cancellationToken + )]; + } + + // + return result; + } + #endregion + // #region Enrichers ... ///