Uncomment the cache settings

This commit is contained in:
Oscar Morales
2025-06-10 23:12:43 -06:00
parent 8207048c25
commit 6cb0aea1a0
9 changed files with 95 additions and 88 deletions

View File

@@ -138,7 +138,7 @@ namespace LSA.Core.Thalos.API.Controllers
//[Permission("ModuleManagement.Write")]
public async Task<IActionResult> UpdateModuleAsync([FromRoute] string id, ModuleAdapter entity, CancellationToken cancellationToken)
{
if (id != entity._Id?.ToString())
if (id != entity.Id?.ToString())
{
return BadRequest("Module ID mismatch");
}

View File

@@ -136,7 +136,7 @@ namespace LSA.Core.Thalos.API.Controllers
//[Permission("PermissionManagement.Write")]
public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken)
{
if (id != entity._Id?.ToString())
if (id != entity.Id?.ToString())
{
return BadRequest("Permission ID mismatch");
}

View File

@@ -103,7 +103,7 @@ namespace LSA.Core.Thalos.API.Controllers
//[Permission("RoleManagement.Write")]
public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken)
{
if (id != entity._Id?.ToString())
if (id != entity.Id?.ToString())
{
return BadRequest("Role ID mismatch");
}

View File

@@ -152,7 +152,7 @@ namespace LSA.Core.Thalos.API.Controllers
//[Permission("UserManagement.Write")]
public async Task<IActionResult> UpdateUserAsync([FromRoute] string id, [FromBody] UserAdapter entity, CancellationToken cancellationToken)
{
if (id != entity._Id?.ToString())
if (id != entity.Id?.ToString())
{
return BadRequest("User ID mismatch");
}

View File

@@ -49,7 +49,7 @@ namespace Core.Thalos.Provider.Contracts
/// <param name="eamil">The User email.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns>
ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken);
ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken);
/// <summary>
/// Changes the status of the user.

View File

@@ -5,7 +5,6 @@
// ***********************************************************************
using Core.Thalos.Adapters;
using Core.Blueprint.Mongo;
using Core.Blueprint.Caching;
using Core.Blueprint.Caching.Helpers;
using Mapster;
using Microsoft.Extensions.Options;
@@ -107,9 +106,9 @@ namespace Core.Thalos.Provider.Providers.Onboarding
var builder = Builders<ModuleAdapter>.Filter;
var filters = new List<FilterDefinition<ModuleAdapter>>();
if (modules == null || !modules.Any())
if (modules != null || !modules.Any())
{
filters.Add(builder.In(x => x.Id, modules));
filters.Add(builder.In(x => x._Id, modules));
}
var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty;

View File

