last ...
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using xModels.Dtos;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using xAiModels.Models.Dtos;
|
using xAiModels.Models.Dtos;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -251,5 +252,51 @@ namespace xAiModels.Interfaces
|
|||||||
CancellationToken cancellationToken = default
|
CancellationToken cancellationToken = default
|
||||||
);
|
);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Query ...
|
||||||
|
/// <summary>
|
||||||
|
/// Query Projects ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XAiProjectDto>> QueryProjects(
|
||||||
|
string ownerId,
|
||||||
|
XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Conversations ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XAiConversationDto>> QueryConversations(
|
||||||
|
string ownerId,
|
||||||
|
Guid projectId,
|
||||||
|
XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Messages ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<XQueryResult<XAiMessageDto>> QueryMessages(
|
||||||
|
string ownerId,
|
||||||
|
Guid conversationId,
|
||||||
|
XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
);
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,9 @@ namespace xAiModels.Providers.Enrichers
|
|||||||
result.Owner = owner;
|
result.Owner = owner;
|
||||||
result.TitleResource = titleResource;
|
result.TitleResource = titleResource;
|
||||||
result.ProjectTitleResource = projectTitleResource;
|
result.ProjectTitleResource = projectTitleResource;
|
||||||
|
result.ProjectTitle = projectTitleResource.Resource;
|
||||||
result.ProjectDescriptionResource = projectDescriptionResource;
|
result.ProjectDescriptionResource = projectDescriptionResource;
|
||||||
|
result.ProjectDescription = projectDescriptionResource.Resource;
|
||||||
|
|
||||||
//
|
//
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -10,9 +10,12 @@ using xAiModels.Models.Dtos;
|
|||||||
using xExceptions.Constants;
|
using xExceptions.Constants;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using xCommons.Configurations;
|
using xCommons.Configurations;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using xDataService.Extensions;
|
||||||
using xAiModels.Providers.Hubs;
|
using xAiModels.Providers.Hubs;
|
||||||
using xAiModels.Interfaces.Dtos;
|
using xAiModels.Interfaces.Dtos;
|
||||||
using xStringService.Interfaces;
|
using xStringService.Interfaces;
|
||||||
|
using xAiModels.Models.Entities;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using xAiModels.Interfaces.Enrichers;
|
using xAiModels.Interfaces.Enrichers;
|
||||||
@@ -1097,6 +1100,193 @@ namespace xAiModels.Providers
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
//
|
||||||
|
#region Query ...
|
||||||
|
/// <summary>
|
||||||
|
/// Query Projects ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XAiProjectDto>> QueryProjects(
|
||||||
|
string ownerId,
|
||||||
|
XQuery query,
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Expression<Func<XAiProject, bool>> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Conversations ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="projectId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XAiConversationDto>> 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<Func<XAiConversation, bool>> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query Messages ...
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ownerId"></param>
|
||||||
|
/// <param name="conversationId"></param>
|
||||||
|
/// <param name="query"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<XQueryResult<XAiMessageDto>> 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<Func<XAiMessage, bool>> 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 ...
|
#region Enrichers ...
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user