Compare commits
1 Commits
32131d032b
...
feature/ad
| Author | SHA1 | Date | |
|---|---|---|---|
| a2a2b6ef8d |
@@ -66,7 +66,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
var result = await service.GetModuleById(_id, cancellationToken);
|
||||
|
||||
if (result == null)
|
||||
return NotFound("Module not found");
|
||||
return NotFound("Entity not found");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@@ -112,10 +112,6 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
public async Task<IActionResult> ChangeModuleStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeModuleStatus(_id, newStatus, cancellationToken);
|
||||
|
||||
if (result == null)
|
||||
return NotFound("Module not found");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@@ -137,7 +133,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
{
|
||||
var result = await service.DeleteModule(_id, cancellationToken);
|
||||
if (result == null)
|
||||
return NotFound("Module not found");
|
||||
return NotFound("Entity not found");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ 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;
|
||||
|
||||
@@ -90,7 +91,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound("Permission not found");
|
||||
return NotFound("Entity not found");
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
@@ -161,10 +162,6 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
public async Task<IActionResult> ChangePermissionStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangePermissionStatus(_id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
return NotFound("Permission not found");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound("Role not found");
|
||||
return NotFound("Entity not found");
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
@@ -126,10 +126,6 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
public async Task<IActionResult> ChangeRoleStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeRoleStatus(_id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
return NotFound("Role not found");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
using Asp.Versioning;
|
||||
using Core.Thalos.BuildingBlocks;
|
||||
using Core.Thalos.Provider.Contracts;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using StatusEnum = Core.Blueprint.Mongo.StatusEnum;
|
||||
using TenantRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.TenantRequest;
|
||||
@@ -22,7 +21,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[ApiController]
|
||||
[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
// [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)]
|
||||
public class TenantController(ITenantProvider service) : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
@@ -36,7 +35,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(IEnumerable<TenantAdapter>), StatusCodes.Status200OK)]
|
||||
[Permission("TenantManagement.Read, RoleManagement.Read")]
|
||||
// [Permission("TenantManagement.Read, RoleManagement.Read")]
|
||||
public async Task<IActionResult> GetAllTenantsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetAllTenants(cancellationToken).ConfigureAwait(false);
|
||||
@@ -57,14 +56,14 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)]
|
||||
[Permission("TenantManagement.Read")]
|
||||
// [Permission("TenantManagement.Read")]
|
||||
public async Task<IActionResult> GetTenantByIdAsync([FromRoute] string _id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetTenantById(_id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
return NotFound("Tenant not found");
|
||||
return NotFound("Entity not found");
|
||||
}
|
||||
|
||||
return Ok(result);
|
||||
@@ -81,7 +80,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
/// <response code="500">The service internal error.</response>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status201Created)]
|
||||
[Permission("TenantManagement.Write")]
|
||||
// [Permission("TenantManagement.Write")]
|
||||
public async Task<IActionResult> CreateTenantAsync([FromBody] TenantRequest newTenant, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.CreateTenant(newTenant, cancellationToken).ConfigureAwait(false);
|
||||
@@ -104,7 +103,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)]
|
||||
[Permission("TenantManagement.Write")]
|
||||
// [Permission("TenantManagement.Write")]
|
||||
public async Task<IActionResult> UpdateTenantAsync([FromRoute] string _id, [FromBody] TenantAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_id != entity._Id)
|
||||
@@ -113,9 +112,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
}
|
||||
|
||||
var result = await service.UpdateTenant(entity, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result is not null) return Ok(result);
|
||||
else return NotFound("Tenant not found");
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -132,14 +129,10 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
[Consumes(MimeTypes.ApplicationJson)]
|
||||
[Produces(MimeTypes.ApplicationJson)]
|
||||
[ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)]
|
||||
[Permission("TenantManagement.Write")]
|
||||
// [Permission("TenantManagement.Write")]
|
||||
public async Task<IActionResult> ChangeTenantStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeTenantStatus(_id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
return NotFound("Tenant not found");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@@ -155,7 +148,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
[HttpDelete]
|
||||
[Route(Routes.Id)]
|
||||
[ProducesResponseType(typeof(TenantAdapter), StatusCodes.Status200OK)]
|
||||
[Permission("TenantManagement.Write")]
|
||||
// [Permission("TenantManagement.Write")]
|
||||
public async Task<IActionResult> DeleteTenantAsync([FromRoute] string _id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.DeleteTenant(_id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
@@ -9,6 +9,7 @@ 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;
|
||||
|
||||
@@ -53,7 +54,7 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
public async Task<IActionResult> GetUserById([FromRoute] string _id, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.GetUserById(_id, cancellationToken).ConfigureAwait(false);
|
||||
return result == null ? NotFound("User not found") : Ok(result);
|
||||
return result == null ? NotFound("Entity not found") : Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -170,10 +171,6 @@ namespace LSA.Core.Thalos.API.Controllers
|
||||
public async Task<IActionResult> ChangeUserStatus([FromRoute] string _id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = await service.ChangeUserStatus(_id, newStatus, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (result == null)
|
||||
return NotFound("User not found");
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Core.Blueprint.KeyVault" Version="1.0.3" />
|
||||
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.1.2" />
|
||||
<PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<ModuleAdapter?> ChangeModuleStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<ModuleAdapter> ChangeModuleStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a Module by its identifier.
|
||||
@@ -72,7 +72,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<ModuleAdapter?> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken);
|
||||
ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a Module by its identifier.
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<PermissionAdapter?> ChangePermissionStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<PermissionAdapter> ChangePermissionStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a Permission.
|
||||
@@ -72,7 +72,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<PermissionAdapter?> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken);
|
||||
ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a Permission by its identifier.
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<RoleAdapter?> ChangeRoleStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<RoleAdapter> ChangeRoleStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a Role.
|
||||
@@ -62,7 +62,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<RoleAdapter?> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken);
|
||||
ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an application to the Role's list of applications.
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<TenantAdapter?> ChangeTenantStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<TenantAdapter> ChangeTenantStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a Tenant.
|
||||
@@ -62,7 +62,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<TenantAdapter?> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken);
|
||||
ValueTask<TenantAdapter> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a Tenant by its identifier.
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<UserAdapter?> ChangeUserStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
ValueTask<UserAdapter> ChangeUserStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a User.
|
||||
@@ -82,7 +82,7 @@ namespace Core.Thalos.Provider.Contracts
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
ValueTask<UserAdapter?> UpdateUser(UserAdapter entity, CancellationToken cancellationToken);
|
||||
ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Logs in the User.
|
||||
|
||||
@@ -131,17 +131,12 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<ModuleAdapter?> ChangeModuleStatus(string _id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
public async ValueTask<ModuleAdapter> ChangeModuleStatus(string _id, StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(_id);
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Status = newStatus;
|
||||
|
||||
return repository.ReplaceOneAsync(entity).Result;
|
||||
}
|
||||
else return null;
|
||||
entity.Status = newStatus;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -152,10 +147,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<ModuleAdapter?> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken)
|
||||
public async ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
var updatedEntity = await repository.ReplaceOneAsync(entity);
|
||||
return updatedEntity;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -130,17 +130,12 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<PermissionAdapter?> ChangePermissionStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
public async ValueTask<PermissionAdapter> ChangePermissionStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(_id);
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Status = newStatus;
|
||||
|
||||
return repository.ReplaceOneAsync(entity).Result;
|
||||
}
|
||||
else return null;
|
||||
entity.Status = newStatus;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -151,10 +146,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<PermissionAdapter?> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken)
|
||||
public async ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
var updatedEntity = await repository.ReplaceOneAsync(entity);
|
||||
return updatedEntity;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -100,17 +100,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<RoleAdapter?> ChangeRoleStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
public async ValueTask<RoleAdapter> ChangeRoleStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(_id);
|
||||
entity.Status = newStatus;
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Status = newStatus;
|
||||
|
||||
return repository.ReplaceOneAsync(entity).Result;
|
||||
}
|
||||
else return null;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,10 +117,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<RoleAdapter?> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken)
|
||||
public async ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
var updatedEntity = await repository.ReplaceOneAsync(entity);
|
||||
return updatedEntity;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -99,17 +99,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<TenantAdapter?> ChangeTenantStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
public async ValueTask<TenantAdapter> ChangeTenantStatus(string _id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(_id);
|
||||
entity.Status = newStatus;
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Status = newStatus;
|
||||
|
||||
return repository.ReplaceOneAsync(entity).Result;
|
||||
}
|
||||
else return null;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,10 +116,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <returns>
|
||||
/// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service.
|
||||
/// </returns>
|
||||
public async ValueTask<TenantAdapter?> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken)
|
||||
public async ValueTask<TenantAdapter> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
var updatedEntity = await repository.ReplaceOneAsync(entity);
|
||||
return updatedEntity;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -146,17 +146,14 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <param name="newStatus">The new status of the user.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<UserAdapter?> ChangeUserStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
public async ValueTask<UserAdapter> ChangeUserStatus(string _id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await repository.FindByIdAsync(_id);
|
||||
entity.Status = newStatus;
|
||||
|
||||
if (entity is not null)
|
||||
{
|
||||
entity.Status = newStatus;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
|
||||
return repository.ReplaceOneAsync(entity).Result;
|
||||
}
|
||||
else return null;
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -166,10 +163,11 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
/// <param name="_id">The User mongo identifier.</param>
|
||||
/// <returns>A <see cref="{Task{UserAdapter}}"/> representing
|
||||
/// the asynchronous execution of the service.</returns>
|
||||
public async ValueTask<UserAdapter?> UpdateUser(UserAdapter entity, CancellationToken cancellationToken)
|
||||
public async ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken)
|
||||
{
|
||||
var updatedEntity = await repository.ReplaceOneAsync(entity);
|
||||
return updatedEntity;
|
||||
await repository.ReplaceOneAsync(entity);
|
||||
|
||||
return entity;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -243,6 +241,16 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
new BsonDocument("$unwind", "$role"),
|
||||
new BsonDocument("$match", new BsonDocument("role.status", Core.Blueprint.Mongo.StatusEnum.Active.ToString())),
|
||||
|
||||
// Tenant lookup
|
||||
new BsonDocument("$lookup", new BsonDocument
|
||||
{
|
||||
{ "from", "Tenants" },
|
||||
{ "localField", "tenantId" },
|
||||
{ "foreignField", "_id" },
|
||||
{ "as", "tenant" }
|
||||
}),
|
||||
new BsonDocument("$unwind", "$tenant"),
|
||||
|
||||
new BsonDocument("$addFields", new BsonDocument
|
||||
{
|
||||
{ "role.permissions", new BsonDocument("$map", new BsonDocument
|
||||
@@ -305,6 +313,25 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{ "role.updatedAt", 1 },
|
||||
{ "role.createdBy", 1 },
|
||||
{ "role.updatedBy", 1 },
|
||||
{ "tenant._id", 1 },
|
||||
{ "tenant.name", 1 },
|
||||
{ "tenant.taxIdentifier", 1 },
|
||||
{ "tenant.addressLine1", 1 },
|
||||
{ "tenant.addressLine2", 1 },
|
||||
{ "tenant.city", 1 },
|
||||
{ "tenant.state", 1 },
|
||||
{ "tenant.country", 1 },
|
||||
{ "tenant.postalCode", 1 },
|
||||
{ "tenant.contactEmail", 1 },
|
||||
{ "tenant.contactPhone", 1 },
|
||||
{ "tenant.website", 1 },
|
||||
{ "tenant.connectionString", 1 },
|
||||
{ "tenant.isolated", 1 },
|
||||
{ "tenant.status", 1 },
|
||||
{ "tenant.createdAt", 1 },
|
||||
{ "tenant.updatedAt", 1 },
|
||||
{ "tenant.createdBy", 1 },
|
||||
{ "tenant.updatedBy", 1 },
|
||||
{ "permissions", 1 },
|
||||
{ "modules", 1 }
|
||||
})
|
||||
@@ -318,8 +345,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
{
|
||||
User = new UserAdapter
|
||||
{
|
||||
Id = result["_id"]?.ToString() ?? "",
|
||||
Guid = result.Contains("guid") && !result["guid"].IsBsonNull ? result["guid"].AsString : string.Empty,
|
||||
_Id = result["_id"]?.ToString() ?? "",
|
||||
Email = result.Contains("email") && !result["email"].IsBsonNull ? result["email"].AsString : string.Empty,
|
||||
Name = result.Contains("name") && !result["name"].IsBsonNull ? result["name"].AsString : string.Empty,
|
||||
MiddleName = result.Contains("middleName") && !result["middleName"].IsBsonNull ? result["middleName"].AsString : string.Empty,
|
||||
@@ -397,13 +423,82 @@ namespace Core.Thalos.Provider.Providers.Onboarding
|
||||
? result["role"]["updatedBy"].AsString
|
||||
: string.Empty
|
||||
},
|
||||
Tenant = result.Contains("tenant") && result["tenant"].IsBsonDocument
|
||||
? new TenantAdapter
|
||||
{
|
||||
Id = result.Contains("tenant") && result["tenant"].IsBsonDocument && result["tenant"].AsBsonDocument.Contains("_id")
|
||||
? result["tenant"]["_id"]?.ToString() ?? ""
|
||||
: string.Empty,
|
||||
Name = result["tenant"].AsBsonDocument.Contains("name") && !result["tenant"]["name"].IsBsonNull
|
||||
? result["tenant"]["name"].AsString
|
||||
: string.Empty,
|
||||
TaxIdentifier = result["tenant"].AsBsonDocument.Contains("taxIdentifier") && !result["tenant"]["taxIdentifier"].IsBsonNull
|
||||
? result["tenant"]["taxIdentifier"].AsString
|
||||
: string.Empty,
|
||||
AddressLine1 = result["tenant"].AsBsonDocument.Contains("addressLine1") && !result["tenant"]["addressLine1"].IsBsonNull
|
||||
? result["tenant"]["addressLine1"].AsString
|
||||
: string.Empty,
|
||||
AddressLine2 = result["tenant"].AsBsonDocument.Contains("addressLine2") && !result["tenant"]["addressLine2"].IsBsonNull
|
||||
? result["tenant"]["addressLine2"].AsString
|
||||
: null,
|
||||
City = result["tenant"].AsBsonDocument.Contains("city") && !result["tenant"]["city"].IsBsonNull
|
||||
? result["tenant"]["city"].AsString
|
||||
: string.Empty,
|
||||
State = result["tenant"].AsBsonDocument.Contains("state") && !result["tenant"]["state"].IsBsonNull
|
||||
? result["tenant"]["state"].AsString
|
||||
: string.Empty,
|
||||
Country = result["tenant"].AsBsonDocument.Contains("country") && !result["tenant"]["country"].IsBsonNull
|
||||
? result["tenant"]["country"].AsString
|
||||
: string.Empty,
|
||||
PostalCode = result["tenant"].AsBsonDocument.Contains("postalCode") && !result["tenant"]["postalCode"].IsBsonNull
|
||||
? result["tenant"]["postalCode"].AsString
|
||||
: string.Empty,
|
||||
ContactEmail = result["tenant"].AsBsonDocument.Contains("contactEmail") && !result["tenant"]["contactEmail"].IsBsonNull
|
||||
? result["tenant"]["contactEmail"].AsString
|
||||
: string.Empty,
|
||||
ContactPhone = result["tenant"].AsBsonDocument.Contains("contactPhone") && !result["tenant"]["contactPhone"].IsBsonNull
|
||||
? result["tenant"]["contactPhone"].AsString
|
||||
: string.Empty,
|
||||
Website = result["tenant"].AsBsonDocument.Contains("website") && !result["tenant"]["website"].IsBsonNull
|
||||
? result["tenant"]["website"].AsString
|
||||
: null,
|
||||
ConnectionString = result["tenant"].AsBsonDocument.Contains("connectionString") && !result["tenant"]["connectionString"].IsBsonNull
|
||||
? result["tenant"]["connectionString"].AsString
|
||||
: null,
|
||||
Isolated = result["tenant"].AsBsonDocument.Contains("isolated") && !result["tenant"]["isolated"].IsBsonNull
|
||||
? result["tenant"]["isolated"].ToBoolean()
|
||||
: false,
|
||||
CreatedAt = result["tenant"].AsBsonDocument.Contains("createdAt") && !result["tenant"]["createdAt"].IsBsonNull
|
||||
? result["tenant"]["createdAt"].ToUniversalTime()
|
||||
: DateTime.MinValue,
|
||||
UpdatedAt = result["tenant"].AsBsonDocument.Contains("updatedAt") && !result["tenant"]["updatedAt"].IsBsonNull
|
||||
? result["tenant"]["updatedAt"].ToUniversalTime()
|
||||
: DateTime.MinValue,
|
||||
CreatedBy = result["tenant"].AsBsonDocument.Contains("createdBy") && !result["tenant"]["createdBy"].IsBsonNull
|
||||
? result["tenant"]["createdBy"].AsString
|
||||
: string.Empty,
|
||||
UpdatedBy = result["tenant"].AsBsonDocument.Contains("updatedBy") && !result["tenant"]["updatedBy"].IsBsonNull
|
||||
? result["tenant"]["updatedBy"].AsString
|
||||
: string.Empty,
|
||||
Status = result["tenant"].AsBsonDocument.Contains("status") && !result["tenant"]["status"].IsBsonNull
|
||||
? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["tenant"]["status"].AsString)
|
||||
: Core.Blueprint.Mongo.StatusEnum.Active
|
||||
}
|
||||
: null,
|
||||
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>()
|
||||
: new List<PermissionAdapter>(),
|
||||
Modules = result.Contains("modules") && result["modules"].IsBsonArray
|
||||
? result["modules"].AsBsonArray
|
||||
.Where(p => p != null && p.IsBsonDocument)
|
||||
.Select(p => BsonSerializer.Deserialize<ModuleAdapter>(p.AsBsonDocument))
|
||||
.Where(p => p.Status == Core.Blueprint.Mongo.StatusEnum.Active)
|
||||
.ToList()
|
||||
: new List<ModuleAdapter>()
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user