@@ -3,15 +3,16 @@
// AgileWebs
// </copyright>
// ***********************************************************************
using Core.Thalos.Adapters;
using Core.Blueprint.Caching.Adapters;
using Core.Blueprint.Caching.Contracts;
using Core.Blueprint.Caching.Helpers;
using Core.Blueprint.Mongo;
//using Core.Blueprint.Redis;
//using Core.Blueprint.Redis.Helpers;
using Core.Thalos.Adapters;
using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Thalos.Provider.Contracts;
using Mapster;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using Core.Thalos.Provider.Contracts;
using Core.Thalos.Domain.Contexts.Onboarding.Request;
namespace Core.Thalos.Provider.Providers.Onboarding
{
@@ -21,18 +22,18 @@ namespace Core.Thalos.Provider.Providers.Onboarding
public class PermissionProvider : IPermissionProvider
{
private readonly CollectionRepository<PermissionAdapter> repository;
//private readonly CacheSettings cacheSettings;
//private readonly IRedisCacheProvider cacheProvider;
private readonly CacheSettings cacheSettings;
private readonly ICacheProvider cacheProvider;
public PermissionProvider(CollectionRepository<PermissionAdapter> repository
//IRedisCacheProvider cacheProvider,
//IOptions<CacheSettings> cacheSettings
public PermissionProvider(CollectionRepository<PermissionAdapter> repository,
ICacheProvider cacheProvider,
IOptions<CacheSettings> cacheSettings
)
{
this.repository = repository;
this.repository.CollectionInitialization();
//this.cacheSettings = cacheSettings.Value;
//this.cacheProvider = cacheProvider;
this.cacheSettings = cacheSettings.Value;
this.cacheProvider = cacheProvider;
}
/// <summary>
@@ -58,14 +59,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>0
public async ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id);
//var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey);
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id);
var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey);
//if (cachedData is not null) { return cachedData; }
var permission = await repository.FindByIdAsync(_id);
//await cacheProvider.SetAsync(cacheKey, permission);
await cacheProvider.SetAsync(cacheKey, permission);
return permission;
}
@@ -77,14 +78,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>
public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions");
//var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions");
var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
//if (cachedData.Any()) return cachedData;
if (cachedData.Any()) return cachedData;
var permissions = await repository.AsQueryable();
//await cacheProvider.SetAsync(cacheKey, permissions);
await cacheProvider.SetAsync(cacheKey, permissions);
return permissions;
}
@@ -97,25 +98,25 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>
public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions);
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions);
//var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
//if (cachedData.Any()) return cachedData;
if (cachedData.Any()) return cachedData;
var builder = Builders<PermissionAdapter>.Filter;
var filters = new List<FilterDefinition<PermissionAdapter>>();
if (permissions == null || !permissions.Any())
if (permissions != null || !permissions.Any())
{
filters.Add(builder.In(x => x.Id, permissions));
filters.Add(builder.In(x => x._Id, permissions));
}
var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty;
var permissionsList = await repository.FilterByMongoFilterAsync(finalFilter);
//await cacheProvider.SetAsync(cacheKey, permissionsList);
await cacheProvider.SetAsync(cacheKey, permissionsList);
return permissionsList;
}

View File

@@ -3,21 +3,22 @@
// AgileWebs
// </copyright>
// ***********************************************************************
using Core.Blueprint.Caching.Adapters;
using Core.Blueprint.Caching.Contracts;
using Core.Blueprint.Caching.Helpers;
using Core.Blueprint.Mongo;
using Core.Thalos.Adapters;
using Core.Thalos.Adapters.Common.Enums;
using Core.Blueprint.Mongo;
//using Core.Blueprint.Redis;
//using Core.Blueprint.Redis.Helpers;
using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Core.Thalos.Provider.Contracts;
using Mapster;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using Core.Thalos.Provider.Contracts;
using MongoDB.Bson;
using System.Text.RegularExpressions;
using MongoDB.Bson.Serialization;
using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Microsoft.Graph;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using System.ComponentModel.Design;
using System.Text.RegularExpressions;
namespace Core.Thalos.Provider.Providers.Onboarding
{
@@ -27,19 +28,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding
public class RoleProvider : IRoleProvider
{
private readonly CollectionRepository<RoleAdapter> repository;
//private readonly CacheSettings cacheSettings;
//private readonly IRedisCacheProvider cacheProvider;
private readonly CacheSettings cacheSettings;
private readonly ICacheProvider cacheProvider;
public RoleProvider(CollectionRepository<RoleAdapter> repository
//IRedisCacheProvider cacheProvider,
//IOptions<CacheSettings> cacheSettings
)
public RoleProvider(CollectionRepository<RoleAdapter> repository,
ICacheProvider cacheProvider,
IOptions<CacheSettings> cacheSettings
)
{
this.repository = repository;
this.repository.CollectionInitialization();
//this.cacheSettings = cacheSettings.Value;
//this.cacheProvider = cacheProvider;
}
this.cacheSettings = cacheSettings.Value;
this.cacheProvider = cacheProvider;
}
/// <summary>
/// Creates a new Role.
@@ -64,14 +65,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>
public async ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id);
//var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey);
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id);
var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey);
//if (cachedData is not null) { return cachedData; }
if (cachedData is not null) { return cachedData; }
var role = await repository.FindByIdAsync(_id);
//await cacheProvider.SetAsync(cacheKey, role);
await cacheProvider.SetAsync(cacheKey, role);
return role;
}
@@ -83,14 +84,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>
public async ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles");
//var cachedData = await cacheProvider.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? [];
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles");
var cachedData = await cacheProvider.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? [];
//if (cachedData.Any()) return cachedData;
if (cachedData.Any()) return cachedData;
var roles = await repository.AsQueryable();
//await cacheProvider.SetAsync(cacheKey, roles);
await cacheProvider.SetAsync(cacheKey, roles);
return roles;
}

