Refactor ...
This commit is contained in:
@@ -20,119 +20,121 @@ using xPushService.Constants;
|
|||||||
|
|
||||||
namespace xIdentityHelper.Controllers
|
namespace xIdentityHelper.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
//
|
||||||
[ApiVersion("1.0")]
|
// TODO: Fix this ...
|
||||||
[RequireXPowered(true)]
|
// [ApiController]
|
||||||
[Route("api/v{version:apiVersion}/entities/[controller]")]
|
// [ApiVersion("1.0")]
|
||||||
public abstract class XIBaseV1EntityController<TEntity, TKey> : XIBaseEntityController<TEntity, TKey>
|
// [RequireXPowered(true)]
|
||||||
where TEntity : XBaseEntity<TKey>
|
// [Route("api/v{version:apiVersion}/entities/[controller]")]
|
||||||
{
|
// public abstract class XIBaseV1EntityController<TEntity, TKey> : XIBaseEntityController<TEntity, TKey>
|
||||||
//
|
// where TEntity : XBaseEntity<TKey>
|
||||||
#region Constructor ...
|
// {
|
||||||
protected XIBaseV1EntityController(
|
// //
|
||||||
ILogger<XIBaseV1EntityController<TEntity, TKey>> logger,
|
// #region Constructor ...
|
||||||
XAppConfiguration appConfiguration,
|
// protected XIBaseV1EntityController(
|
||||||
IXIdentityProvider identityProvider,
|
// ILogger<XIBaseV1EntityController<TEntity, TKey>> logger,
|
||||||
XValidationProvider validationProvider,
|
// XAppConfiguration appConfiguration,
|
||||||
IXBaseRepository<TEntity, TKey> repository,
|
// IXIdentityProvider identityProvider,
|
||||||
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
|
// XValidationProvider validationProvider,
|
||||||
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
|
// IXBaseRepository<TEntity, TKey> repository,
|
||||||
) : base(
|
// Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
|
||||||
logger: logger,
|
// Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
|
||||||
repository: repository,
|
// ) : base(
|
||||||
appConfiguration: appConfiguration,
|
// logger: logger,
|
||||||
identityProvider: identityProvider,
|
// repository: repository,
|
||||||
validationProvider: validationProvider,
|
// appConfiguration: appConfiguration,
|
||||||
defaultOrderBuilder: defaultOrderBuilder,
|
// identityProvider: identityProvider,
|
||||||
defaultIncludeBuilder: defaultIncludeBuilder
|
// validationProvider: validationProvider,
|
||||||
)
|
// defaultOrderBuilder: defaultOrderBuilder,
|
||||||
{ }
|
// defaultIncludeBuilder: defaultIncludeBuilder
|
||||||
#endregion
|
// )
|
||||||
}
|
// { }
|
||||||
|
// #endregion
|
||||||
|
// }
|
||||||
|
|
||||||
public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey>
|
// public abstract class XIBaseV1EntityHubController<TEntity, TKey> : XIBaseV1EntityController<TEntity, TKey>
|
||||||
where TEntity : XBaseEntity<TKey>
|
// where TEntity : XBaseEntity<TKey>
|
||||||
{
|
// {
|
||||||
//
|
// //
|
||||||
#region Props ...
|
// #region Props ...
|
||||||
public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; }
|
// public IHubContext<XBaseEntityHub<TEntity, TKey>> Hub { get; }
|
||||||
#endregion
|
// #endregion
|
||||||
|
|
||||||
//
|
// //
|
||||||
#region Constructor ...
|
// #region Constructor ...
|
||||||
protected XIBaseV1EntityHubController(
|
// protected XIBaseV1EntityHubController(
|
||||||
ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger,
|
// ILogger<XIBaseV1EntityHubController<TEntity, TKey>> logger,
|
||||||
XAppConfiguration appConfiguration,
|
// XAppConfiguration appConfiguration,
|
||||||
IXIdentityProvider identityProvider,
|
// IXIdentityProvider identityProvider,
|
||||||
XValidationProvider validationProvider,
|
// XValidationProvider validationProvider,
|
||||||
IXBaseRepository<TEntity, TKey> repository,
|
// IXBaseRepository<TEntity, TKey> repository,
|
||||||
IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null,
|
// IHubContext<XBaseEntityHub<TEntity, TKey>> hub = null,
|
||||||
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
|
// Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> defaultOrderBuilder = null,
|
||||||
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
|
// Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> defaultIncludeBuilder = null
|
||||||
) : base(
|
// ) : base(
|
||||||
logger: logger,
|
// logger: logger,
|
||||||
repository: repository,
|
// repository: repository,
|
||||||
appConfiguration: appConfiguration,
|
// appConfiguration: appConfiguration,
|
||||||
identityProvider: identityProvider,
|
// identityProvider: identityProvider,
|
||||||
validationProvider: validationProvider,
|
// validationProvider: validationProvider,
|
||||||
defaultOrderBuilder: defaultOrderBuilder,
|
// defaultOrderBuilder: defaultOrderBuilder,
|
||||||
defaultIncludeBuilder: defaultIncludeBuilder
|
// defaultIncludeBuilder: defaultIncludeBuilder
|
||||||
)
|
// )
|
||||||
{
|
// {
|
||||||
Hub = hub;
|
// Hub = hub;
|
||||||
}
|
// }
|
||||||
#endregion
|
// #endregion
|
||||||
|
|
||||||
//
|
// //
|
||||||
#region Hub ...
|
// #region Hub ...
|
||||||
[NonAction]
|
// [NonAction]
|
||||||
public async Task SendPush(
|
// public async Task SendPush(
|
||||||
string action,
|
// string action,
|
||||||
string payLoad,
|
// string payLoad,
|
||||||
CancellationToken cancellationToken = default
|
// CancellationToken cancellationToken = default
|
||||||
)
|
// )
|
||||||
{
|
// {
|
||||||
//
|
// //
|
||||||
var actions = new List<string>
|
// var actions = new List<string>
|
||||||
{
|
// {
|
||||||
XBaseEntityHubAction.Add.GetStringValue(),
|
// XBaseEntityHubAction.Add.GetStringValue(),
|
||||||
XBaseEntityHubAction.Update.GetStringValue(),
|
// XBaseEntityHubAction.Update.GetStringValue(),
|
||||||
XBaseEntityHubAction.Delete.GetStringValue(),
|
// XBaseEntityHubAction.Delete.GetStringValue(),
|
||||||
XBaseEntityHubAction.AddMany.GetStringValue(),
|
// XBaseEntityHubAction.AddMany.GetStringValue(),
|
||||||
XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
// XBaseEntityHubAction.DeleteMany.GetStringValue(),
|
||||||
XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
// XBaseEntityHubAction.UpdateMany.GetStringValue(),
|
||||||
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
// XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
|
||||||
};
|
// };
|
||||||
|
|
||||||
//
|
// //
|
||||||
// Validate ...
|
// // Validate ...
|
||||||
var isValid =
|
// var isValid =
|
||||||
!Hub.IsNull() &&
|
// !Hub.IsNull() &&
|
||||||
!action.IsNullOrEmpty() &&
|
// !action.IsNullOrEmpty() &&
|
||||||
!payLoad.IsNullOrEmpty() &&
|
// !payLoad.IsNullOrEmpty() &&
|
||||||
actions.Contains(action);
|
// actions.Contains(action);
|
||||||
if (!isValid)
|
// if (!isValid)
|
||||||
{
|
// {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
//
|
// //
|
||||||
// Retrieve Connection Id ...
|
// // Retrieve Connection Id ...
|
||||||
var connectionId = GetConnectionId();
|
// var connectionId = GetConnectionId();
|
||||||
var clients = Hub.Clients.All;
|
// var clients = Hub.Clients.All;
|
||||||
if (!connectionId.IsNullOrEmpty())
|
// if (!connectionId.IsNullOrEmpty())
|
||||||
{
|
// {
|
||||||
clients = Hub.Clients.AllExcept(connectionId);
|
// clients = Hub.Clients.AllExcept(connectionId);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//
|
// //
|
||||||
await clients.SendAsync(
|
// await clients.SendAsync(
|
||||||
action,
|
// action,
|
||||||
payLoad,
|
// payLoad,
|
||||||
connectionId,
|
// connectionId,
|
||||||
cancellationToken
|
// cancellationToken
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
#endregion
|
// #endregion
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user