add support for Provider Base Controller and also resolve some refactoring issues ...

This commit is contained in:
2025-12-09 03:11:48 +03:30
parent 7e174fc14a
commit cb8e95dcea
5 changed files with 288 additions and 149 deletions
+4 -1
View File
@@ -17,7 +17,10 @@ using xTagService.Models.Entities;
namespace xTagService.Controllers
{
public class XTagServiceControllerBase : XIBaseProviderController, IXTagServiceControllerActions
/// <summary>
/// a Controller base Class which implement based Actions to Provides Tag Provider Access ...
/// </summary>
public abstract class XTagServiceControllerBase : XIBaseProviderController, IXTagServiceControllerActions
{
//
#region Props ...
+20 -6
View File
@@ -40,10 +40,12 @@ namespace xTagService.Interfaces
/// </summary>
/// <param name="tag"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Attach(
string tag,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
);
/// <summary>
@@ -51,10 +53,12 @@ namespace xTagService.Interfaces
/// </summary>
/// <param name="tag"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Detach(
string tag,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
);
/// <summary>
@@ -62,10 +66,12 @@ namespace xTagService.Interfaces
/// </summary>
/// <param name="model"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Add(
XTagDto model,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
);
/// <summary>
@@ -177,17 +183,23 @@ namespace xTagService.Interfaces
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Remove(
int id
int id,
string connectionId = null
);
/// <summary>
/// Remove All Specified Tags ...
/// </summary>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<bool> RemoveTagsFor(TKey forProvidedId);
Task<bool> RemoveTagsFor(
TKey forProvidedId,
string connectionId = null
);
/// <summary>
/// Update Specified Dto ...
@@ -195,11 +207,13 @@ namespace xTagService.Interfaces
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Update(
int id,
XTagDto model,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
);
/// <summary>
+24 -24
View File
@@ -60,6 +60,30 @@ namespace xTagService.Interfaces
string connectionId = null
);
/// <summary>
/// Update Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Update(
int id,
XTagDto model,
string connectionId = null
);
/// <summary>
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Remove(
int id,
string connectionId = null
);
/// <summary>
/// Retrieve Specified Item as Dto ...
/// </summary>
@@ -112,30 +136,6 @@ namespace xTagService.Interfaces
Expression<Func<XTag, bool>> whereClause
);
/// <summary>
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Remove(
int id,
string connectionId = null
);
/// <summary>
/// Update Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
Task<XTagDto> Update(
int id,
XTagDto model,
string connectionId = null
);
/// <summary>
/// Count Exists Entities ...
/// </summary>
+40 -13
View File
@@ -68,10 +68,12 @@ namespace xTagService.Providers
/// </summary>
/// <param name="tag"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Attach(
string tag,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
)
{
//
@@ -103,7 +105,8 @@ namespace xTagService.Providers
{
Tag = tag,
References = new List<string> { identifier }
});
},
connectionId);
}
//
// Update Exists Tag Enttiy ...
@@ -119,7 +122,11 @@ namespace xTagService.Providers
//
result.References.Add(identifier);
result = await Provider.Update(result.Id, result);
result = await Provider.Update(
result.Id,
result,
connectionId
);
isValid = !result.IsNullOrDefault();
if (!isValid)
{
@@ -136,10 +143,12 @@ namespace xTagService.Providers
/// </summary>
/// <param name="tag"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Detach(
string tag,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
)
{
//
@@ -187,7 +196,11 @@ namespace xTagService.Providers
.References
.Where(rf => rf.ToNormalString() != identifier.ToNormalString())
.ToList();
result = await Provider.Update(result.Id, result);
result = await Provider.Update(
result.Id,
result,
connectionId
);
//
return result;
@@ -198,10 +211,12 @@ namespace xTagService.Providers
/// </summary>
/// <param name="model"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Add(
XTagDto model,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
)
{
//
@@ -228,7 +243,7 @@ namespace xTagService.Providers
}
//
model = await Provider.Add(model);
model = await Provider.Add(model, connectionId);
//
return model;
@@ -833,9 +848,11 @@ namespace xTagService.Providers
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Remove(
int id
int id,
string connectionId = null
)
{
//
@@ -853,7 +870,7 @@ namespace xTagService.Providers
}
//
var result = await Provider.Remove(id);
var result = await Provider.Remove(id, connectionId);
if (result.IsNullOrDefault())
{
XException.ActionFailed.Throw();
@@ -867,8 +884,12 @@ namespace xTagService.Providers
/// Remove All Specified Tags ...
/// </summary>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<bool> RemoveTagsFor(TKey forProvidedId)
public async Task<bool> RemoveTagsFor(
TKey forProvidedId,
string connectionId = null
)
{
//
var result = false;
@@ -885,7 +906,7 @@ namespace xTagService.Providers
try
{
//
await Detach(dto.Tag, forProvidedId);
await Detach(dto.Tag, forProvidedId, connectionId);
if (!result)
{
result = true;
@@ -905,11 +926,13 @@ namespace xTagService.Providers
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="forProvidedId"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Update(
int id,
XTagDto model,
TKey forProvidedId
TKey forProvidedId,
string connectionId = null
)
{
//
@@ -927,7 +950,11 @@ namespace xTagService.Providers
}
//
var result = await Provider.Update(id, model);
var result = await Provider.Update(
id,
model,
connectionId
);
if (result.IsNullOrDefault())
{
XException.ActionFailed.Throw();
+200 -105
View File
@@ -9,6 +9,7 @@ using xDataService.Configuration;
using xExceptions.Constants;
using xIdentityService.Interfaces;
using xModels.Dtos;
using xPushService.Constants;
using xTagService.Extensions;
using xTagService.Hubs;
using xTagService.Interfaces;
@@ -125,32 +126,172 @@ namespace xTagService.Providers
/// Add Specified Tag ...
/// </summary>
/// <param name="model"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Add(XTagDto model)
public async Task<XTagDto> Add(
XTagDto model,
string connectionId = null
)
{
//
XTagDto result = null;
//
// Converts to Entity ...
var entity = model.FromDto();
if (!model.IsNullOrDefault())
{
//
// Converts to Entity ...
var entitiy = model.FromDto();
if (entitiy.IsNullOrDefault())
// Validate ...
if (entity.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
entitiy = await Repository.AddAsync(entitiy);
if (entitiy.IsNullOrDefault())
entity = await Repository.AddAsync(entity);
if (entity.IsNullOrDefault())
{
XException.ActionFailed.Throw();
}
//
result = ToDto(entitiy);
result = ToDto(entity);
}
//
if (!result.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Add.GetStringValue(),
payLoad: entity.ToJSON(camelCase: true),
connectionId: connectionId
);
}
//
return result;
}
/// <summary>
/// Update Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="userInfo"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Update(
int id,
XTagDto model,
string connectionId = null
)
{
//
// Validate ...
var isValid = id.IsValidIntId();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
XTagDto result = null;
//
// Check Exists ...
isValid = await IsExists(id);
if (!isValid)
{
XException.NotFound.Throw();
}
//
var entity = await Repository.GetAsync(id);
if (entity.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
var tagEntity = model.FromDto();
entity = entity.UpdateData(
updateWith: entity,
propertyBlackList: new List<string>
{
nameof(XTagDto.Id),
nameof(XTagDto.References)
}
);
entity.References = tagEntity.References;
entity = await Repository.UpdateAsync(id, entity);
if (!entity.IsNullOrDefault())
{
result = ToDto(entity);
}
//
if (!result.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Update.GetStringValue(),
payLoad: entity.ToJSON(camelCase: true),
connectionId: connectionId
);
}
//
return result;
}
/// <summary>
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task<XTagDto> Remove(
int id,
string connectionId = null
)
{
//
// Validate ...
var isValid = id.IsValidIntId();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Check Exists ...
isValid = await IsExists(id);
if (!isValid)
{
XException.NotFound.Throw();
}
//
var entity = await Repository.RemoveAsync(id);
//
XTagDto result = null;
if (!entity.IsNullOrDefault())
{
result = ToDto(entity);
}
//
if (!result.IsNullOrDefault())
{
//
await SendPush(
action: XBaseEntityHubAction.Delete.GetStringValue(),
payLoad: entity.ToJSON(camelCase: true),
connectionId: connectionId
);
}
//
@@ -333,104 +474,6 @@ namespace xTagService.Providers
return result;
}
/// <summary>
/// Remove Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<XTagDto> Remove(
int id
)
{
//
// Validate ...
var isValid = id.IsValidIntId();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Check Exists ...
isValid = await IsExists(id);
if (!isValid)
{
XException.NotFound.Throw();
}
//
var entity = await Repository.RemoveAsync(id);
//
XTagDto result = null;
if (!entity.IsNullOrDefault())
{
result = ToDto(entity);
}
//
return result;
}
/// <summary>
/// Update Specified Dto ...
/// </summary>
/// <param name="id"></param>
/// <param name="model"></param>
/// <param name="userInfo"></param>
/// <returns></returns>
public async Task<XTagDto> Update(
int id,
XTagDto model
)
{
//
// Validate ...
var isValid = id.IsValidIntId();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
XTagDto result = null;
//
// Check Exists ...
isValid = await IsExists(id);
if (!isValid)
{
XException.NotFound.Throw();
}
//
var entity = await Repository.GetAsync(id);
if (entity.IsNullOrDefault())
{
XException.NotFound.Throw();
}
//
var tagEntity = model.FromDto();
entity = entity.UpdateData(
updateWith: entity,
propertyBlackList: new List<string>
{
nameof(XTagDto.Id),
nameof(XTagDto.References)
}
);
entity.References = tagEntity.References;
entity = await Repository.UpdateAsync(id, entity);
if (!entity.IsNullOrDefault())
{
result = ToDto(entity);
}
//
return result;
}
/// <summary>
/// Count Exists Entities ...
/// </summary>
@@ -472,5 +515,57 @@ namespace xTagService.Providers
return result;
}
#endregion
//
#region Hub Actions ...
/// <summary>
/// Send Custom Push Message ...
/// </summary>
/// <param name="action"></param>
/// <param name="payLoad"></param>
/// <param name="connectionId"></param>
/// <returns></returns>
public async Task SendPush(
string action,
string payLoad,
string connectionId = null
)
{
//
var actions = new List<string>
{
XBaseEntityHubAction.Add.GetStringValue(),
XBaseEntityHubAction.Update.GetStringValue(),
XBaseEntityHubAction.Delete.GetStringValue(),
XBaseEntityHubAction.AddMany.GetStringValue(),
XBaseEntityHubAction.DeleteMany.GetStringValue(),
XBaseEntityHubAction.UpdateMany.GetStringValue(),
XBaseEntityHubAction.AddOrUpdate.GetStringValue(),
};
//
// Validate ...
var isValid =
!Hub.IsNull() &&
!action.IsNullOrEmpty() &&
actions.Contains(action);
if (!isValid)
{
return;
}
//
var clients = Hub.Clients.All;
if (!connectionId.IsNullOrEmpty())
{
clients = Hub.Clients.AllExcept(connectionId);
}
try
{
await clients.SendAsync(action, payLoad, connectionId);
}
catch { }
}
#endregion
}
}