apply fix on Models Enrichments ...
This commit is contained in:
@@ -1,30 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.Query;
|
||||
using xAiModels.Configurations;
|
||||
using xAiModels.Interfaces.Dtos;
|
||||
using xAiModels.Interfaces.Enrichers;
|
||||
using xAiModels.Interfaces.Entities;
|
||||
using xAiModels.Models.Dtos;
|
||||
using xAiModels.Models.Entities;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Providers;
|
||||
using xIdentityService.Interfaces;
|
||||
using xIdentityService.Extensions;
|
||||
using xModels.Dtos;
|
||||
using xAiModels.Interfaces;
|
||||
|
||||
namespace xAiModels.Providers.Dtos
|
||||
{
|
||||
public class XAiConversationRepositoryService : XBaseRepositoryService<XAiConversation, XAiConversationDto, Guid>, IXAiConversationRepositoryService
|
||||
{
|
||||
private readonly IXAiConversationEnricher enricher;
|
||||
private readonly IXIdentityProvider identityProvider;
|
||||
private readonly IXAiConversationRepository repository;
|
||||
private readonly IXAiProjectTitleResourceProvider projectTitleResourceProvider;
|
||||
private readonly IXAiConversationTitleResourceProvider conversationTitleResourceProvider;
|
||||
private readonly IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider;
|
||||
|
||||
public XAiConversationRepositoryService(
|
||||
IXAiConversationEnricher enricher,
|
||||
IXAiConversationRepository repository
|
||||
IXIdentityProvider identityProvider,
|
||||
IXAiConversationRepository repository,
|
||||
IXAiProjectTitleResourceProvider projectTitleResourceProvider,
|
||||
IXAiConversationTitleResourceProvider conversationTitleResourceProvider,
|
||||
IXAiProjectDescriptionResourceProvider projectDescriptionResourceProvider
|
||||
) : base(
|
||||
repository,
|
||||
mapperProfiles:
|
||||
@@ -33,771 +39,169 @@ namespace xAiModels.Providers.Dtos
|
||||
]
|
||||
)
|
||||
{
|
||||
this.enricher = enricher;
|
||||
this.repository = repository;
|
||||
this.identityProvider = identityProvider;
|
||||
this.projectTitleResourceProvider = projectTitleResourceProvider;
|
||||
this.conversationTitleResourceProvider = conversationTitleResourceProvider;
|
||||
this.projectDescriptionResourceProvider = projectDescriptionResourceProvider;
|
||||
}
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
#region Add ...
|
||||
#region Enrichers ...
|
||||
/// <summary>
|
||||
/// add a new Dto ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> AddAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await AddAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add or update a Dto (add if not exists/update if exists) ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> AddOrUpdateAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await AddOrUpdateAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
/// <summary>
|
||||
/// Update an Dto values ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> UpdateAsync(
|
||||
Guid id,
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await UpdateAsync(
|
||||
id: id,
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Remove ...
|
||||
/// <summary>
|
||||
/// remove an Dto by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> RemoveAsync(
|
||||
Guid id,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await RemoveAsync(
|
||||
id: id,
|
||||
fillMessages: false,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// remove an Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> RemoveAsync(
|
||||
XAiConversationDto item,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await RemoveAsync(
|
||||
item: item,
|
||||
fillMessages: false,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrieve ...
|
||||
/// <summary>
|
||||
/// retrieve an Dto by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> GetAsync(
|
||||
Guid id,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await GetAsync(
|
||||
id: id,
|
||||
fillMessages: false,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IEnumerable<XAiConversationDto>> GetAllAsync(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await GetAllAsync(
|
||||
fillMessages: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos
|
||||
/// as Async Enumerable ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override IAsyncEnumerable<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return GetAllAsAsyncEnumerable(
|
||||
fillMessages: false,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find an Dto by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XAiConversationDto> FindOneAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await FindOneAsync(
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find a collection of Dtos by proving a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<IEnumerable<XAiConversationDto>> FindManyAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await FindManyAsync(
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Dtos based on XQuery Pagination structure ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<XQueryResult<XAiConversationDto>> QueryAsync(
|
||||
XQuery query,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Expression<Func<XAiConversation, bool>> predicate = null,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
return await QueryAsync(
|
||||
query: query,
|
||||
fillMessages: false,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Actions ...
|
||||
//
|
||||
#region Add ...
|
||||
/// <summary>
|
||||
/// add a new Dto ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> AddAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
public virtual async Task<XAiConversationDto> Enrich(
|
||||
XAiConversation source,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
// Mapping Default ...
|
||||
var result = Mapper.Map<XAiConversationDto>(source);
|
||||
result = await Enrich(
|
||||
source: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add or update a Dto (add if not exists/update if exists) ...
|
||||
/// Enrich Specified Item ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> AddOrUpdateAsync(
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
public virtual async Task<XAiConversationDto> Enrich(
|
||||
XAiConversationDto source,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.AddAsync(
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
// Handdle Owner ...
|
||||
XPersonDto owner = null;
|
||||
if (!source.OwnerId.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
// Try to Retrieve User Info ...
|
||||
var device = identityProvider.GetDevice();
|
||||
var userInfo = await identityProvider.GetUserInfo(
|
||||
device: device,
|
||||
userSelectByParam: source.OwnerId
|
||||
);
|
||||
owner = userInfo.ToXPersonDto();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Title Resource ...
|
||||
XResourceDto titleResource = null;
|
||||
if (!source.Title.IsNullOrEmpty())
|
||||
{
|
||||
//
|
||||
titleResource = await conversationTitleResourceProvider.GetResource(
|
||||
owner: source.OwnerId,
|
||||
identifier: source.Id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Update ...
|
||||
/// <summary>
|
||||
/// Update an Dto values ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> UpdateAsync(
|
||||
Guid id,
|
||||
XAiConversationDto item,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.UpdateAsync(
|
||||
id: id,
|
||||
item: item,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
// Handle Project Info ...
|
||||
XResourceDto projectTitleResource = null;
|
||||
XResourceDto projectDescriptionResource = null;
|
||||
if (!source.ProjectId.IsDefaultGuid())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
projectTitleResource = await projectTitleResourceProvider.GetResource(
|
||||
owner: source.OwnerId,
|
||||
identifier: source.ProjectId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
projectDescriptionResource = await projectDescriptionResourceProvider.GetResource(
|
||||
owner: source.OwnerId,
|
||||
identifier: source.ProjectId,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Remove ...
|
||||
/// <summary>
|
||||
/// remove an Dto by it's Id ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> RemoveAsync(
|
||||
Guid id,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.RemoveAsync(
|
||||
id: id,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
// Attach Extracted Items ...
|
||||
var result = Mapper.Map<XAiConversationDto>(source, options =>
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
options.Items[nameof(source.Owner)] = owner;
|
||||
options.Items[nameof(source.TitleResource)] = titleResource;
|
||||
options.Items[nameof(source.ProjectTitleResource)] = projectTitleResource;
|
||||
options.Items[nameof(source.ProjectDescriptionResource)] = projectDescriptionResource;
|
||||
});
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// remove an Dto ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="softDelete"></param>
|
||||
/// <param name="saveChanges"></param>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> RemoveAsync(
|
||||
XAiConversationDto item,
|
||||
bool softDelete = true,
|
||||
bool saveChanges = true,
|
||||
bool fillMessages = true,
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> EnrichRange(
|
||||
IEnumerable<XAiConversation> sources,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.RemoveAsync(
|
||||
item: item,
|
||||
softDelete: softDelete,
|
||||
saveChanges: saveChanges,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(
|
||||
source: x,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Retrieve ...
|
||||
/// <summary>
|
||||
/// retrieve an Dto by it's Id ...
|
||||
/// Enrich Specified Items ...
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="sources"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> GetAsync(
|
||||
Guid id,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> EnrichRange(
|
||||
IEnumerable<XAiConversationDto> sources,
|
||||
bool fillMessages = false,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.GetAsync(
|
||||
id: id,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
var tasks = sources
|
||||
.Select(x => Enrich(
|
||||
source: x,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
));
|
||||
|
||||
//
|
||||
var result = await Task.WhenAll(tasks);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> GetAllAsync(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.GetAllAsync(
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result,
|
||||
destinations: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve all exists Dtos
|
||||
/// as Async Enumerable ...
|
||||
/// </summary>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async IAsyncEnumerable<XAiConversationDto> GetAllAsAsyncEnumerable(
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var enumerable = base.GetAllAsAsyncEnumerable(
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
await foreach (var dto in enumerable)
|
||||
{
|
||||
//
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: dto,
|
||||
destination: dto,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
yield return dto;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find an Dto by providing a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XAiConversationDto> FindOneAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.FindOneAsync(
|
||||
predicate: predicate,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichAsync(
|
||||
source: result,
|
||||
destination: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find a collection of Dtos by proving a Conditional Expression ...
|
||||
/// </summary>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<IEnumerable<XAiConversationDto>> FindManyAsync(
|
||||
Expression<Func<XAiConversation, bool>> predicate,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.FindManyAsync(
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result,
|
||||
destinations: result,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// retrieve Dtos based on XQuery Pagination structure ...
|
||||
/// </summary>
|
||||
/// <param name="query"></param>
|
||||
/// <param name="ignoreSoftDeleteds"></param>
|
||||
/// <param name="predicate"></param>
|
||||
/// <param name="orderBuilder"></param>
|
||||
/// <param name="includeBuilder"></param>
|
||||
/// <param name="fillMessages"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public virtual async Task<XQueryResult<XAiConversationDto>> QueryAsync(
|
||||
XQuery query,
|
||||
bool ignoreSoftDeleteds = true,
|
||||
Expression<Func<XAiConversation, bool>> predicate = null,
|
||||
Func<IQueryable<XAiConversation>, IOrderedQueryable<XAiConversation>> orderBuilder = null,
|
||||
Func<IQueryable<XAiConversation>, IIncludableQueryable<XAiConversation, object>> includeBuilder = null,
|
||||
bool fillMessages = true,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = await base.QueryAsync(
|
||||
query: query,
|
||||
predicate: predicate,
|
||||
orderBuilder: orderBuilder,
|
||||
includeBuilder: includeBuilder,
|
||||
cancellationToken: cancellationToken,
|
||||
ignoreSoftDeleteds: ignoreSoftDeleteds
|
||||
);
|
||||
|
||||
//
|
||||
// Do Enrichment if result Exists ...
|
||||
if (!result.IsNullOrDefault())
|
||||
{
|
||||
//
|
||||
await enricher.EnrichRangeAsync(
|
||||
sources: result.Items,
|
||||
destinations: result.Items,
|
||||
fillMessages: fillMessages,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user