diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/ModuleMapper.cs b/Core.Thalos.Domain/Contexts/Onboarding/Mappers/ModuleMapper.cs deleted file mode 100644 index a78e334..0000000 --- a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/ModuleMapper.cs +++ /dev/null @@ -1,42 +0,0 @@ -// *********************************************************************** -// -// AgileWebs -// -// *********************************************************************** -using Core.Thalos.Adapters; -using Core.Thalos.Domain.Contexts.Onboarding.Request; -using Microsoft.AspNetCore.Http; -using MongoDB.Bson; -using System.Security.Claims; -namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers -{ - /// - /// Handles mappings between - /// , - /// and - /// - public static class ModuleMapper - { - /// - /// Maps the permissionRequest to ModuleAdapter. - /// - /// The Module to be mapped. - /// A representing - /// the asynchronous execution of the service. - public static ModuleAdapter ToAdapter(this ModuleRequest newModule, IHttpContextAccessor httpContextAccessor) - { - return new ModuleAdapter - { - Id = ObjectId.GenerateNewId().ToString(), - Name = newModule.Name, - Description = newModule.Description, - Icon = newModule.Icon, - Route = newModule.Route, - Order = newModule.Order, - Application = newModule.Application, - CreatedAt = DateTime.UtcNow, - CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty, - }; - } - } -} diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/PermissionMapper.cs b/Core.Thalos.Domain/Contexts/Onboarding/Mappers/PermissionMapper.cs deleted file mode 100644 index e0a0241..0000000 --- a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/PermissionMapper.cs +++ /dev/null @@ -1,39 +0,0 @@ -// *********************************************************************** -// -// AgileWebs -// -// *********************************************************************** -using Core.Thalos.Adapters; -using Core.Thalos.Domain.Contexts.Onboarding.Request; -using Microsoft.AspNetCore.Http; -using MongoDB.Bson; -using System.Security.Claims; -namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers -{ - /// - /// Handles mappings between - /// , - /// and - /// - public static class PermissionMapper - { - /// - /// Maps the permissionRequest to PermissionAdapter. - /// - /// The Permission to be mapped. - /// A representing - /// the asynchronous execution of the service. - public static PermissionAdapter ToAdapter(this PermissionRequest newPermission, IHttpContextAccessor httpContextAccessor) - { - return new PermissionAdapter - { - Id = ObjectId.GenerateNewId().ToString(), - Name = newPermission.Name, - Description = newPermission.Description, - CreatedAt = DateTime.UtcNow, - CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty, - AccessLevel = newPermission.AccessLevel - }; - } - } -} diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/RoleMapper.cs b/Core.Thalos.Domain/Contexts/Onboarding/Mappers/RoleMapper.cs deleted file mode 100644 index 7d688d8..0000000 --- a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/RoleMapper.cs +++ /dev/null @@ -1,42 +0,0 @@ -// *********************************************************************** -// -// AgileWebs -// -// *********************************************************************** - -using Core.Thalos.Adapters; -using Core.Thalos.Domain.Contexts.Onboarding.Request; -using Microsoft.AspNetCore.Http; -using MongoDB.Bson; -using System.Security.Claims; -namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers -{ - /// - /// Handles mappings between - /// , - /// and - /// - public static class RoleMapper - { - /// - /// Maps the RoleRequest to RoleAdapter. - /// - /// The Role to be mapped. - /// A representing - /// the asynchronous execution of the service. - public static RoleAdapter ToAdapter(this RoleRequest newRole, IHttpContextAccessor httpContextAccessor) - { - return new RoleAdapter - { - Id = ObjectId.GenerateNewId().ToString(), - Name = newRole.Name, - Description = newRole.Description, - Applications = newRole.Applications, - Modules = newRole.Modules, - Permissions = newRole.Permissions, - CreatedAt = DateTime.UtcNow, - CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty - }; - } - } -} diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/UserMapper.cs b/Core.Thalos.Domain/Contexts/Onboarding/Mappers/UserMapper.cs deleted file mode 100644 index 66f07d2..0000000 --- a/Core.Thalos.Domain/Contexts/Onboarding/Mappers/UserMapper.cs +++ /dev/null @@ -1,46 +0,0 @@ -// *********************************************************************** -// -// AgileWebs -// -// *********************************************************************** -using Core.Thalos.Adapters; -using Core.Thalos.Domain.Contexts.Onboarding.Request; -using Microsoft.AspNetCore.Http; -using MongoDB.Bson; -using System.Security.Claims; - -namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers -{ - /// - /// Handles mappings between - /// , - /// and - /// - public static class UserMapper - { - /// - /// Maps the UserRequest to UserAdapter. - /// - /// The User to be mapped. - /// A representing - /// the asynchronous execution of the service. - public static UserAdapter ToAdapter(this UserRequest newUser, IHttpContextAccessor httpContextAccessor) - { - return new UserAdapter - { - Id = ObjectId.GenerateNewId().ToString(), - Guid = Guid.NewGuid().ToString(), - Email = newUser.Email, - Name = newUser.Name, - MiddleName = newUser.MiddleName, - LastName = newUser.LastName, - DisplayName = $"{newUser.Name} {newUser.MiddleName} {newUser.LastName}", - RoleId = newUser.RoleId, - Companies = newUser.Companies, - Projects = newUser.Projects, - CreatedAt = DateTime.UtcNow, - CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty - }; - } - } -} diff --git a/Core.Thalos.Infraestructure/Caching/CacheHelper.cs b/Core.Thalos.Infraestructure/Caching/CacheHelper.cs deleted file mode 100644 index ca20c8d..0000000 --- a/Core.Thalos.Infraestructure/Caching/CacheHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Core.Thalos.Infraestructure.Caching.Configs; - -namespace LSA.Core.Dapper.Service.Caching -{ - public static class CacheHelper - { - /// - /// Determines the cache duration based on specific duration, settings, or a default value. - /// - /// Specific cache duration in minutes, if provided. - /// General cache settings containing default duration values. - /// The cache duration as a TimeSpan. - public static TimeSpan GetCacheDuration(CacheSettings cacheSettings, int? specificCacheDuration = 0) - { - var defaultCacheDuration = TimeSpan.FromMinutes(.5); - - if (specificCacheDuration.HasValue && specificCacheDuration.Value > 0) - { - return TimeSpan.FromMinutes(specificCacheDuration.Value); - } - - if (cacheSettings.DefaultCacheDurationInMinutes > 0) - { - return TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes); - } - - return defaultCacheDuration; - } - } -} diff --git a/Core.Thalos.Infraestructure/Caching/CacheKeyHelper.cs b/Core.Thalos.Infraestructure/Caching/CacheKeyHelper.cs deleted file mode 100644 index d1db226..0000000 --- a/Core.Thalos.Infraestructure/Caching/CacheKeyHelper.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; - -namespace LSA.Core.Dapper.Service.Caching -{ - public static class CacheKeyHelper - { - public static string GenerateCacheKey(object instance, string methodName, params object[] parameters) - { - var className = instance.GetType().Name; - var keyBuilder = new StringBuilder($"{className}.{methodName}"); - - foreach (var param in parameters) - { - string normalizedParam = NormalizeParameter(param); - keyBuilder.Append($".{normalizedParam}"); - } - - return keyBuilder.ToString(); - } - - private static string NormalizeParameter(object param) - { - if (param == null) - { - return "null"; - } - - string paramString; - - if (param is DateTime dateTime) - { - paramString = dateTime.ToString("yyyyMMdd"); - } - else - { - paramString = param.ToString(); - } - - // Replace special characters with an underscore - string normalizedParam = Regex.Replace(paramString, @"[^a-zA-Z0-9]", "_"); - - return normalizedParam; - } - } -} diff --git a/Core.Thalos.Infraestructure/Caching/CacheService.cs b/Core.Thalos.Infraestructure/Caching/CacheService.cs deleted file mode 100644 index c45ec31..0000000 --- a/Core.Thalos.Infraestructure/Caching/CacheService.cs +++ /dev/null @@ -1,133 +0,0 @@ -using Azure.Identity; -using Core.Thalos.Infraestructure.Caching.Contracts; -using Microsoft.Extensions.Logging; -using StackExchange.Redis; -using System.Text.Json; - -namespace LSA.Core.Dapper.Service.Caching -{ - public class CacheService : ICacheService - { - private IDatabase _cacheDatabase = null!; - private readonly ILogger _logger; - - - public CacheService(string connectionString, ILogger logger) - { - _logger = logger; - Task.Run(async () => - { - _cacheDatabase = await GetRedisDatabase(connectionString); - }).Wait(); - } - - private async Task GetRedisDatabase(string connectionString) - { - try - { - var configurationOptions = await ConfigurationOptions.Parse($"{connectionString}") - .ConfigureForAzureWithTokenCredentialAsync(new DefaultAzureCredential()); - - configurationOptions.AbortOnConnectFail = false; - var connectionMultiplexer = await ConnectionMultiplexer.ConnectAsync(configurationOptions); - - _logger.LogInformation("Successfully connected to Redis."); - - return connectionMultiplexer.GetDatabase(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error establishing Redis connection."); - throw; - } - } - - - public async Task GetAsync(string key) - { - try - { - var value = await _cacheDatabase.StringGetAsync(key); - if (value.IsNullOrEmpty) - { - _logger.LogInformation($"Cache miss for key: {key}"); - return default; - } - - _logger.LogInformation($"Cache hit for key: {key}"); - return JsonSerializer.Deserialize(value); - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error getting cache item with key {key}"); - throw; - } - } - - public async Task SetAsync(string key, T value, TimeSpan? expiry = null) - { - try - { - var json = JsonSerializer.Serialize(value); - await _cacheDatabase.StringSetAsync(key, json, expiry); - _logger.LogInformation($"Cache item set with key: {key}"); - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error setting cache item with key {key}"); - throw; - } - } - - public async Task RemoveAsync(string key) - { - try - { - await _cacheDatabase.KeyDeleteAsync(key); - _logger.LogInformation($"Cache item removed with key: {key}"); - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error removing cache item with key {key}"); - throw; - } - } - - public async Task ExistsAsync(string key) - { - try - { - var exists = await _cacheDatabase.KeyExistsAsync(key); - _logger.LogInformation($"Cache item exists check for key: {key} - {exists}"); - return exists; - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error checking existence of cache item with key {key}"); - throw; - } - } - - public async Task RefreshAsync(string key, TimeSpan? expiry = null) - { - try - { - var value = await _cacheDatabase.StringGetAsync(key); - if (!value.IsNullOrEmpty) - { - await _cacheDatabase.StringSetAsync(key, value, expiry); - _logger.LogInformation($"Cache item refreshed with key: {key}"); - } - else - { - _logger.LogWarning($"Cache item with key: {key} does not exist, cannot refresh"); - } - } - catch (Exception ex) - { - _logger.LogError(ex, $"Error refreshing cache item with key {key}"); - throw; - } - } - } -} diff --git a/Core.Thalos.Infraestructure/Caching/Configs/CacheSettings.cs b/Core.Thalos.Infraestructure/Caching/Configs/CacheSettings.cs deleted file mode 100644 index 98693a9..0000000 --- a/Core.Thalos.Infraestructure/Caching/Configs/CacheSettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Core.Thalos.Infraestructure.Caching.Configs -{ - public class CacheSettings - { - public int DefaultCacheDurationInMinutes { get; set; } - } -} \ No newline at end of file diff --git a/Core.Thalos.Infraestructure/Caching/Contracts/ICacheService.cs b/Core.Thalos.Infraestructure/Caching/Contracts/ICacheService.cs deleted file mode 100644 index 5b1768e..0000000 --- a/Core.Thalos.Infraestructure/Caching/Contracts/ICacheService.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Core.Thalos.Infraestructure.Caching.Contracts -{ - public interface ICacheService - { - Task GetAsync(string key); - Task SetAsync(string key, T value, TimeSpan? expiry = null); - Task RemoveAsync(string key); - Task ExistsAsync(string key); - Task RefreshAsync(string key, TimeSpan? expiry = null); - } -} diff --git a/Core.Thalos.Infraestructure/Contexts/Mongo/ConnectionStringProvider.cs b/Core.Thalos.Infraestructure/Contexts/Mongo/ConnectionStringProvider.cs deleted file mode 100644 index 02862ef..0000000 --- a/Core.Thalos.Infraestructure/Contexts/Mongo/ConnectionStringProvider.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.Extensions.Configuration; - -namespace Core.Thalos.Infraestructure.Contexts.Mongo -{ - public class ConnectionStringProvider(IConfiguration configuration) : IConnectionStringProvider - { - public string ConnectionString { get; set; } = string.Empty; - public string Databasename { get; set; } = string.Empty; - public string Audience { get; set; } = string.Empty; - - public string GetConnectionString() - { - return configuration?.GetConnectionString("DefaultConnection")?.ToString() ?? string.Empty; - } - public string GetDatabasename() - { - return configuration.GetSection("MongoDb:DatabaseName").Value ?? string.Empty; - } - - public string GetAudience() - { - return configuration.GetSection("MongoDb:Audience").Value ?? string.Empty; - } - } - public interface IConnectionStringProvider - { - string GetConnectionString(); - string GetDatabasename(); - string ConnectionString { get; set; } - string Databasename { get; set; } - string Audience { get; set; } - } -} diff --git a/Core.Thalos.Infraestructure/Contexts/Mongo/MongoConnSettings.cs b/Core.Thalos.Infraestructure/Contexts/Mongo/MongoConnSettings.cs deleted file mode 100644 index 69b9d1e..0000000 --- a/Core.Thalos.Infraestructure/Contexts/Mongo/MongoConnSettings.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Core.Thalos.Infraestructure.Contexts.Mongo; - -public interface IMongoConnSettings -{ - string ConnectionString { get; set; } - string Databasename { get; set; } - string Audience { get; set; } -} -public class MongoConnSettings : IMongoConnSettings -{ - public string ConnectionString { get; set; } - public string Databasename { get; set; } - public string Audience { get; set; } -} diff --git a/Core.Thalos.Infraestructure/PerformanceCacheService/CacheAttribute.cs b/Core.Thalos.Infraestructure/PerformanceCacheService/CacheAttribute.cs deleted file mode 100644 index 7e1dbe3..0000000 --- a/Core.Thalos.Infraestructure/PerformanceCacheService/CacheAttribute.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Core.Thalos.Infraestructure.PerformanceCacheService -{ - [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] - public class CacheAttribute : Attribute - { - public int CacheDurationInMinutes { get; set; } - public bool EnableCaching { get; set; } - - public CacheAttribute(int cacheDurationInMinutes, bool enableCaching = true) - { - CacheDurationInMinutes = cacheDurationInMinutes; - EnableCaching = enableCaching; - } - } -} diff --git a/Core.Thalos.Provider/ServiceCollectionExtensions.cs b/Core.Thalos.Provider/ServiceCollectionExtensions.cs index bdd18cd..3d55719 100644 --- a/Core.Thalos.Provider/ServiceCollectionExtensions.cs +++ b/Core.Thalos.Provider/ServiceCollectionExtensions.cs @@ -1,16 +1,9 @@ using Core.Blueprint.Mongo; using Core.Thalos.Adapters; -using Core.Thalos.Infraestructure.Caching.Contracts; -using Core.Thalos.Infraestructure.Contexts.Mongo; using Core.Thalos.Provider.Contracts; -using Core.Thalos.Provider.Providers; using Core.Thalos.Provider.Providers.Onboarding; -using LSA.Core.Dapper.Service.Caching; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using MongoDB.Driver; namespace Core.Thalos.Provider { @@ -33,33 +26,5 @@ namespace Core.Thalos.Provider return services; } - - private static IServiceCollection AddLogs(this IServiceCollection services) - { - services.AddLogging(); - var serviceProvider = services.BuildServiceProvider(); - //var logger = serviceProvider.GetService>(); //Add for Markup class later TODO - - //services.AddSingleton(typeof(ILogger), logger); - - return services; - } - - private static IServiceCollection AddRedisCacheService(this IServiceCollection services, IConfiguration configuration) - { - var source = configuration.GetSection("ConnectionStrings"); - - var redisConnectionString = source["Redis"]?.ToString(); - - if (string.IsNullOrEmpty(redisConnectionString)) - { - throw new InvalidOperationException("Redis connection string is not configured."); - } - - services.AddSingleton(provider => - new CacheService(redisConnectionString, provider.GetRequiredService>())); - - return services; - } } }