Compare commits

...
8 Commits
Author SHA1 Message Date
saherelm 18bd6b462e last ... 2026-09-25 19:47:51 +03:30
saherelm 7802ff9561 last ... 2026-09-06 08:45:26 +03:30
saherelm 5d9cd2afbe apply sorting ... 2026-09-06 00:18:57 +03:30
saherelm 5739b968aa add requirements in Content Service ... 2026-09-05 10:24:19 +03:30
saherelm 903703dca0 add support tags ... 2026-09-04 01:35:15 +03:30
saherelm 92d7948c35 last works on content ... 2026-09-03 23:59:05 +03:30
saherelm d9ac3f4506 kast ... 2026-09-03 10:39:34 +03:30
saherelm 0daa339d12 adding Data Requirement on XContent Service ... 2026-08-18 14:05:36 +03:30
52 changed files with 2471 additions and 4 deletions
@@ -0,0 +1,17 @@
using System;
using xDataService.Providers;
using xContentService.Constants;
using Microsoft.EntityFrameworkCore;
using xContentService.Models.Entities;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace xContentService.Configuration.Entities
{
public class XContentEntityConfiguration : XBaseEntityTypeConfiguration<XContent, Guid>
{
public override void Configure(EntityTypeBuilder<XContent> builder)
{
builder.ToTable(XContentServiceConstants.XContentTable);
}
}
}
+15
View File
@@ -1,3 +1,5 @@
using xContentService.Models.Entities;
namespace xContentService.Constants
{
public struct XContentServiceConstants
@@ -19,5 +21,18 @@ namespace xContentService.Constants
// Hubs ...
public const string XContentDtoHub = "contentDto";
public const string XContentEntityHub = "contentEntity";
//
// EF Repositories Helper Extensions ...
public const string GetXContentEFRepositoryDescriptor = "GetXContentEFRepositoryDescriptor";
//
// Custome Constants ...
public const string XAdminRole = "admin";
public const string XContentTagProvided = nameof(XContent);
public const string XContentTitleIdentifier = "CntnT";
public const string XContentDescriptionIdentifier = "CntnD";
}
}
@@ -0,0 +1,33 @@
using System;
using System.Linq;
using xCommons.Providers;
using xCommons.Configurations;
using xDataService.Interfaces;
using xDataService.Controllers;
using Microsoft.Extensions.Logging;
using xContentService.Models.Entities;
using Microsoft.EntityFrameworkCore.Query;
using xContentService.Interfaces.Entities;
namespace xContentService.Controllers
{
public abstract class XContentRepositoryControllerBase : XBaseRepositoryController<XContent, Guid>, IXBaseRepositoryController<XContent, Guid>
{
protected XContentRepositoryControllerBase(
ILogger<XContentRepositoryControllerBase> logger,
XAppConfiguration appConfiguration,
XValidationProvider validationProvider,
IXContentRepository repository,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> defaultOrderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
validationProvider,
repository,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
@@ -0,0 +1,36 @@
using System;
using System.Linq;
using xCommons.Providers;
using xPushService.Interfaces;
using xCommons.Configurations;
using xPushService.Controllers;
using xIdentityService.Interfaces;
using Microsoft.Extensions.Logging;
using xContentService.Models.Entities;
using xContentService.Providers.Entities;
using Microsoft.EntityFrameworkCore.Query;
using xContentService.Interfaces.Entities;
namespace xContentService.Controllers
{
public abstract class XContentRepositoryProviderControllerBase : XBaseRepositoryProviderController<XContent, Guid, XContentEntityHub>, IXBaseRepositoryProviderController<XContent, Guid, XContentEntityHub>
{
protected XContentRepositoryProviderControllerBase(
ILogger<XContentRepositoryProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXContentRepositoryProvider provider,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> defaultOrderBuilder = null, Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
@@ -0,0 +1,34 @@
using System;
using System.Linq;
using xCommons.Providers;
using xCommons.Configurations;
using xDataService.Interfaces;
using xDataService.Controllers;
using xContentService.Models.Dtos;
using Microsoft.Extensions.Logging;
using xContentService.Models.Entities;
using xContentService.Interfaces.Dtos;
using Microsoft.EntityFrameworkCore.Query;
namespace xContentService.Controllers
{
public abstract class XContentServiceControllerBase : XBaseServiceController<XContent, XContentDto, Guid>, IXBaseServiceController<XContent, XContentDto, Guid>
{
protected XContentServiceControllerBase(
ILogger<XContentServiceControllerBase> logger,
XAppConfiguration appConfiguration,
XValidationProvider validationProvider,
IXContentRepositoryService repositoryService,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> defaultOrderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
validationProvider,
repositoryService,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
@@ -0,0 +1,38 @@
using System;
using System.Linq;
using xCommons.Providers;
using xCommons.Configurations;
using xPushService.Interfaces;
using xPushService.Controllers;
using xContentService.Models.Dtos;
using xIdentityService.Interfaces;
using Microsoft.Extensions.Logging;
using xContentService.Providers.Dtos;
using xContentService.Models.Entities;
using xContentService.Interfaces.Dtos;
using Microsoft.EntityFrameworkCore.Query;
namespace xContentService.Controllers
{
public abstract class XContentServiceProviderControllerBase : XBaseServiceProviderController<XContent, XContentDto, Guid, XContentDtoHub>, IXBaseServiceProviderController<XContent, XContentDto, Guid, XContentDtoHub>
{
protected XContentServiceProviderControllerBase(
ILogger<XContentServiceProviderControllerBase> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXContentServiceProvider provider,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> defaultOrderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
defaultOrderBuilder,
defaultIncludeBuilder
)
{ }
}
}
@@ -0,0 +1,113 @@
using System;
using System.Linq;
using System.Threading;
using xCommons.Providers;
using xCommons.Extensions;
using xExceptions.Constants;
using System.Threading.Tasks;
using xCommons.Configurations;
using xTagService.Controllers;
using Microsoft.AspNetCore.Mvc;
using xContentService.Interfaces;
using xContentService.Models.Dtos;
using xIdentityService.Interfaces;
using Microsoft.Extensions.Logging;
using xContentService.Providers.Dtos;
using xContentService.Models.Entities;
using Microsoft.EntityFrameworkCore.Query;
using xContentService.Interfaces.Controllers;
namespace xContentService.Controllers
{
public abstract class XContentProviderControllerBase : XBaseProvidedHasTagControllerBase<XContent, XContentDto, Guid, XContentDtoHub>, IXContentProviderController
{
private readonly IXContentProvider provider;
protected XContentProviderControllerBase(
ILogger<XBaseProvidedHasTagControllerBase<XContent, XContentDto, Guid, XContentDtoHub>> logger,
XAppConfiguration appConfiguration,
IXIdentityProvider identityProvider,
XValidationProvider validationProvider,
IXContentProvider provider,
IXContentTagProvided tagProvided,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> defaultOrderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> defaultIncludeBuilder = null
) : base(
logger,
appConfiguration,
identityProvider,
validationProvider,
provider,
tagProvided,
defaultOrderBuilder,
defaultIncludeBuilder
)
{
this.provider = provider;
}
/// <summary>
/// Add an item ...
/// </summary>
/// <param name="item"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Add")]
public async Task<ActionResult<XContentDto>> Add(
[FromBody] XContentDto item,
[FromQuery] string language = null,
CancellationToken cancellationToken = default
)
{
//
try
{
//
// Validate ...
if (!ModelState.IsValid)
{
XException.InvalidArgs.Throw();
}
await ValidationProvider
.GroupValidationBuilder()
.AddNotNull(item)
.AddNotEmpty(item.Title)
.ValidateGroupAsync();
//
var userInfo = await GetUserInfo();
var connectionId = GetConnectionId();
//
// Normalize Language ...
if (language.IsNullOrEmpty())
{
language = AppConfiguration.DefaultLanguage;
}
if (language.IsNullOrEmpty())
{
XException.InvalidData.Throw();
}
//
var result = await provider.Add(
item: item,
userInfo: userInfo,
language: language,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
return result;
}
catch (Exception ex)
{
//
var result = GetExceptionActionResult(ex);
return result;
}
}
}
}
+259
View File
@@ -0,0 +1,259 @@
using System;
using xPushService.DI;
using xDataService.DI;
using xDataService.Db;
using xCommons.Helpers;
using xDataService.Models;
using xCommons.Extensions;
using xPushService.Helpers;
using xExceptions.Constants;
using xDataService.Constants;
using xContentService.Helpers;
using xContentService.Constants;
using xContentService.Providers;
using xContentService.Interfaces;
using Microsoft.AspNetCore.Builder;
using xContentService.Providers.Dtos;
using xContentService.Interfaces.Dtos;
using xContentService.Providers.Entities;
using xContentService.Interfaces.Entities;
using xContentService.Providers.Enrichers;
using xContentService.Interfaces.Enrichers;
using Microsoft.Extensions.DependencyInjection;
namespace xContentService.DI
{
/// <summary>
/// Service Registration Extensions Classes ...
/// </summary>
public static partial class XDIHelperExtensions
{
/// <summary>
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXContentService(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
AddContentService(
contextType: null,
services: services,
lifeTime: lifeTime,
repositoryType: repositoryType
);
}
/// <summary>
/// Register Service ...
/// </summary>
/// <typeparam name="TContext"></typeparam>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="lifeTime"></param>
public static void AddXContentService<TContext>(
this IServiceCollection services,
XRepositoryType repositoryType,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
where TContext : XDbContext
{
AddContentService(
services: services,
lifeTime: lifeTime,
contextType: typeof(TContext),
repositoryType: repositoryType
);
}
/// <summary>
/// Use xContentService Middleware ...
/// </summary>
/// <param name="app"></param>
/// <param name="isDevelopmentEnvironment"></param>
public static void UseXContentService(
this IApplicationBuilder app,
bool isDevelopmentEnvironment = false
)
{
//
#region Using XContent Hubs ...
//
var pushHelper = new XPushServiceHelper();
//
pushHelper.AddHub<XContentDtoHub>(XContentServiceConstants.XContentDtoHub);
pushHelper.AddHub<XContentEntityHub>(XContentServiceConstants.XContentEntityHub);
//
app.UseXPushService(pushHelper);
#endregion
//
// Using XContent Repository Descriptor ...
if (!descriptor.IsNull())
{
//
app.UseXRepository(
descriptor: descriptor,
isDevelopmentEnvironment: isDevelopmentEnvironment
);
}
}
//
#region Private ...
private static XRepositoryDescriptor descriptor = null;
/// <summary>
/// a LogTag for Service ...
/// </summary>
private static string XLogTag = XContentServiceConstants.XContentServiceDILogTag;
/// <summary>
/// print a log in Console ...
/// </summary>
/// <param name="message"></param>
private static void Log(string message)
{
Console.WriteLine($"{XLogTag} => {message}");
}
/// <summary>
/// Register Service ...
/// </summary>
/// <param name="services"></param>
/// <param name="repositoryType"></param>
/// <param name="contextType"></param>
/// <param name="lifeTime"></param>
private static void AddContentService(
IServiceCollection services,
XRepositoryType repositoryType,
Type contextType = null,
ServiceLifetime lifeTime = ServiceLifetime.Scoped
)
{
//
var exception = XException.InvalidArgs.ToException(); ;
//
// Services ...
var isServicesExists = !services.IsNull();
if (!isServicesExists)
{
//
Log("Service Registration failed, services not provided ...");
throw exception;
}
//
// Lifetime ...
var isLifetimeExists = !lifeTime.IsNull();
if (!isLifetimeExists)
{
//
Log("Service Registration failed, lifetime not provided ...");
throw exception;
}
//
// Validate Repository Type ...
var isRepositoryTypeValid =
(repositoryType == XRepositoryType.EF &&
!contextType.IsNull()) ||
((repositoryType == XRepositoryType.Mongo ||
repositoryType == XRepositoryType.InMemory) &&
contextType.IsNull());
if (!isRepositoryTypeValid)
{
//
Log("Service Registration failed, Invalid Repository Type and Context Type ...");
throw exception;
}
//
// Maske Instance of Repository Descriptor
// Based on Provided Type ...
switch (repositoryType)
{
//
case XRepositoryType.EF:
//
descriptor = typeof(XContentServiceHelper)
.InvokeGenericMethod<XRepositoryDescriptor>(
args: null,
runtimeType: contextType,
methodName: XContentServiceConstants.GetXContentEFRepositoryDescriptor
);
break;
//
case XRepositoryType.Mongo:
descriptor = XContentServiceHelper.GetXContentMongoRepositoryDescriptor();
break;
//
case XRepositoryType.InMemory:
descriptor = XContentServiceHelper.GetXContentInMemoryRepositoryDescriptor();
break;
}
//
// Register XContent Repository Descriptor ...
services.AddXRepository(
lifeTime: lifeTime,
descriptor: descriptor
);
//
// Resource Providers ...
services.Add(
new ServiceDescriptor(typeof(IXContentTitleResourceProvider), typeof(XContentTitleResourceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXContentDescriptionResourceProvider), typeof(XContentDescriptionResourceProvider), lifeTime)
);
//
// Enrichers ...
services.Add(
new ServiceDescriptor(typeof(IXContentEnricher), typeof(XContentEnricher), lifeTime)
);
//
// Register Dto Services ...
services.Add(
new ServiceDescriptor(typeof(IXContentServiceProvider), typeof(XContentServiceProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXContentRepositoryService), typeof(XContentRepositoryService), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXContentRepositoryProvider), typeof(XContentRepositoryProvider), lifeTime)
);
//
// Tags ...
services.Add(
new ServiceDescriptor(typeof(IXContentTagProvider), typeof(XContentTagProvider), lifeTime)
);
services.Add(
new ServiceDescriptor(typeof(IXContentTagProvided), typeof(XContentTagProvided), lifeTime)
);
//
// Provider ...
services.Add(
new ServiceDescriptor(typeof(IXContentProvider), typeof(XContentProvider), lifeTime)
);
//
Log("Service Regitration Succeed ...");
}
#endregion
}
}
+46
View File
@@ -0,0 +1,46 @@
using xCommons.Extensions;
using xContentService.Models.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Extensions
{
/// <summary>
/// All Service Model's Extensions ...
/// </summary>
public static class XModelExtensions
{
/// <summary>
/// Validate a Model ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this XContent source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Title.IsNullOrEmpty() &&
!source.OwnerId.IsNullOrEmpty();
//
return result;
}
/// <summary>
/// Validate a Model ...
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static bool IsValid(this XContentDto source)
{
//
var result =
!source.IsNullOrDefault() &&
!source.Title.IsNullOrEmpty() &&
!source.OwnerId.IsNullOrEmpty();
//
return result;
}
}
}
+282
View File
@@ -0,0 +1,282 @@
using System;
using GraphQL.Types;
using xDataService.Db;
using xDataService.Models;
using xDataService.Providers;
using xContentService.Models.Entities;
using xContentService.Providers.GraphQL;
using xContentService.Providers.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Helpers
{
public static class XContentServiceHelper
{
//
#region XContent ...
//
#region EF Repository Descriptor Provider(s) ...
public static XEFRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentEFRepository<TContext>,
TContext
> GetXContentEFRepositoryDescriptor<TContext>()
where TContext : XDbContext
{
//
var result = new XEFRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentEFRepository<TContext>,
TContext
>();
//
return result;
}
public static XEFRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentEFRepository<TContext>,
TContext,
IXContentSeeder,
TSeederImplementation
> GetXContentEFRepositoryDescriptor<TContext, TSeederImplementation>()
where TContext : XDbContext
where TSeederImplementation : XBaseDbSeeder<XContent, Guid>
{
//
var result = new XEFRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentEFRepository<TContext>,
TContext,
IXContentSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region Mongo Repository Descriptor Provider(s) ...
public static XMongoRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentMongoRepository
> GetXContentMongoRepositoryDescriptor()
{
//
var result = new XMongoRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentMongoRepository
>();
//
return result;
}
public static XMongoRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentMongoRepository,
IXContentSeeder,
TSeederImplementation
> GetXContentMongoRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XContent, Guid>
{
//
var result = new XMongoRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentMongoRepository,
IXContentSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
//
#region InMemory Repository Descriptor Provider(s) ...
public static XInMemoryRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentInMemoryRepository
> GetXContentInMemoryRepositoryDescriptor()
{
//
var result = new XInMemoryRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentInMemoryRepository
>();
//
return result;
}
public static XInMemoryRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentInMemoryRepository,
IXContentSeeder,
TSeederImplementation
> GetXContentInMemoryRepositoryDescriptor<TSeederImplementation>()
where TSeederImplementation : XBaseDbSeeder<XContent, Guid>
{
//
var result = new XInMemoryRepositoryDescriptor<
XContent,
Guid,
IXContentKeyGenerator,
XContentKeyGenerator,
IXContentRepositoryEvents,
XContentRepositoryEvents,
XContentGraphType,
GuidGraphType,
XContentGraphQuery,
IXContentGraphQLTypeHelper,
XContentGraphQLTypeHelper,
XContentGraphSchema,
IXContentRepository,
XContentInMemoryRepository,
IXContentSeeder,
TSeederImplementation
>();
//
return result;
}
#endregion
#endregion
}
}
@@ -0,0 +1,28 @@
using System;
using System.Threading;
using xTagService.Interfaces;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using xContentService.Models.Dtos;
using xContentService.Providers.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Controllers
{
public interface IXContentProviderController : IXBaseProvidedHasTagController<XContent, XContentDto, Guid, XContentDtoHub>
{
/// <summary>
/// Add an item ...
/// </summary>
/// <param name="item"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
[HttpPost("Add")]
Task<ActionResult<XContentDto>> Add(
[FromBody] XContentDto item,
[FromQuery] string language = null,
CancellationToken cancellationToken = default
);
}
}
+10
View File
@@ -0,0 +1,10 @@
using System;
using xPushService.Interfaces;
using xContentService.Models.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Dtos
{
public interface IXContentDtoHub : IXBaseDtoHub<XContent, XContentDto, Guid>
{ }
}
@@ -0,0 +1,10 @@
using System;
using xDataService.Interfaces;
using xContentService.Models.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Dtos
{
public interface IXContentRepositoryService : IXBaseRepositoryService<XContent, XContentDto, Guid>
{ }
}
@@ -0,0 +1,11 @@
using System;
using xPushService.Interfaces;
using xContentService.Models.Dtos;
using xContentService.Providers.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Dtos
{
public interface IXContentServiceProvider : IXBaseDtoProvider<XContent, XContentDto, Guid, XContentDtoHub>
{ }
}
+58
View File
@@ -0,0 +1,58 @@
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using xContentService.Models.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Enrichers
{
public interface IXContentEnricher
{
//
#region Enrichers ...
/// <summary>
/// Enrich Specified Item ...
/// </summary>
/// <param name="source"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XContentDto> Enrich(
XContent source,
CancellationToken cancellationToken = default
);
/// <summary>
/// Enrich Specified Item ...
/// </summary>
/// <param name="source"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XContentDto> Enrich(
XContentDto source,
CancellationToken cancellationToken = default
);
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XContentDto>> EnrichRange(
IEnumerable<XContent> sources,
CancellationToken cancellationToken = default
);
/// <summary>
/// Enrich Specified Items ...
/// </summary>
/// <param name="sources"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<XContentDto>> EnrichRange(
IEnumerable<XContentDto> sources,
CancellationToken cancellationToken = default
);
#endregion
}
}
@@ -0,0 +1,9 @@
using System;
using xPushService.Interfaces;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Entities
{
public interface IXContentEntityHub : IXBaseEntityHub<XContent, Guid>
{ }
}
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Entities
{
public interface IXContentGraphQLTypeHelper : IXBaseGraphQLTypeHelper<XContent, Guid>
{ }
}
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Entities
{
public interface IXContentKeyGenerator : IXKeyGenerator<XContent, Guid>
{ }
}
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Entities
{
public interface IXContentRepository : IXBaseRepository<XContent, Guid>
{ }
}
@@ -0,0 +1,8 @@
using xDataService.Interfaces;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Entities
{
public interface IXContentRepositoryEvents : IXBaseRepositoryEvents<XContent>
{ }
}
@@ -0,0 +1,10 @@
using System;
using xPushService.Interfaces;
using xContentService.Models.Entities;
using xContentService.Providers.Entities;
namespace xContentService.Interfaces.Entities
{
public interface IXContentRepositoryProvider : IXBaseEntityProvider<XContent, Guid, XContentEntityHub>
{ }
}
+9
View File
@@ -0,0 +1,9 @@
using System;
using xDataService.Interfaces;
using xContentService.Models.Entities;
namespace xContentService.Interfaces.Entities
{
public interface IXContentSeeder : IXBaseDbSeeder<XContent, Guid>
{ }
}
@@ -0,0 +1,7 @@
using xStringService.Interfaces;
namespace xContentService.Interfaces
{
public interface IXContentDescriptionResourceProvider : IXItemResourceProvider
{ }
}
+46
View File
@@ -0,0 +1,46 @@
using System;
using System.Threading;
using xTagService.Interfaces;
using System.Threading.Tasks;
using xIdentityModels.Models;
using xContentService.Models.Dtos;
using xContentService.Providers.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Interfaces
{
public interface IXContentProvider : IXBaseProvidedHasTag<XContent, XContentDto, Guid, XContentDtoHub>
{
/// <summary>
/// Add an item values ...
/// </summary>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public Task<XContentDto> Add(
XContentDto item,
XUserClaimsInfoDto userInfo = null,
string connectionId = null,
string language = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Create Content Used Locales for Creating Posts ...
/// </summary>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
// public Task<XContentDto> Create(
// XContentDto item,
// XUserClaimsInfoDto userInfo = null,
// string connectionId = null,
// CancellationToken cancellationToken = default
// );
}
}
+11
View File
@@ -0,0 +1,11 @@
using System;
using xTagService.Interfaces;
using xContentService.Models.Dtos;
using xContentService.Providers.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Interfaces
{
public interface IXContentTagProvided : IXTagProvided<XContent, XContentDto, Guid, XContentDtoHub>
{ }
}
+8
View File
@@ -0,0 +1,8 @@
using System;
using xTagService.Interfaces;
namespace xContentService.Interfaces
{
public interface IXContentTagProvider : IXBaseTagProvider<Guid>
{ }
}
@@ -0,0 +1,7 @@
using xStringService.Interfaces;
namespace xContentService.Interfaces
{
public interface IXContentTitleResourceProvider : IXItemResourceProvider
{ }
}
+21 -2
View File
@@ -1,7 +1,26 @@
using System;
using xModels.Base;
using xModels.Dtos;
namespace xContentService.Models.Dtos
{
public class XContentDto
/// <summary>
/// Content Describe DTO ...
/// </summary>
public class XContentDto : XBaseGuidIDEntityDto
{
public string OwnerId { get; set; }
public virtual XPersonDto Owner { get; set; }
public string Title { get; set; }
public virtual XResourceDto TitleResource { get; set; }
public string Description { get; set; }
public virtual XResourceDto DescriptionResource { get; set; }
public string[] Tags { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime UpdatedAt { get; set; }
}
}
+2
View File
@@ -1,4 +1,6 @@
using System;
using xModels.Base;
using System.ComponentModel.DataAnnotations;
namespace xContentService.Models.Entities
{
+17
View File
@@ -0,0 +1,17 @@
using System;
using xPushService.Base;
using xContentService.Models.Dtos;
using Microsoft.Extensions.Logging;
using xContentService.Interfaces.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Providers.Dtos
{
public class XContentDtoHub : XBaseDtoHub<XContent, XContentDto, Guid>, IXContentDtoHub
{
public XContentDtoHub(
ILogger<XContentDtoHub> logger
) : base(logger)
{ }
}
}
@@ -0,0 +1,23 @@
using System;
using AutoMapper;
using xDataService.Providers;
using System.Collections.Generic;
using xContentService.Models.Dtos;
using xContentService.Interfaces.Dtos;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Dtos
{
public class XContentRepositoryService : XBaseRepositoryService<XContent, XContentDto, Guid>, IXContentRepositoryService
{
public XContentRepositoryService(
IXContentRepository repository,
IEnumerable<Profile> mapperProfiles = null
) : base(
repository,
mapperProfiles
)
{ }
}
}
+27
View File
@@ -0,0 +1,27 @@
using System;
using xPushService.Base;
using xDataService.Configuration;
using xContentService.Models.Dtos;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
using xContentService.Interfaces.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Providers.Dtos
{
public class XContentServiceProvider : XBaseDtoProvider<XContent, XContentDto, Guid, XContentDtoHub>, IXContentServiceProvider
{
public XContentServiceProvider(
IHubContext<XContentDtoHub> hub,
XDataServiceConfiguration dataConfiguration,
IXContentRepositoryService service,
IXIdentityProvider identityProvider = null
) : base(
hub,
dataConfiguration,
service,
identityProvider
)
{ }
}
}
+173
View File
@@ -0,0 +1,173 @@
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using System.Threading.Tasks;
using System.Collections.Generic;
using xContentService.Interfaces;
using xContentService.Models.Dtos;
using xIdentityService.Interfaces;
using xIdentityService.Extensions;
using xContentService.Models.Entities;
using xContentService.Interfaces.Enrichers;
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;
}
//
#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 = source.MapConvert<XContentDto, XContent>();
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;
}
//
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;
result.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
}
}
@@ -0,0 +1,27 @@
using System;
using xDataService.Db;
using xDataService.Providers;
using xDataService.Interfaces;
using xDataService.Configuration;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public class XContentEFRepository<TContext> : XBaseEFRepository<XContent, Guid, TContext>, IXContentRepository
where TContext : XDbContext
{
public XContentEFRepository(
IXUnitOfWorks<TContext> unitOfWorks,
XDataServiceConfiguration configuration,
IXContentKeyGenerator keyGenerator = null,
IXContentRepositoryEvents baseRepositoryEvents = null
) : base(
unitOfWorks,
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
+16
View File
@@ -0,0 +1,16 @@
using System;
using xPushService.Base;
using Microsoft.Extensions.Logging;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public class XContentEntityHub : XBaseEntityHub<XContent, Guid>, IXContentEntityHub
{
public XContentEntityHub(
ILogger<XContentEntityHub> logger
) : base(logger)
{ }
}
}
@@ -0,0 +1,22 @@
using System;
using xDataService.Providers;
using xDataService.Configuration;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public class XContentInMemoryRepository : XBaseInMemoryRepository<XContent, Guid>, IXContentRepository
{
public XContentInMemoryRepository(
XDataServiceConfiguration configuration,
IXContentKeyGenerator keyGenerator = null,
IXContentRepositoryEvents baseRepositoryEvents = null
) : base(
configuration,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public class XContentKeyGenerator : XGuidKeyGenerator<XContent>, IXContentKeyGenerator
{ }
}
@@ -0,0 +1,26 @@
using System;
using xDataService.Providers;
using xDataService.Configuration;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public class XContentMongoRepository : XBaseMongoRepository<XContent, Guid>, IXContentRepository
{
public XContentMongoRepository(
XDataBaseConfiguration dbConfiguration,
XDataServiceConfiguration configuration,
string collectionName = null,
IXContentKeyGenerator keyGenerator = null,
IXContentRepositoryEvents baseRepositoryEvents = null
) : base(
dbConfiguration,
configuration,
collectionName,
keyGenerator,
baseRepositoryEvents
)
{ }
}
}
@@ -0,0 +1,9 @@
using xDataService.Providers;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public class XContentRepositoryEvents : XBaseRepositoryEvents<XContent>, IXContentRepositoryEvents
{ }
}
@@ -0,0 +1,26 @@
using System;
using xPushService.Base;
using xDataService.Configuration;
using xIdentityService.Interfaces;
using Microsoft.AspNetCore.SignalR;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public class XContentRepositoryProvider : XBaseEntityProvider<XContent, Guid, XContentEntityHub>, IXContentRepositoryProvider
{
public XContentRepositoryProvider(
IHubContext<XContentEntityHub> hub,
IXContentRepository repository,
XDataServiceConfiguration dataConfiguration,
IXIdentityProvider identityProvider = null
) : base(
hub,
repository,
dataConfiguration,
identityProvider
)
{ }
}
}
+24
View File
@@ -0,0 +1,24 @@
using System;
using xDataService.Providers;
using xDataService.Configuration;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.Entities
{
public abstract class XContentSeederBase : XBaseDbSeeder<XContent, Guid>, IXContentSeeder
{
protected XContentSeederBase(
string entity,
string database,
IXContentRepository repository,
XDataServiceConfiguration dataServiceConfiguration
) : base(
entity,
database,
repository,
dataServiceConfiguration
)
{ }
}
}
@@ -0,0 +1,21 @@
using System;
using xDataService.GraphQL;
using xContentService.Constants;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.GraphQL
{
public class XContentGraphQLTypeHelper : XBaseGraphQLTypeHelper<XContent, Guid>, IXContentGraphQLTypeHelper
{
public override string GetInQueryCollectionName()
{
return XContentServiceConstants.XContentCollectionName;
}
public override string GetInQuerySingleName()
{
return XContentServiceConstants.XContentSingleName;
}
}
}
+23
View File
@@ -0,0 +1,23 @@
using System;
using GraphQL.Types;
using xDataService.GraphQL;
using xDataService.Configuration;
using xContentService.Models.Entities;
using xContentService.Interfaces.Entities;
namespace xContentService.Providers.GraphQL
{
public class XContentGraphQuery : XBaseGraphQLQuery<XContent, Guid, XContentGraphType, GuidGraphType>
{
public XContentGraphQuery(
XDataServiceConfiguration configuration,
IXContentRepository repository,
IXContentGraphQLTypeHelper helper
) : base(
configuration,
repository,
helper
)
{ }
}
}
+13
View File
@@ -0,0 +1,13 @@
using System;
using GraphQL.Types;
namespace xContentService.Providers.GraphQL
{
public class XContentGraphSchema : Schema
{
public XContentGraphSchema(IServiceProvider services) : base(services)
{
Query = (XContentGraphQuery)services.GetService(typeof(XContentGraphQuery));
}
}
}
+18
View File
@@ -0,0 +1,18 @@
using System;
using xDataService.GraphQL;
using xContentService.Models.Entities;
namespace xContentService.Providers.GraphQL
{
public class XContentGraphType : XBaseGraphObjectType<XContent, Guid>
{
public XContentGraphType() : base()
{
Field(x => x.Title);
Field(x => x.OwnerId);
Field(x => x.CreatedOn);
Field(x => x.UpdatedAt);
Field(x => x.Description);
}
}
}
@@ -0,0 +1,18 @@
using xStringService.Providers;
using xContentService.Constants;
using xContentService.Interfaces;
using xStringService.Interfaces.Dtos;
namespace xContentService.Providers
{
public class XContentDescriptionResourceProvider : XBaseItemResourceProvider, IXContentDescriptionResourceProvider
{
public XContentDescriptionResourceProvider(
IXStringServiceProvider stringProvider
) : base(
stringProvider: stringProvider,
item: XContentServiceConstants.XContentDescriptionIdentifier
)
{ }
}
}
+35
View File
@@ -0,0 +1,35 @@
using System;
using xDataService.Providers;
using xDataService.Interfaces;
using Microsoft.EntityFrameworkCore;
using xContentService.Models.Entities;
using xContentService.Configuration.Entities;
namespace xContentService.Providers
{
public class XContentEntityRegisterar : XBaseEntityRegisterar, IXEntityRegisterar
{
public XContentEntityRegisterar()
: base(nameof(XContentEntityRegisterar))
{
//
// Add Entity ...
AddEntity<XContent, Guid>();
}
/// <summary>
/// Configure Entities ...
/// </summary>
/// <param name="modelBuilder"></param>
public override void ConfigureEntities(ModelBuilder modelBuilder)
{
//
// Configure Entity Using Provided ...
modelBuilder
.ApplyConfigurationsFromAssembly(typeof(XContentEntityConfiguration).Assembly);
//
base.ConfigureEntities(modelBuilder);
}
}
}
+693
View File
@@ -0,0 +1,693 @@
using System;
using System.Linq;
using xModels.Dtos;
using System.Threading;
using xCommons.Extensions;
using xTagService.Providers;
using xExceptions.Constants;
using xIdentityModels.Models;
using System.Threading.Tasks;
using xPushService.Constants;
using System.Linq.Expressions;
using xCommons.Configurations;
using xContentService.Constants;
using xContentService.Interfaces;
using System.Collections.Generic;
using xContentService.Extensions;
using xContentService.Models.Dtos;
using xContentService.Providers.Dtos;
using xContentService.Models.Entities;
using xContentService.Interfaces.Dtos;
using Microsoft.EntityFrameworkCore.Query;
using xContentService.Interfaces.Enrichers;
namespace xContentService.Providers
{
public class XContentProvider : XBaseProvidedHasTag<XContent, XContentDto, Guid, XContentDtoHub>, IXContentProvider
{
private readonly IXContentEnricher enricher;
private readonly XAppConfiguration configuration;
private readonly IXContentTagProvider tagProvider;
private readonly IXContentServiceProvider provider;
private readonly IXContentTitleResourceProvider titleResourceProvider;
private readonly IXContentDescriptionResourceProvider descriptionResourceProvider;
public XContentProvider(
IXContentEnricher enricher,
XAppConfiguration configuration,
IXContentTagProvider tagProvider,
IXContentServiceProvider provider,
IXContentTitleResourceProvider titleResourceProvider,
IXContentDescriptionResourceProvider descriptionResourceProvider
) : base(
provider: provider,
tagProvider: tagProvider,
permittedRoles: [XContentServiceConstants.XAdminRole]
)
{
this.provider = provider;
this.enricher = enricher;
this.tagProvider = tagProvider;
this.configuration = configuration;
this.titleResourceProvider = titleResourceProvider;
this.descriptionResourceProvider = descriptionResourceProvider;
}
public override bool IsOwned(
XContent item,
XUserClaimsInfoDto userInfo
)
{
//
var result =
!item.IsNullOrDefault() &&
!userInfo.IsNullOrDefault() &&
!item.OwnerId.IsNullOrEmpty() &&
userInfo.UserId == item.OwnerId;
//
return result;
}
public override bool IsOwned(
XContentDto item,
XUserClaimsInfoDto userInfo
)
{
//
var result =
!item.IsNullOrDefault() &&
!userInfo.IsNullOrDefault() &&
!item.OwnerId.IsNullOrEmpty() &&
userInfo.UserId == item.OwnerId;
//
return result;
}
//
#region Overrides ...
/// <summary>
/// Get Specified Item by ID ...
/// </summary>
/// <param name="id"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<XContentDto> Get(
Guid id,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> includeBuilder = null,
CancellationToken cancellationToken = default
)
{
//
// Retrieve Item ...
var result = await provider.GetAsync(
id: id,
includeBuilder: null,
ignoreSoftDeleteds: true,
cancellationToken: cancellationToken
);
//
// Handle Enrichment ...
if (!result.IsNullOrDefault())
{
//
result = await enricher.Enrich(
source: result,
cancellationToken: cancellationToken
);
}
//
return result;
}
/// <summary>
/// Get All Exists Items ...
/// </summary>
/// <param name="orderBuilder"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<IEnumerable<XContentDto>> GetAll(
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> orderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> includeBuilder = null,
CancellationToken cancellationToken = default
)
{
//
// Retrieve Items ...
var result = await provider.GetAllAsync(
ignoreSoftDeleteds: true,
orderBuilder: orderBuilder,
includeBuilder: includeBuilder,
cancellationToken: cancellationToken
);
//
// Handle Enrichment ...
if (result.HasChild())
{
//
result = await enricher.EnrichRange(
sources: result,
cancellationToken: cancellationToken
);
}
//
return result;
}
/// <summary>
/// find an item by providing a Conditional Expression ...
/// </summary>
/// <param name="predicate"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<XContentDto> FindOne(
Expression<Func<XContent, bool>> predicate,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> includeBuilder = null,
CancellationToken cancellationToken = default
)
{
//
// Detect Item ...
var result = await provider.FindOneAsync(
predicate: predicate,
ignoreSoftDeleteds: true,
includeBuilder: includeBuilder,
cancellationToken: cancellationToken
);
//
// Handle Enrichment ...
if (!result.IsNullOrDefault())
{
//
result = await enricher.Enrich(
source: result,
cancellationToken: cancellationToken
);
}
//
return result;
}
/// <summary>
/// find a collection of Items by proving a Conditional Expression ...
/// </summary>
/// <param name="predicate"></param>
/// <param name="orderBuilder"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<IEnumerable<XContentDto>> FindMany(
Expression<Func<XContent, bool>> predicate,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> orderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> includeBuilder = null,
CancellationToken cancellationToken = default
)
{
//
// Detect Items ...
var result = await provider.FindManyAsync(
predicate: predicate,
ignoreSoftDeleteds: true,
orderBuilder: orderBuilder,
includeBuilder: includeBuilder,
cancellationToken: cancellationToken
);
//
// Handle Enrichment ...
if (result.HasChild())
{
//
result = await enricher.EnrichRange(
sources: result,
cancellationToken: cancellationToken
);
}
//
return result;
}
/// <summary>
/// retrieve Items based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <param name="predicate"></param>
/// <param name="orderBuilder"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<XQueryResult<XContentDto>> Query(
XQuery query,
Expression<Func<XContent, bool>> predicate = null,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> orderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> includeBuilder = null,
CancellationToken cancellationToken = default
)
{
//
// Query Items ...
var result = await provider.QueryAsync(
query: query,
predicate: predicate,
ignoreSoftDeleteds: true,
orderBuilder: orderBuilder,
includeBuilder: includeBuilder,
cancellationToken: cancellationToken
);
//
// Handle Enrichment ...
if (!result.IsNullOrDefault() && result.Items.HasChild())
{
//
result.Items = await enricher.EnrichRange(
sources: result.Items,
cancellationToken: cancellationToken
);
}
//
return result;
}
/// <summary>
/// retrieve Owned Items based on XQuery Pagination structure ...
/// if supported ...
/// </summary>
/// <param name="query"></param>
/// <param name="userInfo"></param>
/// <param name="predicate"></param>
/// <param name="orderBuilder"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<XQueryResult<XContentDto>> QueryOwned(
XQuery query,
XUserClaimsInfoDto userInfo = null,
Expression<Func<XContent, bool>> predicate = null,
Func<IQueryable<XContent>, IOrderedQueryable<XContent>> orderBuilder = null,
Func<IQueryable<XContent>, IIncludableQueryable<XContent, object>> includeBuilder = null,
CancellationToken cancellationToken = default
)
{
//
// Prepare Predicator ...
Expression<Func<XContent, bool>> predicateor = null;
if (!predicate.IsNull())
{
//
var predicateFnc = predicate.Compile();
predicateor = x =>
predicateFnc(x) &&
IsOwned(x, userInfo);
}
else
{
predicateor = x => IsOwned(x, userInfo);
}
//
// Query Items ...
var result = await provider.QueryAsync(
query: query,
predicate: predicateor,
ignoreSoftDeleteds: true,
orderBuilder: orderBuilder,
includeBuilder: includeBuilder,
cancellationToken: cancellationToken
);
//
// Handle Enrichment ...
if (!result.IsNullOrDefault() && result.Items.HasChild())
{
//
result.Items = await enricher.EnrichRange(
sources: result.Items,
cancellationToken: cancellationToken
);
}
//
return result;
}
/// <summary>
/// Add an item values ...
/// </summary>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<XContentDto> Add(
XContentDto item,
XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
var result = await Add(
item: item,
language: null,
userInfo: userInfo,
connectionId: connectionId,
cancellationToken: cancellationToken
);
//
return result;
}
/// <summary>
/// Add an item values ...
/// </summary>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="language"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XContentDto> Add(
XContentDto item,
XUserClaimsInfoDto userInfo = null,
string connectionId = null,
string language = null,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
var isValid = !item.IsNullOrDefault();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Normalize ...
//
// Language ...
if (language.IsNullOrEmpty())
{
language = configuration.DefaultLanguage;
}
//
// Owner Id ...
if (item.OwnerId.IsNullOrEmpty())
{
//
if (!userInfo.IsNullOrDefault())
{
item.OwnerId = userInfo.UserId;
}
}
//
// Created On ...
item.CreatedOn = DateTime.UtcNow;
//
// Validate Normalized Items ...
isValid = item.IsValid();
if (!isValid)
{
XException.InvalidData.Throw();
}
//
// Handle Insert Temp ...
var result = await provider.AddAsync(
item: item,
saveChanges: true,
connectionId: null, // Ignor Push Notifications ...,
cancellationToken: cancellationToken
);
isValid = !result.IsNullOrDefault();
if (!isValid)
{
XException.ActionFailed.Throw();
}
//
// Handle Insert Title/Description ...
//
var titleResource = await titleResourceProvider.AddOrUpdateLocale(
connectionId: null,
identifier: result.Id,
locale: new XLocaleResourceDto
{
Language = language,
Value = result.Title,
},
cancellationToken: cancellationToken
);
//
XResourceDto descriptionResource = null;
if (!result.Description.IsNullOrEmpty())
{
//
descriptionResource = await descriptionResourceProvider.AddOrUpdateLocale(
connectionId: null,
identifier: result.Id,
locale: new XLocaleResourceDto
{
Language = language,
Value = result.Description,
},
cancellationToken: cancellationToken
);
}
//
// Fill Item Title and Description ...
if (titleResource.IsNullOrDefault())
{
result.Title = titleResource.Resource;
}
if (descriptionResource.IsNullOrDefault())
{
result.Description = descriptionResource.Resource;
}
//
// Update Item ...
result = await Update(
item: result,
id: result.Id,
userInfo: userInfo,
connectionId: null,
cancellationToken: cancellationToken
);
isValid = !result.IsNullOrDefault();
if (!isValid)
{
XException.ActionFailed.Throw();
}
//
// Handle Enrichment ...
if (isValid)
{
//
result = await enricher.Enrich(
source: result,
cancellationToken: cancellationToken
);
}
//
// Handle Push Notifications ...
if (isValid && !connectionId.IsNullOrEmpty())
{
//
await provider.SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: result.ToJSON(camelCase: true),
action: XBaseEntityHubAction.Add.GetStringValue()
);
}
//
return result;
}
/// <summary>
/// Update an item values ...
/// </summary>
/// <param name="id"></param>
/// <param name="item"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<XContentDto> Update(
Guid id,
XContentDto item,
XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Check Permission ...
var hasPermission =
IsOwned(item, userInfo) ||
HasPermision(userInfo);
if (!hasPermission)
{
XException.NotAllowed.Throw();
}
//
// Handle Resources ...
if (!item.TitleResource.IsNullOrDefault())
{
item.TitleResource = await titleResourceProvider.AddOrUpdateResource(
identifier: item.Id,
connectionId: connectionId,
resource: item.TitleResource,
cancellationToken: cancellationToken
);
}
//
// Handle Update on ...
item.UpdatedAt = DateTime.UtcNow;
//
var result = await provider.UpdateAsync(
id: id,
item: item,
saveChanges: true,
connectionId: null,
cancellationToken: cancellationToken
);
var isValid = !result.IsNullOrDefault();
//
// Handle Enrichment ...
if (isValid)
{
//
result = await enricher.Enrich(
source: result,
cancellationToken: cancellationToken
);
}
//
// Handle Notification ...
if (isValid && !connectionId.IsNullOrEmpty())
{
//
await provider.SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: result.ToJSON(camelCase: true),
action: XBaseEntityHubAction.Update.GetStringValue()
);
}
//
return result;
}
/// <summary>
/// remove an Item ...
/// </summary>
/// <param name="id"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<XContentDto> Remove(
Guid id,
XUserClaimsInfoDto userInfo = null,
string connectionId = null,
CancellationToken cancellationToken = default
)
{
//
// Check Permission ...
var item = await Get(
id: id,
cancellationToken: cancellationToken
);
var hasPermission =
IsOwned(item, userInfo) ||
HasPermision(userInfo);
if (!hasPermission)
{
XException.NotAllowed.Throw();
}
//
// Handle Item Remove ...
var result = await provider.RemoveAsync(
id: id,
saveChanges: true,
softDelete: false,
connectionId: null,
cancellationToken: cancellationToken
);
if (result.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
// Remove Titles/Descriptions ...
//
// Titles ...
await titleResourceProvider.RemoveLocales(
connectionId: null,
identifier: result.Id,
cancellationToken: cancellationToken
);
//
// Descriptions ...
await descriptionResourceProvider.RemoveLocales(
connectionId: null,
identifier: result.Id,
cancellationToken: cancellationToken
);
//
// Handle Notifications ...
if (!connectionId.IsNullOrEmpty())
{
//
await provider.SendPush(
connectionId: connectionId,
cancellationToken: cancellationToken,
payLoad: result.ToJSON(camelCase: true),
action: XBaseEntityHubAction.Delete.GetStringValue()
);
}
//
return result;
}
#endregion
}
}
+56
View File
@@ -0,0 +1,56 @@
using System;
using xCommons.Extensions;
using xTagService.Providers;
using xIdentityModels.Models;
using xContentService.Constants;
using xContentService.Interfaces;
using xContentService.Models.Dtos;
using xContentService.Providers.Dtos;
using xContentService.Interfaces.Dtos;
using xContentService.Models.Entities;
namespace xContentService.Providers
{
public class XContentTagProvided : XBaseTagProvided<XContent, XContentDto, Guid, XContentDtoHub>, IXContentTagProvided
{
public XContentTagProvided(
IXContentTagProvider tagProvider,
IXContentServiceProvider provider
) : base(
provider: provider,
tagProvider: tagProvider,
permittedRoles: [XContentServiceConstants.XAdminRole]
)
{ }
public override bool IsOwned(
XContent item,
XUserClaimsInfoDto userInfo
)
{
//
var result =
!item.IsNullOrDefault() &&
!userInfo.IsNullOrDefault() &&
item.OwnerId == userInfo.UserId;
//
return result;
}
public override bool IsOwned(
XContentDto item,
XUserClaimsInfoDto userInfo
)
{
//
var result =
!item.IsNullOrDefault() &&
!userInfo.IsNullOrDefault() &&
item.OwnerId == userInfo.UserId;
//
return result;
}
}
}
+19
View File
@@ -0,0 +1,19 @@
using System;
using xTagService.Providers;
using xContentService.Constants;
using xContentService.Interfaces;
using xTagService.Interfaces.Dtos;
namespace xContentService.Providers
{
public class XContentTagProvider : XBaseTagProvider<Guid>, IXContentTagProvider
{
public XContentTagProvider(
IXTagServiceProvider tagProvider
) : base(
tagProvider: tagProvider,
providedFor: XContentServiceConstants.XContentTagProvided
)
{ }
}
}
@@ -0,0 +1,18 @@
using xStringService.Providers;
using xContentService.Constants;
using xContentService.Interfaces;
using xStringService.Interfaces.Dtos;
namespace xContentService.Providers
{
public class XContentTitleResourceProvider : XBaseItemResourceProvider, IXContentTitleResourceProvider
{
public XContentTitleResourceProvider(
IXStringServiceProvider stringProvider
) : base(
stringProvider: stringProvider,
item: XContentServiceConstants.XContentTitleIdentifier
)
{ }
}
}
+3 -2
View File
@@ -31,13 +31,14 @@
<ItemGroup>
<ProjectReference Include="../xTagService/xTagService.csproj" />
<ProjectReference Include="../xFileService/xFileService.csproj" />
<ProjectReference Include="../xStringService/xStringService.csproj" />
</ItemGroup>
<!-- For XML Documentation Support -->
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
</Project>