This commit is contained in:
2026-09-06 08:45:26 +03:30
parent 5d9cd2afbe
commit 7802ff9561
6 changed files with 35 additions and 211 deletions
+1 -152
View File
@@ -1,16 +1,8 @@
using System;
using AutoMapper;
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xDataService.Providers;
using System.Threading.Tasks;
using System.Collections.Generic;
using xContentService.Interfaces;
using xContentService.Models.Dtos;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xContentService.Interfaces.Dtos;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
@@ -19,156 +11,13 @@ namespace xContentService.Providers.Dtos
{
public class XContentRepositoryService : XBaseRepositoryService<XContent, XContentDto, Guid>, IXContentRepositoryService
{
private readonly IXIdentityProvider identityProvider;
private readonly IXContentTitleResourceProvider titleResourceProvider;
private readonly IXContentDescriptionResourceProvider descriptionResourceProvider;
public XContentRepositoryService(
IXContentRepository repository,
IXIdentityProvider identityProvider,
IXContentTitleResourceProvider titleResourceProvider,
IXContentDescriptionResourceProvider descriptionResourceProvider,
IEnumerable<Profile> mapperProfiles = null
) : base(
repository,
mapperProfiles
)
{
this.identityProvider = identityProvider;
this.titleResourceProvider = titleResourceProvider;
this.descriptionResourceProvider = descriptionResourceProvider;
}
//
#region Enrichers ...
/// <summary>
/// Enrich Specified Item ...
/// </summary>
/// <param name="source"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XContentDto> Enrich(
XContent source,
CancellationToken cancellationToken = default
)
{
//
// Mapping Default ...
var result = Mapper.Map<XContentDto>(source);
result = await Enrich(
source: result,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary>
/// Enrich Specified Item ...
/// </summary>
/// <param name="source"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XContentDto> Enrich(
XContentDto source,
CancellationToken cancellationToken = default
)
{
//
// Handdle Owner ...
XPersonDto owner = null;
if (!source.OwnerId.IsNullOrEmpty())
{
//
// Try to Retrieve User Info ...
var device = identityProvider.GetDevice();
var userInfo = await identityProvider.GetUserInfo(
device: device,
userSelectByParam: source.OwnerId
);
owner = userInfo.ToXPersonDto();
}
//
// Hanlde Content Title ...
string contentTitle = string.Empty;
XResourceDto titleResource = await titleResourceProvider.GetResource(
identifier: source.Id,
cancellationToken: cancellationToken
);
if (!titleResource.IsNullOrDefault())
{
contentTitle = titleResource.Resource;
}
//
// Hanlde Content Description ...
string contentDescription = string.Empty;
XResourceDto descriptionResource = await descriptionResourceProvider.GetResource(
identifier: source.Id,
cancellationToken: cancellationToken
);
if (!descriptionResource.IsNullOrDefault())
{
contentDescription = descriptionResource.Resource;
}
//
// Attach Extracted Items ...
var result = Mapper.Map<XContentDto>(source, options =>
{
//
options.Items[nameof(source.Owner)] = owner;
options.Items[nameof(source.Title)] = contentTitle;
options.Items[nameof(source.TitleResource)] = titleResource;
options.Items[nameof(source.Description)] = contentDescription;
options.Items[nameof(source.DescriptionResource)] = descriptionResource;
});
//
return result;
}
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XContentDto>> EnrichRange(
IEnumerable<XContent> sources,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(x, cancellationToken));
//
var result = await Task.WhenAll(tasks);
return result;
}
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IEnumerable<XContentDto>> EnrichRange(
IEnumerable<XContentDto> sources,
CancellationToken cancellationToken = default
)
{
//
var tasks = sources
.Select(x => Enrich(x, cancellationToken));
//
var result = await Task.WhenAll(tasks);
return result;
}
#endregion
{ }
}
}
+11
View File
@@ -15,16 +15,19 @@ namespace xContentService.Providers.Enrichers
{
public class XContentEnricher : IXContentEnricher
{
private readonly IXContentTagProvided tagProvider;
private readonly IXIdentityProvider identityProvider;
private readonly IXContentTitleResourceProvider titleResourceProvider;
private readonly IXContentDescriptionResourceProvider descriptionResourceProvider;
public XContentEnricher(
IXContentTagProvided tagProvider,
IXIdentityProvider identityProvider,
IXContentTitleResourceProvider titleResourceProvider,
IXContentDescriptionResourceProvider descriptionResourceProvider
)
{
this.tagProvider = tagProvider;
this.identityProvider = identityProvider;
this.titleResourceProvider = titleResourceProvider;
this.descriptionResourceProvider = descriptionResourceProvider;
@@ -105,10 +108,18 @@ namespace xContentService.Providers.Enrichers
contentDescription = descriptionResource.Resource;
}
//
var tags = await tagProvider.GetTags(
id: source.Id,
cancellationToken: cancellationToken
);
//
// Attach Extracted Items ...
var result = source.MapConvert();
result.Owner = owner;
result.Tags = [..tags];
result.Title = contentTitle;
result.TitleResource = titleResource;
result.Description = contentDescription;
+1 -4
View File
@@ -419,10 +419,7 @@ namespace xContentService.Providers
//
// Created On ...
if (item.CreatedOn.IsNull())
{
item.CreatedOn = DateTime.UtcNow;
}
item.CreatedOn = DateTime.UtcNow;
//
// Validate Normalized Items ...