Fix some issues in the endpoints and use local mongodb
This commit is contained in:
@@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Graph;
|
||||
using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest;
|
||||
|
||||
namespace LSA.Core.Kerberos.API.Controllers
|
||||
namespace LSA.Core.Thalos.API.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all requests for module authentication.
|
||||
@@ -25,6 +25,7 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[ApiController]
|
||||
[AllowAnonymous]
|
||||
public class ModuleController(IModuleProvider service) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
@@ -38,8 +39,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("ModuleManagement.Read, RoleManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("ModuleManagement.Read, RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetAllModules(cancellationToken).ConfigureAwait(false);
|
||||
@@ -59,8 +60,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("ModuleManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("ModuleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken)
|
||||
{
|
||||
if (modules == null || !modules.Any())
|
||||
@@ -86,11 +87,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("ModuleManagement.Read")]
|
||||
public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("ModuleManagement.Read")]
|
||||
public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetModuleById(_id, cancellationToken).ConfigureAwait(false);
|
||||
var result = await service.GetModuleById(id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
@@ -110,8 +111,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal e|ror.</response>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("ModuleManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("ModuleManagement.Write")]
|
||||
public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.CreateModule(newModule, cancellationToken).ConfigureAwait(false);
|
||||
@@ -133,11 +134,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("ModuleManagement.Write")]
|
||||
public async Task<IActionResult> UpdateModuleAsync([FromRoute] string _id, ModuleAdapter entity, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("ModuleManagement.Write")]
|
||||
public async Task<IActionResult> UpdateModuleAsync([FromRoute] string id, ModuleAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_id != entity._Id?.ToString())
|
||||
if (id != entity._Id?.ToString())
|
||||
{
|
||||
return BadRequest("Module ID mismatch");
|
||||
}
|
||||
@@ -162,8 +163,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("ModuleManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("ModuleManagement.Write")]
|
||||
public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeModuleStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -15,7 +15,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Graph;
|
||||
using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest;
|
||||
|
||||
namespace LSA.Core.Kerberos.API.Controllers
|
||||
namespace LSA.Core.Thalos.API.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all requests for permission authentication.
|
||||
@@ -38,8 +38,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("PermissionManagement.Read, RoleManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("PermissionManagement.Read, RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetAllPermissions(cancellationToken).ConfigureAwait(false);
|
||||
@@ -59,13 +59,13 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("PermissionManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("PermissionManagement.Read")]
|
||||
public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken)
|
||||
{
|
||||
if (permissions == null || !permissions.Any())
|
||||
{
|
||||
return BadRequest("Module identifiers are required.");
|
||||
return BadRequest("Permissions identifiers are required.");
|
||||
}
|
||||
|
||||
var result = await service.GetAllPermissionsByList(permissions, cancellationToken).ConfigureAwait(false);
|
||||
@@ -85,11 +85,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("PermissionManagement.Read")]
|
||||
public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string _id, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("PermissionManagement.Read")]
|
||||
public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetPermissionById(_id, cancellationToken).ConfigureAwait(false);
|
||||
var result = await service.GetPermissionById(id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
@@ -109,8 +109,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal e|ror.</response>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("PermissionManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("PermissionManagement.Write")]
|
||||
public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.CreatePermission(newPermission, cancellationToken).ConfigureAwait(false);
|
||||
@@ -132,11 +132,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("PermissionManagement.Write")]
|
||||
public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string _id, PermissionAdapter entity, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("PermissionManagement.Write")]
|
||||
public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_id != entity._Id?.ToString())
|
||||
if (id != entity._Id?.ToString())
|
||||
{
|
||||
return BadRequest("Permission ID mismatch");
|
||||
}
|
||||
@@ -161,8 +161,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("PermissionManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("PermissionManagement.Write")]
|
||||
public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangePermissionStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using StatusEnum = Core.Blueprint.Mongo.StatusEnum;
|
||||
|
||||
namespace LSA.Core.Kerberos.API.Controllers
|
||||
namespace LSA.Core.Thalos.API.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all requests for role authentication.
|
||||
@@ -35,8 +35,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("RoleManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false);
|
||||
@@ -54,11 +54,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpGet]
|
||||
[Route(Routes.Id)]
|
||||
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string _id, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetRoleById(_id, cancellationToken).ConfigureAwait(false);
|
||||
var result = await service.GetRoleById(id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
@@ -78,8 +78,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false);
|
||||
@@ -99,11 +99,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpPut]
|
||||
[Route(Routes.Id)]
|
||||
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> UpdateRoleAsync([FromRoute] string _id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_id != entity._Id?.ToString())
|
||||
if (id != entity._Id?.ToString())
|
||||
{
|
||||
return BadRequest("Role ID mismatch");
|
||||
}
|
||||
@@ -126,8 +126,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpPatch]
|
||||
[Route(Routes.ChangeStatus)]
|
||||
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeRoleStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
@@ -146,8 +146,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPost(Routes.AddApplication)]
|
||||
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false);
|
||||
@@ -166,8 +166,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpDelete(Routes.RemoveApplication)]
|
||||
[ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("RoleManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("RoleManagement.Write")]
|
||||
public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -14,7 +14,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Graph;
|
||||
using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest;
|
||||
|
||||
namespace LSA.Core.Kerberos.API.Controllers
|
||||
namespace LSA.Core.Thalos.API.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles all requests for user authentication.
|
||||
@@ -35,8 +35,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Read")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Read")]
|
||||
public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false);
|
||||
@@ -54,11 +54,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpGet]
|
||||
[Route(Routes.Id)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Read")]
|
||||
public async Task<IActionResult> GetUserById([FromRoute] string _id, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Read")]
|
||||
public async Task<IActionResult> GetUserById([FromRoute] string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetUserById(_id, cancellationToken).ConfigureAwait(false);
|
||||
var result = await service.GetUserById(id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpGet]
|
||||
[Route(Routes.Email)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
//[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false);
|
||||
@@ -127,8 +127,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPost(Routes.Register)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false);
|
||||
@@ -148,11 +148,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpPut]
|
||||
[Route(Routes.Id)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> UpdateUserAsync([FromRoute] string _id, [FromBody] UserAdapter entity, CancellationToken cancellationToken)
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> UpdateUserAsync([FromRoute] string id, [FromBody] UserAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_id != entity._Id?.ToString())
|
||||
if (id != entity._Id?.ToString())
|
||||
{
|
||||
return BadRequest("User ID mismatch");
|
||||
}
|
||||
@@ -173,7 +173,7 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPatch(Routes.LogIn)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
//[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false);
|
||||
@@ -194,7 +194,7 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPatch(Routes.LogOut)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
//[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false);
|
||||
@@ -216,8 +216,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpPatch]
|
||||
[Route(Routes.ChangeStatus)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeUserStatus(id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
@@ -236,8 +236,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpPost]
|
||||
[Route(Routes.AddCompany)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[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);
|
||||
@@ -256,8 +256,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpDelete]
|
||||
[Route(Routes.RemoveCompany)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[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); ;
|
||||
@@ -276,8 +276,8 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpPost]
|
||||
[Route(Routes.AddProject)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[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);
|
||||
@@ -296,11 +296,11 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpDelete]
|
||||
[Route(Routes.RemoveProject)]
|
||||
[ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
[Permission("UserManagement.Write")]
|
||||
//[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
//[Permission("UserManagement.Write")]
|
||||
public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.RemoveCompanyFromUser(userId, projectId, cancellationToken).ConfigureAwait(false);
|
||||
var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ namespace LSA.Core.Kerberos.API.Controllers
|
||||
[HttpGet]
|
||||
[Route("{email}/GetTokenAdapter")]
|
||||
[ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)]
|
||||
[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
//[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")]
|
||||
public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken)
|
||||
{
|
||||
var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blueprint.Logging" Version="0.0.1" />
|
||||
<PackageReference Include="Blueprint.Logging" Version="0.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
71
Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
Normal file
71
Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Asp.Versioning.ApiExplorer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Any;
|
||||
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)
|
||||
{
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen();
|
||||
services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
|
||||
}
|
||||
|
||||
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,90 +1,80 @@
|
||||
using Core.Blueprint.DAL.Mongo.Configuration;
|
||||
using Core.Blueprint.Logging.Configuration;
|
||||
using Core.Thalos.Adapters.Extensions;
|
||||
using Core.Thalos.Adapters.Helpers;
|
||||
using Core.Thalos.DAL.API.Extensions;
|
||||
using Core.Thalos.Provider;
|
||||
using Microsoft.AspNetCore.RateLimiting;
|
||||
using Microsoft.AspNetCore.ResponseCompression;
|
||||
using System.IO.Compression;
|
||||
using Microsoft.AspNetCore.HttpLogging;
|
||||
using System.Reflection;
|
||||
using System.Threading.RateLimiting;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var authSettings = AuthHelper.GetAuthSettings(builder, "thalos_dal");
|
||||
|
||||
builder.Services.ConfigureAuthentication(builder.Configuration, authSettings);
|
||||
|
||||
builder.Configuration.AddUserSecrets(Assembly.GetExecutingAssembly()).AddEnvironmentVariables();
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Configuration
|
||||
.AddUserSecrets(Assembly.GetExecutingAssembly())
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
builder.Services.AddLogs(builder);
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", policyBuilder =>
|
||||
policyBuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
|
||||
});
|
||||
builder.Services.AddMvc().AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.WriteIndented = true;
|
||||
options.JsonSerializerOptions.MaxDepth = 20;
|
||||
options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals;
|
||||
});
|
||||
builder.Services.Configure<BrotliCompressionProviderOptions>(options =>
|
||||
{
|
||||
options.Level = CompressionLevel.Fastest;
|
||||
});
|
||||
builder.Services.Configure<GzipCompressionProviderOptions>(options =>
|
||||
{
|
||||
options.Level = CompressionLevel.SmallestSize;
|
||||
});
|
||||
builder.Services.AddResponseCompression(options =>
|
||||
{
|
||||
options.EnableForHttps = true;
|
||||
options.Providers.Add<BrotliCompressionProvider>();
|
||||
options.Providers.Add<GzipCompressionProvider>();
|
||||
});
|
||||
|
||||
builder.Services.AddRateLimiter(_ => _
|
||||
.AddFixedWindowLimiter("fixed", options =>
|
||||
{
|
||||
options.PermitLimit = 5;
|
||||
options.Window = TimeSpan.FromSeconds(10);
|
||||
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
|
||||
options.QueueLimit = 2;
|
||||
})
|
||||
.AddSlidingWindowLimiter("sliding", options =>
|
||||
{
|
||||
options.PermitLimit = 5;
|
||||
options.Window = TimeSpan.FromSeconds(10);
|
||||
options.SegmentsPerWindow = 5;
|
||||
options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst;
|
||||
options.QueueLimit = 2;
|
||||
}));
|
||||
|
||||
builder.Services.AddResponseCaching();
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwagger(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings);
|
||||
builder.Services.AddVersioning(builder.Configuration);
|
||||
builder.Services.AddLogging();
|
||||
builder.Services.AddResponseCompression();
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddLogs(builder);
|
||||
builder.Services.AddMongoLayer(builder.Configuration);
|
||||
builder.Services.AddDALLayerServices(builder.Configuration);
|
||||
|
||||
builder.Host.ConfigureServices((context, services) =>
|
||||
{
|
||||
|
||||
builder.Services.AddDALLayer(builder.Configuration);
|
||||
services.AddLogging();
|
||||
services.AddControllers();
|
||||
services.AddProblemDetails();
|
||||
services.AddCors(options
|
||||
=> options.AddDefaultPolicy(policyBuilder
|
||||
=> policyBuilder
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()));
|
||||
|
||||
builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options =>
|
||||
{
|
||||
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||
});
|
||||
|
||||
services
|
||||
.AddEndpointsApiExplorer()
|
||||
.AddVersioning()
|
||||
.AddSwagger();
|
||||
|
||||
services.AddHealthChecks();
|
||||
services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All);
|
||||
|
||||
builder.Services.AddOutputCache(options =>
|
||||
{
|
||||
options.AddBasePolicy(builder =>
|
||||
builder.Expire(TimeSpan.FromSeconds(10)));
|
||||
options.AddPolicy("Expire20", builder =>
|
||||
builder.Expire(TimeSpan.FromSeconds(20)));
|
||||
options.AddPolicy("Expire30", builder =>
|
||||
builder.Expire(TimeSpan.FromSeconds(30)));
|
||||
});
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseSwaggerUI(builder.Configuration, authSettings);
|
||||
app.ConfigureSwagger(builder.Configuration);
|
||||
app.UseLogging(builder.Configuration);
|
||||
app.UseHttpsRedirection();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
app.UseCors();
|
||||
app.ConfigureSwagger();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseResponseCompression();
|
||||
app.UseOutputCache();
|
||||
app.UseResponseCaching();
|
||||
app.UseLogging(builder.Configuration);
|
||||
app.MapHealthChecks("/health");
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
||||
@@ -26,7 +26,7 @@
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7031;http://localhost:5211",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Local"
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
|
||||
@@ -5,4 +5,18 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"MongoDbSettings": {
|
||||
"ConnectionString": "mongodb://localhost:27017",
|
||||
"Databasename": "Thalos",
|
||||
"Audience": "local-dev"
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"MongoDB": "mongodb://localhost:27017"
|
||||
},
|
||||
"MongoDb": {
|
||||
"DatabaseName": "Thalos",
|
||||
"LocalAudience": "local-dev"
|
||||
},
|
||||
"DetailedErrors": true
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
"AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT)
|
||||
"TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT)
|
||||
"Scope": "", // Scope for application permissions (STORED IN KEY VAULT)
|
||||
"ClientId": "" // Client ID for Kerberos application (STORED IN KEY VAULT)
|
||||
"ClientId": "" // Client ID for Thalos application (STORED IN KEY VAULT)
|
||||
},
|
||||
"MicrosoftGraph": {
|
||||
"Scopes": "", // Scopes for Microsoft Graph API access
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Thalos.Building.Blocks" Version="0.0.2" />
|
||||
<PackageReference Include="Thalos.Building.Blocks" Version="0.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blueprint.Mongo" Version="0.0.3" />
|
||||
<PackageReference Include="Blueprint.Mongo" Version="0.0.5" />
|
||||
<PackageReference Include="Blueprint.Redis" Version="0.0.1" />
|
||||
<PackageReference Include="BuildingBlocks.Library" Version="0.0.1" />
|
||||
<PackageReference Include="Mapster" Version="7.4.2-pre02" />
|
||||
|
||||
@@ -22,15 +22,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
private readonly CollectionRepository<ModuleAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
//private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public ModuleProvider(CollectionRepository<ModuleAdapter> repository,
|
||||
IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings)
|
||||
public ModuleProvider(CollectionRepository<ModuleAdapter> repository, IOptions<CacheSettings> cacheSettings)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.repository.CollectionInitialization();
|
||||
this.cacheSettings = cacheSettings.Value;
|
||||
this.cacheProvider = cacheProvider;
|
||||
//this.cacheProvider = cacheProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,13 +56,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id);
|
||||
var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(cacheKey);
|
||||
//var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(cacheKey);
|
||||
|
||||
if (cachedData is not null) { return cachedData; }
|
||||
//if (cachedData is not null) { return cachedData; }
|
||||
|
||||
var module = await repository.FindByIdAsync(_id);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, module);
|
||||
//await cacheProvider.SetAsync(cacheKey, module);
|
||||
|
||||
return module;
|
||||
}
|
||||
@@ -76,13 +75,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules");
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? [];
|
||||
//var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
//if (cachedData.Any()) return cachedData;
|
||||
|
||||
var modules = await repository.AsQueryable();
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, modules);
|
||||
//await cacheProvider.SetAsync(cacheKey, modules);
|
||||
|
||||
return modules;
|
||||
}
|
||||
@@ -97,9 +96,9 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules);
|
||||
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? [];
|
||||
//var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
//if (cachedData.Any()) return cachedData;
|
||||
|
||||
var builder = Builders<ModuleAdapter>.Filter;
|
||||
var filters = new List<FilterDefinition<ModuleAdapter>>();
|
||||
@@ -113,7 +112,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
|
||||
var modulesList = await repository.FilterByMongoFilterAsync(finalFilter);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, modulesList);
|
||||
//await cacheProvider.SetAsync(cacheKey, modulesList);
|
||||
|
||||
return modulesList;
|
||||
}
|
||||
|
||||
@@ -22,15 +22,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
private readonly CollectionRepository<PermissionAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
//private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public PermissionProvider(CollectionRepository<PermissionAdapter> repository,
|
||||
IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings)
|
||||
//IRedisCacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.repository.CollectionInitialization();
|
||||
this.cacheSettings = cacheSettings.Value;
|
||||
this.cacheProvider = cacheProvider;
|
||||
//this.cacheProvider = cacheProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,14 +57,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>0
|
||||
public async ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id);
|
||||
var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey);
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id);
|
||||
//var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey);
|
||||
|
||||
if (cachedData is not null) { return cachedData; }
|
||||
//if (cachedData is not null) { return cachedData; }
|
||||
|
||||
var permission = await repository.FindByIdAsync(_id);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, permission);
|
||||
//await cacheProvider.SetAsync(cacheKey, permission);
|
||||
|
||||
return permission;
|
||||
}
|
||||
@@ -75,14 +76,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions");
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions");
|
||||
//var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
//if (cachedData.Any()) return cachedData;
|
||||
|
||||
var permissions = await repository.AsQueryable();
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, permissions);
|
||||
//await cacheProvider.SetAsync(cacheKey, permissions);
|
||||
|
||||
return permissions;
|
||||
}
|
||||
@@ -95,11 +96,11 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions);
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions);
|
||||
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
|
||||
//var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
//if (cachedData.Any()) return cachedData;
|
||||
|
||||
var builder = Builders<PermissionAdapter>.Filter;
|
||||
var filters = new List<FilterDefinition<PermissionAdapter>>();
|
||||
@@ -113,7 +114,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
|
||||
var permissionsList = await repository.FilterByMongoFilterAsync(finalFilter);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, permissionsList);
|
||||
//await cacheProvider.SetAsync(cacheKey, permissionsList);
|
||||
|
||||
return permissionsList;
|
||||
}
|
||||
|
||||
@@ -28,15 +28,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
private readonly CollectionRepository<RoleAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
//private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public RoleProvider(CollectionRepository<RoleAdapter> repository,
|
||||
IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings)
|
||||
//IRedisCacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.repository.CollectionInitialization();
|
||||
this.cacheSettings = cacheSettings.Value;
|
||||
this.cacheProvider = cacheProvider;
|
||||
//this.cacheProvider = cacheProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,14 +63,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id);
|
||||
var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey);
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id);
|
||||
//var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey);
|
||||
|
||||
if (cachedData is not null) { return cachedData; }
|
||||
//if (cachedData is not null) { return cachedData; }
|
||||
|
||||
var role = await repository.FindByIdAsync(_id);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, role);
|
||||
//await cacheProvider.SetAsync(cacheKey, role);
|
||||
|
||||
return role;
|
||||
}
|
||||
@@ -81,14 +82,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles");
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? [];
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles");
|
||||
//var cachedData = await cacheProvider.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
//if (cachedData.Any()) return cachedData;
|
||||
|
||||
var roles = await repository.AsQueryable();
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, roles);
|
||||
//await cacheProvider.SetAsync(cacheKey, roles);
|
||||
|
||||
return roles;
|
||||
}
|
||||
@@ -133,7 +134,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken)
|
||||
{
|
||||
var role = await repository.FindOneAsync(
|
||||
u => u.Id == roleId &&
|
||||
u => u._Id == roleId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedApplications = role.Applications.Append(application).Distinct().ToArray();
|
||||
@@ -153,7 +154,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken)
|
||||
{
|
||||
var role = await repository.FindOneAsync(
|
||||
u => u.Id == roleId &&
|
||||
u => u._Id == roleId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedApplications = role.Applications
|
||||
|
||||
@@ -26,15 +26,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
private readonly CollectionRepository<UserAdapter> repository;
|
||||
private readonly CacheSettings cacheSettings;
|
||||
private readonly IRedisCacheProvider cacheProvider;
|
||||
//private readonly IRedisCacheProvider cacheProvider;
|
||||
|
||||
public UserProvider(CollectionRepository<UserAdapter> repository,
|
||||
IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings)
|
||||
//IRedisCacheProvider cacheProvider,
|
||||
IOptions<CacheSettings> cacheSettings)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.repository.CollectionInitialization();
|
||||
this.cacheSettings = cacheSettings.Value;
|
||||
this.cacheProvider = cacheProvider;
|
||||
//this.cacheProvider = cacheProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -60,14 +61,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id);
|
||||
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id);
|
||||
//var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
|
||||
|
||||
if (cachedData is not null) { return cachedData; }
|
||||
//if (cachedData is not null) { return cachedData; }
|
||||
|
||||
var user = await repository.FindByIdAsync(_id);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, user);
|
||||
//await cacheProvider.SetAsync(cacheKey, user);
|
||||
|
||||
return user;
|
||||
}
|
||||
@@ -79,14 +80,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers");
|
||||
var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? [];
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers");
|
||||
//var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? [];
|
||||
|
||||
if (cachedData.Any()) return cachedData;
|
||||
//if (cachedData.Any()) return cachedData;
|
||||
|
||||
var users = await repository.AsQueryable();
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, users);
|
||||
//await cacheProvider.SetAsync(cacheKey, users);
|
||||
|
||||
return users;
|
||||
}
|
||||
@@ -99,16 +100,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
|
||||
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
|
||||
//var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
|
||||
|
||||
if (cachedData is not null) { return cachedData; }
|
||||
//if (cachedData is not null) { return cachedData; }
|
||||
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u.Email == email &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, user);
|
||||
//await cacheProvider.SetAsync(cacheKey, user);
|
||||
|
||||
return user;
|
||||
}
|
||||
@@ -121,16 +122,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken)
|
||||
{
|
||||
var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
|
||||
var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
|
||||
//var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email);
|
||||
//var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey);
|
||||
|
||||
if (cachedData is not null) { return cachedData; }
|
||||
//if (cachedData is not null) { return cachedData; }
|
||||
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u.Email == email &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
await cacheProvider.SetAsync(cacheKey, user);
|
||||
//await cacheProvider.SetAsync(cacheKey, user);
|
||||
|
||||
return user;
|
||||
}
|
||||
@@ -213,7 +214,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u.Id == userId &&
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedCompanies = user.Companies.Append(companyId).Distinct().ToArray();
|
||||
@@ -233,7 +234,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u.Id == userId &&
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedCompanies = user.Companies
|
||||
@@ -256,11 +257,11 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u.Id == userId &&
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedProjects = user.Projects.Append(projectId).Distinct().ToArray();
|
||||
user.Companies = updatedProjects;
|
||||
user.Projects = updatedProjects;
|
||||
|
||||
await repository.ReplaceOneAsync(user);
|
||||
|
||||
@@ -276,14 +277,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
public async ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken)
|
||||
{
|
||||
var user = await repository.FindOneAsync(
|
||||
u => u.Id == userId &&
|
||||
u => u._Id == userId &&
|
||||
u.Status == Core.Blueprint.Mongo.StatusEnum.Active);
|
||||
|
||||
var updatedProjects = user.Projects
|
||||
?.Where(c => c != projectId)
|
||||
.ToArray();
|
||||
|
||||
user.Companies = updatedProjects;
|
||||
user.Projects = updatedProjects;
|
||||
|
||||
await repository.ReplaceOneAsync(user);
|
||||
|
||||
@@ -399,53 +400,106 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
User = new UserAdapter
|
||||
{
|
||||
Id = result["_id"]?.ToString() ?? "",
|
||||
Guid = result["guid"].AsString,
|
||||
Email = result["email"].AsString,
|
||||
Name = result["name"].AsString,
|
||||
MiddleName = result["middleName"].AsString,
|
||||
LastName = result["lastName"].AsString,
|
||||
DisplayName = result["displayName"].AsString,
|
||||
RoleId = result["roleId"]?.ToString() ?? "",
|
||||
Companies = result["companies"].AsBsonArray
|
||||
.Select(c => c.AsString)
|
||||
.ToArray(),
|
||||
Projects = result["projects"].AsBsonArray
|
||||
.Select(c => c.AsString)
|
||||
.ToArray(),
|
||||
LastLogIn = result["lastLogIn"].ToUniversalTime(),
|
||||
LastLogOut = result["lastLogOut"].ToUniversalTime(),
|
||||
CreatedAt = result["createdAt"].ToUniversalTime(),
|
||||
CreatedBy = result["createdBy"].AsString,
|
||||
UpdatedAt = result["updatedAt"].ToUniversalTime(),
|
||||
UpdatedBy = result["updatedBy"].AsString,
|
||||
Status = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString),
|
||||
Guid = result.Contains("guid") && !result["guid"].IsBsonNull ? result["guid"].AsString : "",
|
||||
Email = result.Contains("email") && !result["email"].IsBsonNull ? result["email"].AsString : "",
|
||||
Name = result.Contains("name") && !result["name"].IsBsonNull ? result["name"].AsString : "",
|
||||
MiddleName = result.Contains("middleName") && !result["middleName"].IsBsonNull ? result["middleName"].AsString : "",
|
||||
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,
|
||||
CreatedBy = result.Contains("createdBy") && !result["createdBy"].IsBsonNull ? result["createdBy"].AsString : "",
|
||||
UpdatedAt = result.Contains("updatedAt") && !result["updatedAt"].IsBsonNull ? result["updatedAt"].ToUniversalTime() : DateTime.MinValue,
|
||||
UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : "",
|
||||
Status = result.Contains("status") && !result["status"].IsBsonNull
|
||||
? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString)
|
||||
: Core.Blueprint.Mongo.StatusEnum.Inactive
|
||||
},
|
||||
Role = new RoleAdapter
|
||||
{
|
||||
Id = result["role"]["_id"]?.ToString() ?? "",
|
||||
Name = result["role"]["name"].AsString,
|
||||
Description = result["role"]["description"].AsString,
|
||||
Applications = result["role"]["applications"].AsBsonArray
|
||||
.Select(c => (ApplicationsEnum)c.AsInt32)
|
||||
.ToArray(),
|
||||
Modules = result["role"]["modules"].AsBsonArray
|
||||
.Select(c => c.ToString() ?? "")
|
||||
.ToArray(),
|
||||
Permissions = result["role"]["permissions"].AsBsonArray
|
||||
.Select(c => c.ToString() ?? "")
|
||||
.ToArray(),
|
||||
Status = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["role"]["status"].AsString),
|
||||
CreatedAt = result["role"]["createdAt"].ToUniversalTime(),
|
||||
UpdatedAt = result["role"]["updatedAt"].ToUniversalTime(),
|
||||
CreatedBy = result["role"]["createdBy"].AsString,
|
||||
UpdatedBy = result["role"]["updatedBy"].AsString
|
||||
Id = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("_id")
|
||||
? result["role"]["_id"]?.ToString() ?? ""
|
||||
: "",
|
||||
Name = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("name")
|
||||
? result["role"]["name"]?.AsString ?? ""
|
||||
: "",
|
||||
Description = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("description")
|
||||
? result["role"]["description"]?.AsString ?? ""
|
||||
: "",
|
||||
Applications = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("applications") &&
|
||||
result["role"]["applications"].IsBsonArray
|
||||
? result["role"]["applications"].AsBsonArray
|
||||
.Where(app => app != null && app.IsInt32)
|
||||
.Select(app => (ApplicationsEnum)app.AsInt32)
|
||||
.ToArray()
|
||||
: Array.Empty<ApplicationsEnum>(),
|
||||
Modules = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("modules") &&
|
||||
result["role"]["modules"].IsBsonArray
|
||||
? result["role"]["modules"].AsBsonArray
|
||||
.Where(m => m != null)
|
||||
.Select(m => m.ToString() ?? "")
|
||||
.ToArray()
|
||||
: Array.Empty<string>(),
|
||||
Permissions = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("permissions") &&
|
||||
result["role"]["permissions"].IsBsonArray
|
||||
? result["role"]["permissions"].AsBsonArray
|
||||
.Where(p => p != null)
|
||||
.Select(p => p.ToString() ?? "")
|
||||
.ToArray()
|
||||
: Array.Empty<string>(),
|
||||
Status = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("status") &&
|
||||
!result["role"]["status"].IsBsonNull
|
||||
? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["role"]["status"].AsString)
|
||||
: Core.Blueprint.Mongo.StatusEnum.Inactive,
|
||||
CreatedAt = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("createdAt") &&
|
||||
!result["role"]["createdAt"].IsBsonNull
|
||||
? result["role"]["createdAt"].ToUniversalTime()
|
||||
: DateTime.MinValue,
|
||||
UpdatedAt = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("updatedAt") &&
|
||||
!result["role"]["updatedAt"].IsBsonNull
|
||||
? result["role"]["updatedAt"].ToUniversalTime()
|
||||
: DateTime.MinValue,
|
||||
CreatedBy = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("createdBy") &&
|
||||
!result["role"]["createdBy"].IsBsonNull
|
||||
? result["role"]["createdBy"].AsString
|
||||
: "",
|
||||
UpdatedBy = result.Contains("role") && result["role"].IsBsonDocument &&
|
||||
result["role"].AsBsonDocument.Contains("updatedBy") &&
|
||||
!result["role"]["updatedBy"].IsBsonNull
|
||||
? result["role"]["updatedBy"].AsString
|
||||
: ""
|
||||
},
|
||||
Permissions = result["permissions"].AsBsonArray
|
||||
.Select(permission => BsonSerializer.Deserialize<PermissionAdapter>(permission.AsBsonDocument))
|
||||
.Where(permission => permission.Status == Core.Blueprint.Mongo.StatusEnum.Active)
|
||||
.ToList()
|
||||
Permissions = result.Contains("permissions") && result["permissions"].IsBsonArray
|
||||
? result["permissions"].AsBsonArray
|
||||
.Where(p => p != null && p.IsBsonDocument)
|
||||
.Select(p => BsonSerializer.Deserialize<PermissionAdapter>(p.AsBsonDocument))
|
||||
.Where(p => p.Status == Core.Blueprint.Mongo.StatusEnum.Active)
|
||||
.ToList()
|
||||
: new List<PermissionAdapter>()
|
||||
};
|
||||
|
||||
|
||||
return tokenAdapter;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Core.Thalos.Infraestructure.Caching.Contracts;
|
||||
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;
|
||||
@@ -14,60 +16,21 @@ namespace Core.Thalos.Provider
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddDALLayer(this IServiceCollection services, IConfiguration configuration)
|
||||
public static IServiceCollection AddDALLayerServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty;
|
||||
//Mongo
|
||||
services.AddScoped<IModuleProvider, ModuleProvider>();
|
||||
services.AddScoped<CollectionRepository<ModuleAdapter>>();
|
||||
|
||||
var connectionString = configuration.GetSection("ConnectionStrings:MongoDB").Value ?? string.Empty;
|
||||
var databaseName = configuration.GetSection("MongoDB:DatabaseName").Value ?? string.Empty;
|
||||
var audience = (environment == "Local")
|
||||
? configuration.GetSection("MongoDB:LocalAudience").Value
|
||||
: configuration.GetSection("MongoDB:Audience").Value;
|
||||
services.AddScoped<IPermissionProvider, PermissionProvider>();
|
||||
services.AddScoped<CollectionRepository<PermissionAdapter>>();
|
||||
|
||||
if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(databaseName) || string.IsNullOrEmpty(audience))
|
||||
{
|
||||
throw new InvalidOperationException("Mongo connection is not configured correctly.");
|
||||
}
|
||||
|
||||
services.Configure<MongoConnSettings>(options =>
|
||||
{
|
||||
options.ConnectionString = connectionString;
|
||||
options.Databasename = databaseName;
|
||||
options.Audience = audience ?? string.Empty;
|
||||
});
|
||||
|
||||
services.AddSingleton<IMongoClient>(serviceProvider =>
|
||||
{
|
||||
var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value;
|
||||
var mongoClientSettings = MongoClientSettings.FromConnectionString(settings.ConnectionString);
|
||||
mongoClientSettings.Credential = MongoCredential.CreateOidcCredential(new HeathOidcCallback(settings.Audience));
|
||||
return new MongoClient(mongoClientSettings);
|
||||
});
|
||||
|
||||
services.AddSingleton<IMongoDatabase>(serviceProvider =>
|
||||
{
|
||||
var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value;
|
||||
var client = serviceProvider.GetRequiredService<IMongoClient>();
|
||||
return client.GetDatabase(settings.Databasename);
|
||||
});
|
||||
|
||||
services.AddDALConfigurationLayer();
|
||||
services.AddLogs();
|
||||
services.AddRedisCacheService(configuration);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
private static IServiceCollection AddDALConfigurationLayer(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpContextAccessor();
|
||||
services.AddScoped<IRoleProvider, RoleProvider>();
|
||||
services.AddScoped<CollectionRepository<RoleAdapter>>();
|
||||
|
||||
services.AddScoped<IUserProvider, UserProvider>();
|
||||
services.AddScoped<IRoleProvider, RoleProvider>();
|
||||
services.AddScoped<IPermissionProvider, PermissionProvider>();
|
||||
services.AddScoped<IPermissionProvider, PermissionProvider>();
|
||||
services.AddScoped<IModuleProvider, ModuleProvider>();
|
||||
services.AddScoped<CollectionRepository<UserAdapter>>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user