Compare commits
10 Commits
feature/co
...
7c92a7e791
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c92a7e791 | |||
| 570e74a199 | |||
| 9590a03cee | |||
|
|
82166f5042 | ||
| 5922a53b93 | |||
| 13774093b4 | |||
| 7cd08411b9 | |||
| 1d52ee424d | |||
| 4a26ecc83a | |||
| c85897fd1a |
@@ -9,8 +9,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Domain", "Core.Thalos.Domain\Core.Thalos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Infrastructure", "Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}"
|
||||
@@ -29,10 +27,6 @@ Global
|
||||
{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BE8E05D6-05B2-4317-B619-21853B7D21DB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{43BD5F47-132F-4E78-83F1-A1FEED01A502}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8CAE8380-475F-46B8-AF90-C495AAC58606}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8CAE8380-475F-46B8-AF90-C495AAC58606}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -44,7 +38,6 @@ Global
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{F00B4683-03B3-487A-9608-4B30675AA278} = {36839283-6407-476A-BB33-F0EE90383E2B}
|
||||
{BE8E05D6-05B2-4317-B619-21853B7D21DB} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E}
|
||||
{43BD5F47-132F-4E78-83F1-A1FEED01A502} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E}
|
||||
{8CAE8380-475F-46B8-AF90-C495AAC58606} = {2E7D918E-AB9F-44BF-A334-FD675C9B626E}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -4,10 +4,7 @@
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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;
|
||||
|
||||
@@ -4,14 +4,12 @@
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
@@ -224,86 +222,6 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a company to the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user identifier.</param>
|
||||
/// <param name="companyId">The company identifier to add.</param>
|
||||
/// <returns>The updated <see cref="UserAdapter"/> entity.</returns>
|
||||
/// <response code="200">The user with the updated companies.</response>
|
||||
/// <response code="404">The user or company not found.</response>
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPost]
|
||||
[Route(Routes.AddCompany)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a company from the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user identifier.</param>
|
||||
/// <param name="companyId">The company identifier to remove.</param>
|
||||
/// <returns>The updated <see cref="UserAdapter"/> entity.</returns>
|
||||
/// <response code="200">The user with the updated companies.</response>
|
||||
/// <response code="404">The user or company not found.</response>
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpDelete]
|
||||
[Route(Routes.RemoveCompany)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ;
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a project to the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user identifier.</param>
|
||||
/// <param name="projectId">The project identifier to add.</param>
|
||||
/// <returns>The updated <see cref="UserAdapter"/> entity.</returns>
|
||||
/// <response code="200">The user with the updated projects.</response>
|
||||
/// <response code="404">The user or project not found.</response>
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPost]
|
||||
[Route(Routes.AddProject)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a project from the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user identifier.</param>
|
||||
/// <param name="projectId">The project identifier to remove.</param>
|
||||
/// <returns>The updated <see cref="UserAdapter"/> entity.</returns>
|
||||
/// <response code="200">The user with the updated projects.</response>
|
||||
/// <response code="404">The user or project not found.</response>
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpDelete]
|
||||
[Route(Routes.RemoveProject)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a token for the user, including roles, permissions, and modules.
|
||||
/// </summary>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Blueprint.Logging" Version="1.0.0" />
|
||||
<PackageReference Include="Core.Blueprint.Logging" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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<IConfigureOptions<SwaggerGenOptions>, 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<string>()
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
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<SwaggerGenOptions>
|
||||
{
|
||||
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<DateOnly>(() => new()
|
||||
{
|
||||
Format = "date",
|
||||
Example = new OpenApiString(DateOnly.MinValue.ToString())
|
||||
});
|
||||
|
||||
options.CustomSchemaIds(type => type.ToString().Replace("+", "."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using Core.Blueprint.Caching.Configuration;
|
||||
using Core.Blueprint.DAL.Mongo.Configuration;
|
||||
using Core.Blueprint.KeyVault.Configuration;
|
||||
using Core.Blueprint.Logging.Configuration;
|
||||
using Core.Thalos.Adapters.Extensions;
|
||||
using Core.Thalos.BuildingBlocks.Authentication.Extensions;
|
||||
using Core.Thalos.DAL.API.Extensions;
|
||||
using Core.Blueprint.Redis.Configuration;
|
||||
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,20 +66,22 @@ builder.Host.ConfigureServices((context, services) =>
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.MapControllers();
|
||||
app.UseLogging(builder.Configuration);
|
||||
app.UseSwaggerUI(builder.Configuration, authSettings);
|
||||
app.ConfigureSwagger(builder.Configuration);
|
||||
|
||||
app.UseRouting();
|
||||
app.UseCors();
|
||||
app.ConfigureSwagger();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseResponseCompression();
|
||||
app.UseOutputCache();
|
||||
app.UseResponseCaching();
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseLogging(builder.Configuration);
|
||||
|
||||
app.MapControllers();
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
app.Run();
|
||||
35
Core.Thalos.DAL.API/appsettings.Local.json
Normal file
35
Core.Thalos.DAL.API/appsettings.Local.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256",
|
||||
"Redis": "100.123.31.103:6379"
|
||||
},
|
||||
"MongoDb": {
|
||||
"DatabaseName": "Thalos",
|
||||
"LocalAudience": ""
|
||||
},
|
||||
"DetailedErrors": true,
|
||||
"UseRedisCache": true,
|
||||
"CacheSettings": {
|
||||
"DefaultCacheDurationInMinutes": 3
|
||||
},
|
||||
"ServiceSettings": {
|
||||
"ApplicationName": "thalos",
|
||||
"LayerName": "dal"
|
||||
},
|
||||
"Vault": {
|
||||
"Address": "http://100.123.31.103:8200",
|
||||
"Token": "hvs.e37LQvLuPhTd5ALS5QQ03Cwm",
|
||||
"SecretMount": "secret"
|
||||
},
|
||||
"IdentityProviders": {
|
||||
"Google": true,
|
||||
"Azure": true
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleMapper.cs">
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles mappings between
|
||||
/// <see cref="ModuleRequest"/>,
|
||||
/// and <see cref="ModuleAdapter"/>
|
||||
/// </summary>
|
||||
public static class ModuleMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps the permissionRequest to ModuleAdapter.
|
||||
/// </summary>
|
||||
/// <param name="newModule">The Module to be mapped.</param>
|
||||
/// <returns>A <see cref="ModuleAdapter"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="PermissionMapper.cs">
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles mappings between
|
||||
/// <see cref="PermissionRequest"/>,
|
||||
/// and <see cref="PermissionAdapter"/>
|
||||
/// </summary>
|
||||
public static class PermissionMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps the permissionRequest to PermissionAdapter.
|
||||
/// </summary>
|
||||
/// <param name="newPermission">The Permission to be mapped.</param>
|
||||
/// <returns>A <see cref="PermissionAdapter"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleMapper.cs">
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles mappings between
|
||||
/// <see cref="RoleRequest"/>,
|
||||
/// and <see cref="RoleAdapter"/>
|
||||
/// </summary>
|
||||
public static class RoleMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps the RoleRequest to RoleAdapter.
|
||||
/// </summary>
|
||||
/// <param name="newRole">The Role to be mapped.</param>
|
||||
/// <returns>A <see cref="RoleAdapter"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
// ***********************************************************************
|
||||
// <copyright file="UserMapper.cs">
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles mappings between
|
||||
/// <see cref="UserRequest"/>,
|
||||
/// and <see cref="UserAdapter"/>
|
||||
/// </summary>
|
||||
public static class UserMapper
|
||||
{
|
||||
/// <summary>
|
||||
/// Maps the UserRequest to UserAdapter.
|
||||
/// </summary>
|
||||
/// <param name="newUser">The User to be mapped.</param>
|
||||
/// <returns>A <see cref="UserAdapter"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
using Core.Thalos.Adapters.Common.Enums;
|
||||
using Core.Thalos.BuildingBlocks;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
using Core.Thalos.Adapters.Common.Constants;
|
||||
using Core.Thalos.BuildingBlocks;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
|
||||
using Core.Thalos.Adapters.Common.Enums;
|
||||
using Core.Thalos.BuildingBlocks;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@@ -54,19 +54,5 @@ namespace Core.Thalos.Domain.Contexts.Onboarding.Request
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
[JsonPropertyName("roleId")]
|
||||
public string RoleId { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the array of companies associated with the user.
|
||||
/// </summary>
|
||||
[BsonElement("companies")]
|
||||
[JsonPropertyName("companies")]
|
||||
public string[] Companies { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the array of projects associated with the user.
|
||||
/// </summary>
|
||||
[BsonElement("projects")]
|
||||
[JsonPropertyName("projects")]
|
||||
public string[]? Projects { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.5" />
|
||||
<PackageReference Include="Core.Blueprint.KeyVault" Version="1.0.3" />
|
||||
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.8" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
using Core.Thalos.Infraestructure.Caching.Configs;
|
||||
|
||||
namespace LSA.Core.Dapper.Service.Caching
|
||||
{
|
||||
public static class CacheHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines the cache duration based on specific duration, settings, or a default value.
|
||||
/// </summary>
|
||||
/// <param name="specificCacheDuration">Specific cache duration in minutes, if provided.</param>
|
||||
/// <param name="cacheSettings">General cache settings containing default duration values.</param>
|
||||
/// <returns>The cache duration as a TimeSpan.</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<CacheService> _logger;
|
||||
|
||||
|
||||
public CacheService(string connectionString, ILogger<CacheService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
_cacheDatabase = await GetRedisDatabase(connectionString);
|
||||
}).Wait();
|
||||
}
|
||||
|
||||
private async Task<IDatabase> 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<T> GetAsync<T>(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<T>(value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Error getting cache item with key {key}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetAsync<T>(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<bool> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Core.Thalos.Infraestructure.Caching.Configs
|
||||
{
|
||||
public class CacheSettings
|
||||
{
|
||||
public int DefaultCacheDurationInMinutes { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Core.Thalos.Infraestructure.Caching.Contracts
|
||||
{
|
||||
public interface ICacheService
|
||||
{
|
||||
Task<T> GetAsync<T>(string key);
|
||||
Task SetAsync<T>(string key, T value, TimeSpan? expiry = null);
|
||||
Task RemoveAsync(string key);
|
||||
Task<bool> ExistsAsync(string key);
|
||||
Task RefreshAsync(string key, TimeSpan? expiry = 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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,7 @@
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
/// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns>
|
||||
/// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
ValueTask<ModuleAdapter> ChangeModuleStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<ModuleAdapter> ChangeModuleStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a Module by id.
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
/// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns>
|
||||
/// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<PermissionAdapter> ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a Permission by id.
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
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
|
||||
/// <param name="newStatus">The new status of the user.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
ValueTask<UserAdapter> ChangeUserStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<UserAdapter> ChangeUserStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a User by id.
|
||||
@@ -85,39 +84,6 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a company to the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user to whom the company will be added.</param>
|
||||
/// <param name="companyId">The identifier of the company to add.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a company from the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user from whom the company will be removed.</param>
|
||||
/// <param name="companyId">The identifier of the company to remove.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a project to the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user to whom the project will be added.</param>
|
||||
/// <param name="projectId">The identifier of the project to add.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Removes a project from the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user from whom the project will be removed.</param>
|
||||
/// <param name="projectId">The identifier of the project to remove.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the token adapter for a user.
|
||||
/// </summary>
|
||||
|
||||
@@ -12,13 +12,12 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Blueprint.Mongo" Version="1.0.0" />
|
||||
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.0" />
|
||||
<PackageReference Include="Core.Blueprint.Redis" Version="1.0.2" />
|
||||
<PackageReference Include="Mapster" Version="7.4.2-pre02" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" />
|
||||
<ProjectReference Include="..\Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Core.Thalos.Provider.Providers
|
||||
{
|
||||
public class BaseProvider
|
||||
{
|
||||
private readonly IMongoDatabase _database;
|
||||
|
||||
public BaseProvider(IMongoDatabase database)
|
||||
{
|
||||
_database = database ?? throw new ArgumentNullException(nameof(database));
|
||||
}
|
||||
|
||||
protected IMongoDatabase Database => _database;
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
using Azure.Core;
|
||||
using Azure.Identity;
|
||||
using Core.Thalos.Adapters.Common.Constants;
|
||||
using MongoDB.Driver.Authentication.Oidc;
|
||||
|
||||
namespace Core.Thalos.Provider.Providers
|
||||
{
|
||||
public class HeathOidcCallback : IOidcCallback
|
||||
{
|
||||
private readonly string _audience;
|
||||
private readonly string _environment;
|
||||
public HeathOidcCallback(string audience)
|
||||
{
|
||||
_audience = audience;
|
||||
_environment = Environment.GetEnvironmentVariable(EnvironmentVariables.Stage) ?? string.Empty;
|
||||
}
|
||||
|
||||
public OidcAccessToken GetOidcAccessToken(OidcCallbackParameters parameters, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
AccessToken token;
|
||||
|
||||
TokenRequestContext tokenRequestContext =
|
||||
new TokenRequestContext(
|
||||
new[] { _audience }
|
||||
);
|
||||
|
||||
if (_environment == "Local")
|
||||
{
|
||||
token =
|
||||
new ChainedTokenCredential(
|
||||
new ManagedIdentityCredential(),
|
||||
new VisualStudioCredential(),
|
||||
new VisualStudioCodeCredential(),
|
||||
new SharedTokenCacheCredential()
|
||||
)
|
||||
.GetToken(
|
||||
tokenRequestContext
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
token =
|
||||
new ManagedIdentityCredential()
|
||||
.GetToken(
|
||||
tokenRequestContext
|
||||
);
|
||||
}
|
||||
|
||||
return new(token.Token, expiresIn: null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OidcAccessToken> GetOidcAccessTokenAsync(OidcCallbackParameters parameters, CancellationToken cancellationToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
TokenRequestContext tokenRequestContext =
|
||||
new TokenRequestContext(
|
||||
new[] { _audience }
|
||||
);
|
||||
|
||||
AccessToken token;
|
||||
|
||||
if (_environment == "Local")
|
||||
{
|
||||
token = await new ChainedTokenCredential(
|
||||
new ManagedIdentityCredential(),
|
||||
new VisualStudioCredential(),
|
||||
new VisualStudioCodeCredential(),
|
||||
new SharedTokenCacheCredential()
|
||||
)
|
||||
.GetTokenAsync(
|
||||
tokenRequestContext, cancellationToken
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
token = await new ManagedIdentityCredential()
|
||||
.GetTokenAsync(
|
||||
tokenRequestContext, cancellationToken
|
||||
).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return new(token.Token, expiresIn: null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"An error ocurred while trying to get the OIDC token to connect to the database, ERROR: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,15 @@
|
||||
// AgileWebs
|
||||
// </copyright>
|
||||
// ***********************************************************************
|
||||
using Core.Thalos.Adapters;
|
||||
using Core.Blueprint.Mongo;
|
||||
using Core.Blueprint.Caching.Helpers;
|
||||
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.Caching.Contracts;
|
||||
using Core.Blueprint.Caching.Adapters;
|
||||
|
||||
namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
@@ -23,10 +22,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
private readonly CollectionRepository<ModuleAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly ICacheProvider cacheProvider;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public ModuleProvider(CollectionRepository<ModuleAdapter> repository,
|
||||
ICacheProvider cacheProvider,
|
||||
IRedisCacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings)
|
||||
{
|
||||
this.repository = repository;
|
||||
|
||||
@@ -3,11 +3,10 @@
|
||||
// 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.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;
|
||||
@@ -23,10 +22,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
private readonly CollectionRepository<PermissionAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly ICacheProvider cacheProvider;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public PermissionProvider(CollectionRepository<PermissionAdapter> repository,
|
||||
ICacheProvider cacheProvider,
|
||||
IRedisCacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings
|
||||
)
|
||||
{
|
||||
@@ -129,7 +128,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <param name="newStatus">The new status of the permission.</param>
|
||||
/// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
public async ValueTask<PermissionAdapter> ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(id);
|
||||
entity.Status = newStatus;
|
||||
|
||||
@@ -3,22 +3,15 @@
|
||||
// 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.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 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
|
||||
{
|
||||
@@ -28,19 +21,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public class RoleProvider : IRoleProvider
|
||||
{
|
||||
private readonly CollectionRepository<RoleAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly ICacheProvider cacheProvider;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public RoleProvider(CollectionRepository<RoleAdapter> repository,
|
||||
ICacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings
|
||||
)
|
||||
public RoleProvider(CollectionRepository<RoleAdapter> repository,
|
||||
IRedisCacheProvider 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.
|
||||
|
||||
@@ -4,19 +4,16 @@
|
||||
// </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.Redis;
|
||||
using Core.Blueprint.Redis.Helpers;
|
||||
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,19 +24,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public class UserProvider : IUserProvider
|
||||
{
|
||||
private readonly CollectionRepository<UserAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly ICacheProvider cacheProvider;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public UserProvider(CollectionRepository<UserAdapter> repository,
|
||||
ICacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings
|
||||
public UserProvider(CollectionRepository<UserAdapter> repository,
|
||||
IRedisCacheProvider 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.
|
||||
@@ -109,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);
|
||||
@@ -212,92 +209,6 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a company to the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user to whom the company will be added.</param>
|
||||
/// <param name="companyId">The identifier of the company to add.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedCompanies = user.Companies.Append(companyId).Distinct().ToArray();
|
||||
user.Companies = updatedCompanies;
|
||||
|
||||
await repository.ReplaceOneAsync(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a company from the user's list of companies.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user from whom the company will be removed.</param>
|
||||
/// <param name="companyId">The identifier of the company to remove.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedCompanies = user.Companies
|
||||
?.Where(c => c != companyId)
|
||||
.ToArray();
|
||||
|
||||
user.Companies = updatedCompanies;
|
||||
|
||||
await repository.ReplaceOneAsync(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a project to the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user to whom the project will be added.</param>
|
||||
/// <param name="projectId">The identifier of the project to add.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedProjects = user.Projects.Append(projectId).Distinct().ToArray();
|
||||
user.Projects = updatedProjects;
|
||||
|
||||
await repository.ReplaceOneAsync(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a project from the user's list of projects.
|
||||
/// </summary>
|
||||
/// <param name="userId">The identifier of the user from whom the project will be removed.</param>
|
||||
/// <param name="projectId">The identifier of the project to remove.</param>
|
||||
/// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns>
|
||||
public async ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedProjects = user.Projects
|
||||
?.Where(c => c != projectId)
|
||||
.ToArray();
|
||||
|
||||
user.Projects = updatedProjects;
|
||||
|
||||
await repository.ReplaceOneAsync(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the token adapter for a user.
|
||||
/// </summary>
|
||||
@@ -414,18 +325,6 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "",
|
||||
DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "",
|
||||
RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "",
|
||||
Companies = result.Contains("companies") && result["companies"].IsBsonArray
|
||||
? result["companies"].AsBsonArray
|
||||
.Where(c => c != null && !c.IsBsonNull)
|
||||
.Select(c => c.AsString)
|
||||
.ToArray()
|
||||
: Array.Empty<string>(),
|
||||
Projects = result.Contains("projects") && result["projects"].IsBsonArray
|
||||
? result["projects"].AsBsonArray
|
||||
.Where(p => p != null && !p.IsBsonNull)
|
||||
.Select(p => p.AsString)
|
||||
.ToArray()
|
||||
: Array.Empty<string>(),
|
||||
LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue,
|
||||
LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].ToUniversalTime() : DateTime.MinValue,
|
||||
CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue,
|
||||
|
||||
@@ -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.BuildingBlocks;
|
||||
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<ILogger<DashboardDALService>>(); //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<ICacheService>(provider =>
|
||||
new CacheService(redisConnectionString, provider.GetRequiredService<ILogger<CacheService>>()));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user