From 9590a03cee6dc99e688db95db0c8c23a273a650c Mon Sep 17 00:00:00 2001 From: Sergio Matias Date: Fri, 25 Jul 2025 23:49:49 -0600 Subject: [PATCH] Revise TBB and authentication logic --- .../Controllers/ModuleController.cs | 6 +- .../Controllers/PermissionController.cs | 6 +- .../Controllers/RoleController.cs | 5 +- .../Controllers/UserController.cs | 6 +- .../Extensions/SwaggerExtensions.cs | 104 ------------------ Core.Thalos.DAL.API/Program.cs | 29 +++-- Core.Thalos.DAL.API/appsettings.Local.json | 9 ++ Core.Thalos.DAL.API/appsettings.json | 29 +---- .../Onboarding/Request/ModuleRequest.cs | 2 +- .../Onboarding/Request/PermissionRequest.cs | 2 +- .../Onboarding/Request/RoleRequest.cs | 2 +- Core.Thalos.Domain/Core.Thalos.Domain.csproj | 3 +- .../Contracts/IModuleProvider.cs | 5 +- .../Contracts/IPermissionProvider.cs | 5 +- .../Contracts/IRoleProvider.cs | 3 +- .../Contracts/IUserProvider.cs | 5 +- .../Providers/Onboarding/ModuleProvider.cs | 10 +- .../Onboarding/PermissionProvider.cs | 4 +- .../Providers/Onboarding/RoleProvider.cs | 26 ++--- .../Providers/Onboarding/UserProvider.cs | 20 ++-- .../ServiceCollectionExtensions.cs | 2 +- 21 files changed, 70 insertions(+), 213 deletions(-) delete mode 100644 Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs diff --git a/Core.Thalos.DAL.API/Controllers/ModuleController.cs b/Core.Thalos.DAL.API/Controllers/ModuleController.cs index eaf093d..e2b829d 100644 --- a/Core.Thalos.DAL.API/Controllers/ModuleController.cs +++ b/Core.Thalos.DAL.API/Controllers/ModuleController.cs @@ -5,15 +5,13 @@ // *********************************************************************** using Asp.Versioning; -using Core.Blueprint.Mongo; -using Core.Thalos.Adapters; -using Core.Thalos.Adapters.Attributes; -using Core.Thalos.Adapters.Common.Constants; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Provider.Contracts; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Graph; using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; +using StatusEnum = Core.Blueprint.Mongo.StatusEnum; namespace LSA.Core.Thalos.API.Controllers { diff --git a/Core.Thalos.DAL.API/Controllers/PermissionController.cs b/Core.Thalos.DAL.API/Controllers/PermissionController.cs index fef6015..5962382 100644 --- a/Core.Thalos.DAL.API/Controllers/PermissionController.cs +++ b/Core.Thalos.DAL.API/Controllers/PermissionController.cs @@ -5,15 +5,13 @@ // *********************************************************************** using Asp.Versioning; -using Core.Blueprint.Mongo; -using Core.Thalos.Adapters; -using Core.Thalos.Adapters.Attributes; -using Core.Thalos.Adapters.Common.Constants; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Provider.Contracts; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Graph; using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; +using StatusEnum = Core.Blueprint.Mongo.StatusEnum; namespace LSA.Core.Thalos.API.Controllers { diff --git a/Core.Thalos.DAL.API/Controllers/RoleController.cs b/Core.Thalos.DAL.API/Controllers/RoleController.cs index 9375d4a..dee539a 100644 --- a/Core.Thalos.DAL.API/Controllers/RoleController.cs +++ b/Core.Thalos.DAL.API/Controllers/RoleController.cs @@ -4,10 +4,7 @@ // // *********************************************************************** using Asp.Versioning; -using Core.Thalos.Adapters; -using Core.Thalos.Adapters.Attributes; -using Core.Thalos.Adapters.Common.Constants; -using Core.Thalos.Adapters.Common.Enums; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Provider.Contracts; using Microsoft.AspNetCore.Authorization; diff --git a/Core.Thalos.DAL.API/Controllers/UserController.cs b/Core.Thalos.DAL.API/Controllers/UserController.cs index e6db802..f5ddb8e 100644 --- a/Core.Thalos.DAL.API/Controllers/UserController.cs +++ b/Core.Thalos.DAL.API/Controllers/UserController.cs @@ -4,14 +4,12 @@ // // *********************************************************************** using Asp.Versioning; -using Core.Blueprint.Mongo; -using Core.Thalos.Adapters; -using Core.Thalos.Adapters.Attributes; -using Core.Thalos.Adapters.Common.Constants; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Provider.Contracts; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Graph; +using StatusEnum = Core.Blueprint.Mongo.StatusEnum; using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; namespace LSA.Core.Thalos.API.Controllers diff --git a/Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs b/Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs deleted file mode 100644 index 0daae61..0000000 --- a/Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs +++ /dev/null @@ -1,104 +0,0 @@ -using Asp.Versioning.ApiExplorer; -using Microsoft.Extensions.Options; -using Microsoft.Graph.ExternalConnectors; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; -using Swashbuckle.AspNetCore.SwaggerUI; - -namespace Core.Thalos.DAL.API.Extensions -{ - public static class SwaggerExtensions - { - public static void AddSwagger(this IServiceCollection services, IConfiguration configuration) - { - services.AddEndpointsApiExplorer(); - AddSwaggerGen(services, configuration); - services.AddTransient, ConfigureSwaggerOptions>(); - } - - public static void AddSwaggerGen(this IServiceCollection services, IConfiguration configuration) - { - services.AddSwaggerGen(c => - { - c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme - { - Description = "JWT Authorization header using the Bearer scheme", - Name = "Authorization", - In = ParameterLocation.Header, - Type = SecuritySchemeType.Http, - Scheme = "bearer", - BearerFormat = "JWT" - }); - - c.AddSecurityRequirement(new OpenApiSecurityRequirement - { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "Bearer" - } - }, - Array.Empty() - } - }); - }); - } - - public static void ConfigureSwagger(this WebApplication app) - { - app.UseSwagger(); - app.UseSwaggerUI(options => - { - foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) - options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); - - options.DisplayRequestDuration(); - options.EnableTryItOutByDefault(); - options.DocExpansion(DocExpansion.None); - }); - } - public static IServiceCollection AddVersioning(this IServiceCollection services) - { - services.AddApiVersioning(options => options.ReportApiVersions = true) - .AddApiExplorer(options => - { - options.GroupNameFormat = "'v'VVV"; - options.SubstituteApiVersionInUrl = true; - }); - - return services; - } - } - public class ConfigureSwaggerOptions : IConfigureOptions - { - private readonly IApiVersionDescriptionProvider _provider; - - public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) - { - _provider = provider; - } - - public void Configure(SwaggerGenOptions options) - { - foreach (var description in _provider.ApiVersionDescriptions) - options.SwaggerDoc(description.GroupName, new() - { - Title = AppDomain.CurrentDomain.FriendlyName, - Version = description.ApiVersion.ToString() - }); - - //Map ALL Values Format TODO - options.MapType(() => new() - { - Format = "date", - Example = new OpenApiString(DateOnly.MinValue.ToString()) - }); - - options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); - } - } -} diff --git a/Core.Thalos.DAL.API/Program.cs b/Core.Thalos.DAL.API/Program.cs index b690bb4..f25d640 100644 --- a/Core.Thalos.DAL.API/Program.cs +++ b/Core.Thalos.DAL.API/Program.cs @@ -1,9 +1,9 @@ using Core.Blueprint.DAL.Mongo.Configuration; +using Core.Blueprint.KeyVault.Configuration; using Core.Blueprint.Logging.Configuration; using Core.Blueprint.Redis.Configuration; -using Core.Thalos.Adapters.Extensions; -using Core.Thalos.BuildingBlocks.Authentication.Extensions; -using Core.Thalos.DAL.API.Extensions; +using Core.Thalos.BuildingBlocks; +using Core.Thalos.BuildingBlocks.Configuration; using Core.Thalos.Provider; using Microsoft.AspNetCore.HttpLogging; using System.Reflection; @@ -11,14 +11,19 @@ using System.Text.Json.Serialization; var builder = WebApplication.CreateBuilder(args); -builder.Services.ConfigureAuthentication(builder.Configuration); - -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); builder.Configuration .AddUserSecrets(Assembly.GetExecutingAssembly()) .AddEnvironmentVariables(); +var services = builder.Services.AddKeyVault(builder.Configuration); + +var authSettings = await AuthHelper.GetAuthSettings(builder.Services, builder, "thalos_common"); + +builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings); +builder.Services.AddVersioning(builder.Configuration); builder.Services.AddResponseCompression(); builder.Services.AddProblemDetails(); builder.Services.AddMemoryCache(); @@ -45,11 +50,6 @@ builder.Host.ConfigureServices((context, services) => options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); }); - services - .AddEndpointsApiExplorer() - .AddVersioning() - .AddSwagger(builder.Configuration); - services.AddHealthChecks(); services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); @@ -66,11 +66,10 @@ builder.Host.ConfigureServices((context, services) => var app = builder.Build(); -app.UseSwagger(); -app.UseSwaggerUI(); +app.UseSwaggerUI(builder.Configuration, authSettings); app.MapControllers(); app.UseCors(); -app.ConfigureSwagger(); +app.ConfigureSwagger(builder.Configuration); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); diff --git a/Core.Thalos.DAL.API/appsettings.Local.json b/Core.Thalos.DAL.API/appsettings.Local.json index c265e62..2508806 100644 --- a/Core.Thalos.DAL.API/appsettings.Local.json +++ b/Core.Thalos.DAL.API/appsettings.Local.json @@ -22,5 +22,14 @@ "ServiceSettings": { "ApplicationName": "thalos", "LayerName": "dal" + }, + "Vault": { + "Address": "http://100.123.31.103:8200", + "Token": "hvs.e37LQvLuPhTd5ALS5QQ03Cwm", + "SecretMount": "secret" + }, + "IdentityProviders": { + "Google": true, + "Azure": true } } diff --git a/Core.Thalos.DAL.API/appsettings.json b/Core.Thalos.DAL.API/appsettings.json index fc57ec1..0c208ae 100644 --- a/Core.Thalos.DAL.API/appsettings.json +++ b/Core.Thalos.DAL.API/appsettings.json @@ -4,32 +4,5 @@ "Default": "Information", "Microsoft.AspNetCore": "Warning" } - }, - "AllowedHosts": "*", - "ConnectionStrings": { - "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", - "Redis": "localhost:6379" - }, - "MongoDb": { - "DatabaseName": "Thalos", - "LocalAudience": "" - }, - "DetailedErrors": true, - "UseRedisCache": true, - "CacheSettings": { - "DefaultCacheDurationInMinutes": 3 - }, - "Authentication": { - "Google": { - "ClientId": "128345072002-mtfdgpcur44o9tbd7q6e0bb9qnp2crfp.apps.googleusercontent.com", - "ClientSecret": "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", - "ApplicationName": "Thalos", - "RedirectUri": "https://localhost:7239/api/v1/Authentication/callback" - } - }, - "JwtIssuerOptions": { - "Audience": "https://localhost:7239/", - "Issuer": "webApi" - }, - "SecretKey": "iNivDmHLpUA223sqsfhqGbMRdRj1PVkH1" + } } diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Request/ModuleRequest.cs b/Core.Thalos.Domain/Contexts/Onboarding/Request/ModuleRequest.cs index 3cf6a3d..bf30ec0 100644 --- a/Core.Thalos.Domain/Contexts/Onboarding/Request/ModuleRequest.cs +++ b/Core.Thalos.Domain/Contexts/Onboarding/Request/ModuleRequest.cs @@ -4,7 +4,7 @@ // // *********************************************************************** -using Core.Thalos.Adapters.Common.Enums; +using Core.Thalos.BuildingBlocks; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using System.Text.Json.Serialization; diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Request/PermissionRequest.cs b/Core.Thalos.Domain/Contexts/Onboarding/Request/PermissionRequest.cs index b86e5c7..0f65e92 100644 --- a/Core.Thalos.Domain/Contexts/Onboarding/Request/PermissionRequest.cs +++ b/Core.Thalos.Domain/Contexts/Onboarding/Request/PermissionRequest.cs @@ -4,7 +4,7 @@ // // *********************************************************************** -using Core.Thalos.Adapters.Common.Constants; +using Core.Thalos.BuildingBlocks; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using System.Text.Json.Serialization; diff --git a/Core.Thalos.Domain/Contexts/Onboarding/Request/RoleRequest.cs b/Core.Thalos.Domain/Contexts/Onboarding/Request/RoleRequest.cs index bed385c..051f150 100644 --- a/Core.Thalos.Domain/Contexts/Onboarding/Request/RoleRequest.cs +++ b/Core.Thalos.Domain/Contexts/Onboarding/Request/RoleRequest.cs @@ -4,7 +4,7 @@ // // *********************************************************************** -using Core.Thalos.Adapters.Common.Enums; +using Core.Thalos.BuildingBlocks; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using System.Text.Json.Serialization; diff --git a/Core.Thalos.Domain/Core.Thalos.Domain.csproj b/Core.Thalos.Domain/Core.Thalos.Domain.csproj index 742ab0f..5fa5c3c 100644 --- a/Core.Thalos.Domain/Core.Thalos.Domain.csproj +++ b/Core.Thalos.Domain/Core.Thalos.Domain.csproj @@ -7,7 +7,8 @@ - + + diff --git a/Core.Thalos.Provider/Contracts/IModuleProvider.cs b/Core.Thalos.Provider/Contracts/IModuleProvider.cs index e6b8f61..9e63dd5 100644 --- a/Core.Thalos.Provider/Contracts/IModuleProvider.cs +++ b/Core.Thalos.Provider/Contracts/IModuleProvider.cs @@ -3,8 +3,7 @@ // AgileWebs // // *********************************************************************** -using Core.Blueprint.Mongo; -using Core.Thalos.Adapters; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Domain.Contexts.Onboarding.Request; namespace Core.Thalos.Provider.Contracts @@ -50,7 +49,7 @@ namespace Core.Thalos.Provider.Contracts /// The updated entity. /// A representing /// the asynchronous execution of the service. - ValueTask ChangeModuleStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); + ValueTask ChangeModuleStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); /// /// Updates a Module by id. diff --git a/Core.Thalos.Provider/Contracts/IPermissionProvider.cs b/Core.Thalos.Provider/Contracts/IPermissionProvider.cs index dd34895..3824b61 100644 --- a/Core.Thalos.Provider/Contracts/IPermissionProvider.cs +++ b/Core.Thalos.Provider/Contracts/IPermissionProvider.cs @@ -3,8 +3,7 @@ // AgileWebs // // *********************************************************************** -using Core.Blueprint.Mongo; -using Core.Thalos.Adapters; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Domain.Contexts.Onboarding.Request; namespace Core.Thalos.Provider.Contracts @@ -50,7 +49,7 @@ namespace Core.Thalos.Provider.Contracts /// The updated entity. /// A representing /// the asynchronous execution of the service. - ValueTask ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); + ValueTask ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); /// /// Updates a Permission by id. diff --git a/Core.Thalos.Provider/Contracts/IRoleProvider.cs b/Core.Thalos.Provider/Contracts/IRoleProvider.cs index 3d516d7..a8c8676 100644 --- a/Core.Thalos.Provider/Contracts/IRoleProvider.cs +++ b/Core.Thalos.Provider/Contracts/IRoleProvider.cs @@ -3,8 +3,7 @@ // AgileWebs // // *********************************************************************** -using Core.Thalos.Adapters; -using Core.Thalos.Adapters.Common.Enums; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Domain.Contexts.Onboarding.Request; namespace Core.Thalos.Provider.Contracts diff --git a/Core.Thalos.Provider/Contracts/IUserProvider.cs b/Core.Thalos.Provider/Contracts/IUserProvider.cs index ab20202..a670c9c 100644 --- a/Core.Thalos.Provider/Contracts/IUserProvider.cs +++ b/Core.Thalos.Provider/Contracts/IUserProvider.cs @@ -3,8 +3,7 @@ // AgileWebs // // *********************************************************************** -using Core.Blueprint.Mongo; -using Core.Thalos.Adapters; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Domain.Contexts.Onboarding.Request; namespace Core.Thalos.Provider.Contracts @@ -58,7 +57,7 @@ namespace Core.Thalos.Provider.Contracts /// The new status of the user. /// A representing /// the asynchronous execution of the service. - ValueTask ChangeUserStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); + ValueTask ChangeUserStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); /// /// Updates a User by id. diff --git a/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs index 726a48d..e24135c 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs @@ -3,15 +3,15 @@ // AgileWebs // // *********************************************************************** -using Core.Thalos.Adapters; using Core.Blueprint.Mongo; +using Core.Blueprint.Redis; +using Core.Blueprint.Redis.Helpers; +using Core.Thalos.BuildingBlocks; +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; -using Core.Blueprint.Redis; -using Core.Blueprint.Redis.Helpers; namespace Core.Thalos.Provider.Providers.Onboarding { diff --git a/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs index ad3a0d1..5abc218 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs @@ -6,7 +6,7 @@ using Core.Blueprint.Mongo; using Core.Blueprint.Redis; using Core.Blueprint.Redis.Helpers; -using Core.Thalos.Adapters; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Provider.Contracts; using Mapster; @@ -128,7 +128,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding /// The new status of the permission. /// A representing /// the asynchronous execution of the service. - public async ValueTask ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken) + public async ValueTask ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) { var entity = await repository.FindByIdAsync(id); entity.Status = newStatus; diff --git a/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs index dd2b7cb..02eafb8 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs @@ -6,18 +6,12 @@ using Core.Blueprint.Mongo; using Core.Blueprint.Redis; using Core.Blueprint.Redis.Helpers; -using Core.Thalos.Adapters; -using Core.Thalos.Adapters.Common.Enums; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Domain.Contexts.Onboarding.Request; using Core.Thalos.Provider.Contracts; using Mapster; using Microsoft.Extensions.Options; -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 +21,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding public class RoleProvider : IRoleProvider { private readonly CollectionRepository repository; - private readonly CacheSettings cacheSettings; - private readonly IRedisCacheProvider cacheProvider; + private readonly CacheSettings cacheSettings; + private readonly IRedisCacheProvider cacheProvider; - public RoleProvider(CollectionRepository repository, - IRedisCacheProvider cacheProvider, - IOptions cacheSettings - ) + public RoleProvider(CollectionRepository repository, + IRedisCacheProvider cacheProvider, + IOptions cacheSettings + ) { this.repository = repository; this.repository.CollectionInitialization(); - this.cacheSettings = cacheSettings.Value; - this.cacheProvider = cacheProvider; - } + this.cacheSettings = cacheSettings.Value; + this.cacheProvider = cacheProvider; + } /// /// Creates a new Role. diff --git a/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs b/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs index 83e8105..0b8a570 100644 --- a/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs +++ b/Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs @@ -7,15 +7,13 @@ using Core.Blueprint.Mongo; using Core.Blueprint.Redis; using Core.Blueprint.Redis.Helpers; -using Core.Thalos.Adapters; -using Core.Thalos.Adapters.Common.Enums; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Provider.Contracts; using Mapster; using Microsoft.Extensions.Options; using MongoDB.Bson; using MongoDB.Bson.Serialization; using MongoDB.Driver; -using System.Reflection; using System.Text.RegularExpressions; namespace Core.Thalos.Provider.Providers.Onboarding @@ -27,18 +25,18 @@ namespace Core.Thalos.Provider.Providers.Onboarding { private readonly CollectionRepository repository; private readonly CacheSettings cacheSettings; - private readonly IRedisCacheProvider cacheProvider; + private readonly IRedisCacheProvider cacheProvider; - public UserProvider(CollectionRepository repository, + public UserProvider(CollectionRepository repository, IRedisCacheProvider cacheProvider, - IOptions cacheSettings + IOptions cacheSettings ) { this.repository = repository; this.repository.CollectionInitialization(); - this.cacheSettings = cacheSettings.Value; - this.cacheProvider = cacheProvider; - } + this.cacheSettings = cacheSettings.Value; + this.cacheProvider = cacheProvider; + } /// /// Creates a new User. @@ -108,7 +106,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding //if (cachedData is not null) { return cachedData; } var user = await repository.FindOneAsync( - u => u.Email == email && + u => u.Email == email && u.Status == Core.Blueprint.Mongo.StatusEnum.Active); await cacheProvider.SetAsync(cacheKey, user); @@ -419,7 +417,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding .Select(c => c.AsString) .ToArray() : Array.Empty(), - Projects = result.Contains("projects") && result["projects"].IsBsonArray + Projects = result.Contains("projects") && result["projects"].IsBsonArray ? result["projects"].AsBsonArray .Where(p => p != null && !p.IsBsonNull) .Select(p => p.AsString) diff --git a/Core.Thalos.Provider/ServiceCollectionExtensions.cs b/Core.Thalos.Provider/ServiceCollectionExtensions.cs index 3d55719..b1af15d 100644 --- a/Core.Thalos.Provider/ServiceCollectionExtensions.cs +++ b/Core.Thalos.Provider/ServiceCollectionExtensions.cs @@ -1,5 +1,5 @@ using Core.Blueprint.Mongo; -using Core.Thalos.Adapters; +using Core.Thalos.BuildingBlocks; using Core.Thalos.Provider.Contracts; using Core.Thalos.Provider.Providers.Onboarding; using Microsoft.Extensions.Configuration;