View File

@@ -4,18 +4,20 @@
// </copyright>
// ***********************************************************************
using Core.Blueprint.Caching.Adapters;
using Core.Blueprint.Caching.Contracts;
using Core.Blueprint.Caching.Helpers;
using Core.Blueprint.Mongo;
using Core.Thalos.Adapters;
using Core.Thalos.Adapters.Common.Enums;
using Core.Blueprint.Mongo;
//using Core.Blueprint.Redis;
//using Core.Blueprint.Redis.Helpers;
using Core.Thalos.Provider.Contracts;
using Mapster;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using Core.Thalos.Provider.Contracts;
using MongoDB.Bson;
using System.Text.RegularExpressions;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using System.Reflection;
using System.Text.RegularExpressions;
namespace Core.Thalos.Provider.Providers.Onboarding
{
@@ -25,19 +27,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding
public class UserProvider : IUserProvider
{
private readonly CollectionRepository<UserAdapter> repository;
//private readonly CacheSettings cacheSettings;
//private readonly IRedisCacheProvider cacheProvider;
private readonly CacheSettings cacheSettings;
private readonly ICacheProvider cacheProvider;
public UserProvider(CollectionRepository<UserAdapter> repository
//IRedisCacheProvider cacheProvider,
//IOptions<CacheSettings> cacheSettings
public UserProvider(CollectionRepository<UserAdapter> repository,
ICacheProvider cacheProvider,
IOptions<CacheSettings> cacheSettings
)
{
this.repository = repository;
this.repository.CollectionInitialization();
//this.cacheSettings = cacheSettings.Value;
//this.cacheProvider = cacheProvider;
}
this.cacheSettings = cacheSettings.Value;
this.cacheProvider = cacheProvider;
}
/// <summary>
/// Creates a new User.
@@ -62,14 +64,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>
public async ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id);
//var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id);
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
//if (cachedData is not null) { return cachedData; }
var user = await repository.FindByIdAsync(_id);
//await cacheProvider.SetAsync(cacheKey, user);
await cacheProvider.SetAsync(cacheKey, user);
return user;
}
@@ -81,14 +83,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>
public async ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers");
//var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? [];
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers");
var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? [];
//if (cachedData.Any()) return cachedData;
if (cachedData.Any()) return cachedData;
var users = await repository.AsQueryable();
//await cacheProvider.SetAsync(cacheKey, users);
await cacheProvider.SetAsync(cacheKey, users);
return users;
}
@@ -101,8 +103,8 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// the asynchronous execution of the service.</returns>
public async ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
//var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
//if (cachedData is not null) { return cachedData; }
@@ -110,7 +112,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
u => u.Email == email &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
//await cacheProvider.SetAsync(cacheKey, user);
await cacheProvider.SetAsync(cacheKey, user);
return user;
}
@@ -121,10 +123,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding
/// <param name="email">The User email.</param>
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
/// the asynchronous execution of the service.</returns>
public async ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken)
public async ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken)
{
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
//var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
//if (cachedData is not null) { return cachedData; }
@@ -132,9 +134,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding
u => u.Email == email &&
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
//await cacheProvider.SetAsync(cacheKey, user);
UserExistenceAdapter userExistance = new UserExistenceAdapter();
return user;
userExistance.Existence = (user != null) ? true : false;
await cacheProvider.SetAsync(cacheKey, userExistance);
return userExistance;
}
/// <summary>