Add tenant services
This commit is contained in:
		| @@ -3,61 +3,85 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interface for Module-related service operations. | ||||
|     /// </summary> | ||||
|     public interface IModuleProvider | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Creates a new Module. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Module to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="newModule">The Module to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an Module by identifier. | ||||
|         /// Gets a Module by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The Module identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="_id">The Module Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the roles. | ||||
|         /// Gets all Modules. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the permissions by permissions identifier list. | ||||
|         /// Gets all Modules by a list of identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="permissions">The list of permissions identifiers.</param> | ||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="modules">The list of Module identifiers.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the permission. | ||||
|         /// Changes the status of a Module. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The permission identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the permission.</param> | ||||
|         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         ValueTask<ModuleAdapter> ChangeModuleStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||
|         /// <param name="_id">The Module Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Module.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Module by id. | ||||
|         /// Updates a Module by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Module to be updated.</param> | ||||
|         /// <param name="id">The Module identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Module by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Module Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<ModuleAdapter?> DeleteModule(string _id, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,61 +3,85 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interface for Permission-related service operations. | ||||
|     /// </summary> | ||||
|     public interface IPermissionProvider | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Creates a new Permission. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Permission to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="newPermission">The Permission to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an Permission by identifier. | ||||
|         /// Gets a Permission by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The Permission identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="_id">The Permission Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the roles. | ||||
|         /// Gets all Permissions. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the permissions by permissions identifier list. | ||||
|         /// Gets all Permissions by a list of identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="permissions">The list of permissions identifiers.</param> | ||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="permissions">The list of Permission identifiers.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the permission. | ||||
|         /// Changes the status of a Permission. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The permission identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the permission.</param> | ||||
|         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         ValueTask<PermissionAdapter> ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||
|         /// <param name="_id">The Permission Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Permission.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Permission by id. | ||||
|         /// Updates a Permission. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Permission to be updated.</param> | ||||
|         /// <param name="id">The Permission identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Permission by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Permission Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<PermissionAdapter?> DeletePermission(string _id, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,69 +3,97 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interface for Role-related service operations. | ||||
|     /// </summary> | ||||
|     public interface IRoleProvider | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Creates a new Role. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Role to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="newRole">The Role to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an Role by identifier. | ||||
|         /// Gets a Role by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The Role identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="_id">The Role Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the roles. | ||||
|         /// Gets all Roles. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{RoleAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the role. | ||||
|         /// Changes the status of a Role. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The role identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the role.</param> | ||||
|         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         ValueTask<RoleAdapter> ChangeRoleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||
|         /// <param name="_id">The Role Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Role.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Role by id. | ||||
|         /// Updates a Role. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Role to be updated.</param> | ||||
|         /// <param name="id">The Role identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds an application to the role's list of applications. | ||||
|         /// Adds an application to the Role's list of applications. | ||||
|         /// </summary> | ||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> | ||||
|         /// <param name="roleId">The identifier of the Role to which the application will be added.</param> | ||||
|         /// <param name="application">The application enum value to add.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation with the updated Role. | ||||
|         /// </returns> | ||||
|         ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes an application from the role's list of applications. | ||||
|         /// Removes an application from the Role's list of applications. | ||||
|         /// </summary> | ||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> | ||||
|         /// <param name="roleId">The identifier of the Role from which the application will be removed.</param> | ||||
|         /// <param name="application">The application enum value to remove.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation with the updated Role. | ||||
|         /// </returns> | ||||
|         ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Role by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Role Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<RoleAdapter?> DeleteRole(string _id, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										77
									
								
								Core.Thalos.Provider/Contracts/ITenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								Core.Thalos.Provider/Contracts/ITenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="ITenantService.cs"> | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interface for Tenant-related service operations. | ||||
|     /// </summary> | ||||
|     public interface ITenantProvider | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Creates a new Tenant. | ||||
|         /// </summary> | ||||
|         /// <param name="newTenant">The Tenant to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<TenantAdapter> CreateTenant(TenantRequest newTenant, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets a Tenant by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<TenantAdapter> GetTenantById(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all Tenants. | ||||
|         /// </summary> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{TenantAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<IEnumerable<TenantAdapter>> GetAllTenants(CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of a Tenant. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Tenant.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Tenant. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Tenant to be updated.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<TenantAdapter> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Tenant by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<TenantAdapter?> DeleteTenant(string _id, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
| @@ -3,100 +3,125 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Interface for User-related service operations. | ||||
|     /// </summary> | ||||
|     public interface IUserProvider | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Creates a new User. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The User to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="newUser">The User to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserAdapter> CreateUser(UserRequest newUser, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an User by identifier. | ||||
|         /// Gets a User by Mongo identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="_id">The User Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken); | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the users. | ||||
|         /// Gets all Users. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{UserAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an User by email. | ||||
|         /// Gets a User by email. | ||||
|         /// </summary> | ||||
|         /// <param name="email">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken); | ||||
|         /// <param name="email">The User's email.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserAdapter> GetUserByEmail(string email, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Validates if a users exists by email. | ||||
|         /// Validates if a User exists by email. | ||||
|         /// </summary> | ||||
|         /// <param name="eamil">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken); | ||||
|         /// <param name="email">The User's email.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserExistenceAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserExistenceAdapter> ValidateUserExistence(string email, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the user. | ||||
|         /// Changes the status of a User. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The user identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the user.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         ValueTask<UserAdapter> ChangeUserStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||
|         /// <param name="_id">The User Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the User.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a User by id. | ||||
|         /// Updates a User. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The User to be updated.</param> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
|         /// Logs in the User. | ||||
|         /// </summary> | ||||
|         /// <param name="email">The User's email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs out the user's session. | ||||
|         /// Logs out the User's session. | ||||
|         /// </summary> | ||||
|         /// <param name="email">The User's email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the token adapter for a user. | ||||
|         /// Gets the TokenAdapter for a User. | ||||
|         /// </summary> | ||||
|         /// <param name="email">The user's email.</param> | ||||
|         /// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns> | ||||
|         /// <param name="email">The User's email.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TokenAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken); | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Delete an User by identifier. | ||||
|         /// Deletes a User by Mongo identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         ValueTask<UserAdapter> DeleteUser(string _id, CancellationToken cancellationToken); | ||||
|         /// <param name="_id">The User Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{UserAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         ValueTask<UserAdapter?> DeleteUser(string _id, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Blueprint.Redis; | ||||
| using Core.Blueprint.Redis.Helpers; | ||||
| @@ -10,8 +11,8 @@ using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Mapster; | ||||
| using Microsoft.Extensions.Options; | ||||
| using MongoDB.Driver; | ||||
| using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| { | ||||
| @@ -21,59 +22,63 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|     public class ModuleProvider : IModuleProvider | ||||
|     { | ||||
|         private readonly CollectionRepository<ModuleAdapter> repository; | ||||
|         private readonly CacheSettings cacheSettings; | ||||
|         private readonly ICacheSettings cacheSettings; | ||||
|         private readonly IRedisCacheProvider cacheProvider; | ||||
|  | ||||
|         public ModuleProvider(CollectionRepository<ModuleAdapter> repository, | ||||
|         public ModuleProvider( | ||||
|             CollectionRepository<ModuleAdapter> repository, | ||||
|             IRedisCacheProvider cacheProvider, | ||||
|             IOptions<CacheSettings> cacheSettings) | ||||
|             ICacheSettings cacheSettings) | ||||
|         { | ||||
|             this.repository = repository; | ||||
|             this.repository.CollectionInitialization(); | ||||
|             this.cacheSettings = cacheSettings.Value; | ||||
|             this.cacheProvider = cacheProvider; | ||||
|             this.cacheSettings = cacheSettings; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new Module. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Module to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="newModule">The Module to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var moduleCollection = newModule.Adapt<ModuleAdapter>(); | ||||
|  | ||||
|             await repository.InsertOneAsync(moduleCollection); | ||||
|  | ||||
|             return moduleCollection; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an Module by identifier. | ||||
|         /// Gets a Module by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The Module identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns>0 | ||||
|         /// <param name="_id">The Module Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id); | ||||
|             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, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return module; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the modules. | ||||
|         /// Gets all the Modules. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules"); | ||||
| @@ -82,22 +87,22 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|             if (cachedData.Any()) return cachedData; | ||||
|  | ||||
|             var modules = await repository.AsQueryable(); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, modules); | ||||
|  | ||||
|             return modules; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the modules by modules identifier list. | ||||
|         /// Gets all the Modules by a list of identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="modules">The list of modules identifiers.</param> | ||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="modules">The list of Module identifiers.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{ModuleAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules); | ||||
|  | ||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; | ||||
|  | ||||
|             if (cachedData.Any()) return cachedData; | ||||
| @@ -105,49 +110,61 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|             var builder = Builders<ModuleAdapter>.Filter; | ||||
|             var filters = new List<FilterDefinition<ModuleAdapter>>(); | ||||
|  | ||||
|             if (modules != null || !modules.Any()) | ||||
|             if (modules is { Length: > 0 }) | ||||
|             { | ||||
|                 filters.Add(builder.In(x => x._Id, modules)); | ||||
|             } | ||||
|  | ||||
|             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||
|  | ||||
|             var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, modulesList); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, modulesList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|             return modulesList; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the module. | ||||
|         /// Changes the status of the Module. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The module identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the module.</param> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async ValueTask<ModuleAdapter> ChangeModuleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         /// <param name="_id">The Module Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Module.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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) | ||||
|         { | ||||
|             var entity = await repository.FindByIdAsync(id); | ||||
|             var entity = await repository.FindByIdAsync(_id); | ||||
|             entity.Status = newStatus; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Module by id. | ||||
|         /// Updates a Module. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Module to be updated.</param> | ||||
|         /// <param name="id">The Module identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Module by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Module Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{ModuleAdapter}"/> representing the asynchronous deletion result. | ||||
|         /// The deleted Module entity if found; otherwise, null. | ||||
|         /// </returns> | ||||
|         public async ValueTask<ModuleAdapter?> DeleteModule(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var entity = await this.repository.DeleteOneAsync(doc => doc._Id == _id); | ||||
|             return entity; | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Blueprint.Redis; | ||||
| using Core.Blueprint.Redis.Helpers; | ||||
| @@ -10,7 +11,6 @@ using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Mapster; | ||||
| using Microsoft.Extensions.Options; | ||||
| using MongoDB.Driver; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| @@ -21,84 +21,87 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|     public class PermissionProvider : IPermissionProvider | ||||
|     { | ||||
|         private readonly CollectionRepository<PermissionAdapter> repository; | ||||
|         private readonly CacheSettings cacheSettings; | ||||
|         private readonly ICacheSettings cacheSettings; | ||||
|         private readonly IRedisCacheProvider cacheProvider; | ||||
|  | ||||
|         public PermissionProvider(CollectionRepository<PermissionAdapter> repository, | ||||
|         public PermissionProvider( | ||||
|             CollectionRepository<PermissionAdapter> repository, | ||||
|             IRedisCacheProvider cacheProvider, | ||||
|             IOptions<CacheSettings> cacheSettings | ||||
|             ) | ||||
|             ICacheSettings cacheSettings) | ||||
|         { | ||||
|             this.repository = repository; | ||||
|             this.repository.CollectionInitialization(); | ||||
|             this.cacheSettings = cacheSettings.Value; | ||||
|             this.cacheProvider = cacheProvider; | ||||
|             this.cacheSettings = cacheSettings; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new Permission. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Permission to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="newPermission">The Permission to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var permissionCollection = newPermission.Adapt<PermissionAdapter>(); | ||||
|  | ||||
|             await repository.InsertOneAsync(permissionCollection); | ||||
|  | ||||
|             return permissionCollection; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an Permission by identifier. | ||||
|         /// Gets a Permission by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The Permission identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns>0 | ||||
|         /// <param name="_id">The Permission Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             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); | ||||
|  | ||||
|             return permission; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the permissions. | ||||
|         /// Gets all Permissions. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing 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) ?? []; | ||||
|  | ||||
|             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, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return permissions; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the permissions by permissions identifier list. | ||||
|         /// Gets all Permissions by a list of identifiers. | ||||
|         /// </summary> | ||||
|         /// <param name="permissions">The list of permissions identifiers.</param> | ||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="permissions">The list of Permission identifiers.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{PermissionAdapter}}"/> representing 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 cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; | ||||
|  | ||||
|             if (cachedData.Any()) return cachedData; | ||||
| @@ -106,49 +109,61 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|             var builder = Builders<PermissionAdapter>.Filter; | ||||
|             var filters = new List<FilterDefinition<PermissionAdapter>>(); | ||||
|  | ||||
|             if (permissions != null || !permissions.Any()) | ||||
|             if (permissions is { Length: > 0 }) | ||||
|             { | ||||
|                 filters.Add(builder.In(x => x._Id, permissions)); | ||||
|             } | ||||
|  | ||||
|             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||
|  | ||||
|             var permissionsList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, permissionsList); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, permissionsList, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|             return permissionsList; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the permission. | ||||
|         /// Changes the status of a Permission. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The permission identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the permission.</param> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async ValueTask<PermissionAdapter> ChangePermissionStatus(string id, Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         /// <param name="_id">The Permission Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Permission.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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) | ||||
|         { | ||||
|             var entity = await repository.FindByIdAsync(id); | ||||
|             var entity = await repository.FindByIdAsync(_id); | ||||
|             entity.Status = newStatus; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Permission by id. | ||||
|         /// Updates a Permission. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Permission to be updated.</param> | ||||
|         /// <param name="id">The Permission identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Permission by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Permission Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{PermissionAdapter}"/> representing the asynchronous deletion result. | ||||
|         /// The deleted Permission entity if found; otherwise, null. | ||||
|         /// </returns> | ||||
|         public async ValueTask<PermissionAdapter?> DeletePermission(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var entity = await this.repository.DeleteOneAsync(doc => doc._Id == _id); | ||||
|             return entity; | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Blueprint.Redis; | ||||
| using Core.Blueprint.Redis.Helpers; | ||||
| @@ -10,7 +11,6 @@ using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Mapster; | ||||
| using Microsoft.Extensions.Options; | ||||
| using MongoDB.Driver; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| @@ -21,146 +21,166 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|     public class RoleProvider : IRoleProvider | ||||
|     { | ||||
|         private readonly CollectionRepository<RoleAdapter> repository; | ||||
|         private readonly CacheSettings cacheSettings; | ||||
|         private readonly ICacheSettings cacheSettings; | ||||
|         private readonly IRedisCacheProvider cacheProvider; | ||||
|  | ||||
|         public RoleProvider(CollectionRepository<RoleAdapter> repository, | ||||
|         public RoleProvider( | ||||
|             CollectionRepository<RoleAdapter> repository, | ||||
|             IRedisCacheProvider cacheProvider, | ||||
|             IOptions<CacheSettings> cacheSettings | ||||
|             ) | ||||
|             ICacheSettings cacheSettings) | ||||
|         { | ||||
|             this.repository = repository; | ||||
|             this.repository.CollectionInitialization(); | ||||
|             this.cacheSettings = cacheSettings.Value; | ||||
|             this.cacheProvider = cacheProvider; | ||||
|             this.cacheSettings = cacheSettings; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new Role. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Role to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="newRole">The Role to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var roleCollection = newRole.Adapt<RoleAdapter>(); | ||||
|  | ||||
|             await repository.InsertOneAsync(roleCollection); | ||||
|  | ||||
|             return roleCollection; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an Role by identifier. | ||||
|         /// Gets a Role by its identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The Role identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="_id">The Role Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing 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); | ||||
|  | ||||
|             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, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return role; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the roles. | ||||
|         /// Gets all Roles. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{RoleAdapter}}"/> representing 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) ?? []; | ||||
|  | ||||
|             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, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return roles; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the role. | ||||
|         /// Changes the status of a Role. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The role identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the role.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async ValueTask<RoleAdapter> ChangeRoleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         /// <param name="_id">The Role Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Role.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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) | ||||
|         { | ||||
|             var entity = await repository.FindByIdAsync(id); | ||||
|             var entity = await repository.FindByIdAsync(_id); | ||||
|             entity.Status = newStatus; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Role by id. | ||||
|         /// Updates a Role. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Role to be updated.</param> | ||||
|         /// <param name="id">The Role identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Adds an application to the role's list of applications. | ||||
|         /// Adds an application to the Role's list of applications. | ||||
|         /// </summary> | ||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> | ||||
|         /// <param name="roleId">The identifier of the Role to which the application will be added.</param> | ||||
|         /// <param name="application">The application enum value to add.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation, with the updated Role object. | ||||
|         /// </returns> | ||||
|         public async ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var role = await repository.FindOneAsync( | ||||
|                 u => u._Id == roleId && | ||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||
|                 u => u._Id == roleId && u.Status == Blueprint.Mongo.StatusEnum.Active); | ||||
|  | ||||
|             var updatedApplications = role.Applications.Append(application).Distinct().ToArray(); | ||||
|             var updatedApplications = role.Applications?.Append(application).Distinct().ToArray(); | ||||
|             role.Applications = updatedApplications; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(role); | ||||
|             return role; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes an application from the Role's list of applications. | ||||
|         /// </summary> | ||||
|         /// <param name="roleId">The identifier of the Role from which the application will be removed.</param> | ||||
|         /// <param name="application">The application enum value to remove.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous operation, with the updated Role object. | ||||
|         /// </returns> | ||||
|         public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var role = await repository.FindOneAsync( | ||||
|                 u => u._Id == roleId && u.Status == Blueprint.Mongo.StatusEnum.Active); | ||||
|  | ||||
|             var updatedApplications = role.Applications? | ||||
|                 .Where(c => c != application) | ||||
|                 .ToArray(); | ||||
|  | ||||
|             role.Applications = updatedApplications; | ||||
|             await repository.ReplaceOneAsync(role); | ||||
|  | ||||
|             return role; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Removes an application from the role's list of applications. | ||||
|         /// Deletes a Role by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> | ||||
|         /// <param name="application">The application enum value to remove.</param> | ||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||
|         public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||
|         /// <param name="_id">The Role Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{RoleAdapter}"/> representing the asynchronous deletion result. | ||||
|         /// The deleted Role entity if found; otherwise, null. | ||||
|         /// </returns> | ||||
|         public async ValueTask<RoleAdapter?> DeleteRole(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var role = await repository.FindOneAsync( | ||||
|                 u => u._Id == roleId && | ||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||
|  | ||||
|             var updatedApplications = role.Applications | ||||
|                     ?.Where(c => c != application) | ||||
|                     .ToArray(); | ||||
|  | ||||
|             role.Applications = updatedApplications; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(role); | ||||
|  | ||||
|             return role; | ||||
|             var entity = await repository.DeleteOneAsync(doc => doc._Id == _id); | ||||
|             return entity; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										140
									
								
								Core.Thalos.Provider/Providers/Onboarding/TenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								Core.Thalos.Provider/Providers/Onboarding/TenantProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,140 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="TenantService.cs"> | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Blueprint.Redis; | ||||
| using Core.Blueprint.Redis.Helpers; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Mapster; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="TenantAdapter"/>. | ||||
|     /// </summary> | ||||
|     public class TenantProvider : ITenantProvider | ||||
|     { | ||||
|         private readonly CollectionRepository<TenantAdapter> repository; | ||||
|         private readonly ICacheSettings cacheSettings; | ||||
|         private readonly IRedisCacheProvider cacheProvider; | ||||
|  | ||||
|         public TenantProvider( | ||||
|             CollectionRepository<TenantAdapter> repository, | ||||
|             IRedisCacheProvider cacheProvider, | ||||
|             ICacheSettings cacheSettings) | ||||
|         { | ||||
|             this.repository = repository; | ||||
|             this.repository.CollectionInitialization(); | ||||
|             this.cacheSettings = cacheSettings; | ||||
|             this.cacheProvider = cacheProvider; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new Tenant. | ||||
|         /// </summary> | ||||
|         /// <param name="newTenant">The Tenant to be created.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<TenantAdapter> CreateTenant(TenantRequest newTenant, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var tenant = newTenant.Adapt<TenantAdapter>(); | ||||
|             await repository.InsertOneAsync(tenant); | ||||
|             return tenant; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets a Tenant by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<TenantAdapter> GetTenantById(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTenantById", _id); | ||||
|             var cachedData = await cacheProvider.GetAsync<TenantAdapter>(cacheKey); | ||||
|  | ||||
|             if (cachedData is not null) return cachedData; | ||||
|  | ||||
|             var tenant = await repository.FindByIdAsync(_id); | ||||
|             await cacheProvider.SetAsync(cacheKey, tenant, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return tenant; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all Tenants. | ||||
|         /// </summary> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{IEnumerable{TenantAdapter}}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<IEnumerable<TenantAdapter>> GetAllTenants(CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetTenants"); | ||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<TenantAdapter>>(cacheKey) ?? []; | ||||
|  | ||||
|             //if (cachedData.Any()) return cachedData; | ||||
|  | ||||
|             var tenants = await repository.AsQueryable(); | ||||
|             await cacheProvider.SetAsync(cacheKey, tenants, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return tenants; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of a Tenant. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||
|         /// <param name="newStatus">The new status of the Tenant.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <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) | ||||
|         { | ||||
|             var entity = await repository.FindByIdAsync(_id); | ||||
|             entity.Status = newStatus; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a Tenant. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The Tenant to be updated.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous execution of the service. | ||||
|         /// </returns> | ||||
|         public async ValueTask<TenantAdapter> UpdateTenant(TenantAdapter entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a Tenant by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="_id">The Tenant Mongo identifier.</param> | ||||
|         /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> | ||||
|         /// <returns> | ||||
|         /// A <see cref="ValueTask{TenantAdapter}"/> representing the asynchronous deletion result. | ||||
|         /// The deleted Tenant entity if found; otherwise, null. | ||||
|         /// </returns> | ||||
|         public async ValueTask<TenantAdapter?> DeleteTenant(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var entity = await repository.DeleteOneAsync(doc => doc._Id == _id); | ||||
|             return entity; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -10,7 +10,6 @@ using Core.Blueprint.Redis.Helpers; | ||||
| using Core.Thalos.BuildingBlocks; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Mapster; | ||||
| using Microsoft.Extensions.Options; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Bson.Serialization; | ||||
| using MongoDB.Driver; | ||||
| @@ -24,17 +23,17 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|     public class UserProvider : IUserProvider | ||||
|     { | ||||
|         private readonly CollectionRepository<UserAdapter> repository; | ||||
|         private readonly CacheSettings cacheSettings; | ||||
|         private readonly ICacheSettings cacheSettings; | ||||
|         private readonly IRedisCacheProvider cacheProvider; | ||||
|  | ||||
|         public UserProvider(CollectionRepository<UserAdapter> repository, | ||||
|             IRedisCacheProvider cacheProvider, | ||||
|             IOptions<CacheSettings> cacheSettings | ||||
|             ICacheSettings cacheSettings | ||||
|             ) | ||||
|         { | ||||
|             this.repository = repository; | ||||
|             this.repository.CollectionInitialization(); | ||||
|             this.cacheSettings = cacheSettings.Value; | ||||
|             this.cacheSettings = cacheSettings; | ||||
|             this.cacheProvider = cacheProvider; | ||||
|         } | ||||
|  | ||||
| @@ -56,7 +55,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|         /// <summary> | ||||
|         /// Gets an User by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <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> GetUserById(string _id, CancellationToken cancellationToken) | ||||
| @@ -68,7 +67,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|  | ||||
|             var user = await repository.FindByIdAsync(_id); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, user); | ||||
|             await cacheProvider.SetAsync(cacheKey, user, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return user; | ||||
|         } | ||||
| @@ -83,11 +82,11 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|             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, TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes)); | ||||
|  | ||||
|             return users; | ||||
|         } | ||||
| @@ -98,7 +97,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|         /// <param name="email">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken) | ||||
|         public async ValueTask<UserAdapter> GetUserByEmail(string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||
| @@ -120,7 +119,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|         /// <param name="email">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken) | ||||
|         public async ValueTask<UserExistenceAdapter> ValidateUserExistence(string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||
| @@ -143,13 +142,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|         /// <summary> | ||||
|         /// Changes the status of the user. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The user identifier.</param> | ||||
|         /// <param name="_id">The user mongo identifier.</param> | ||||
|         /// <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); | ||||
|             var entity = await repository.FindByIdAsync(_id); | ||||
|             entity.Status = newStatus; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
| @@ -158,10 +157,10 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a User by id. | ||||
|         /// Updates a User by _id. | ||||
|         /// </summary> | ||||
|         /// <param name="entity">The User to be updated.</param> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <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) | ||||
| @@ -174,7 +173,7 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <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?> LogInUser(string email, CancellationToken cancellationToken) | ||||
| @@ -318,19 +317,19 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|                     User = new UserAdapter | ||||
|                     { | ||||
|                         Id = result["_id"]?.ToString() ?? "", | ||||
|                         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() : "", | ||||
|                         Guid = result.Contains("guid") && !result["guid"].IsBsonNull ? result["guid"].AsString : string.Empty, | ||||
|                         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, | ||||
|                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : string.Empty, | ||||
|                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : string.Empty, | ||||
|                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : string.Empty, | ||||
|                         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 : "", | ||||
|                         CreatedBy = result.Contains("createdBy") && !result["createdBy"].IsBsonNull ? result["createdBy"].AsString : string.Empty, | ||||
|                         UpdatedAt = result.Contains("updatedAt") && !result["updatedAt"].IsBsonNull ? result["updatedAt"].ToUniversalTime() : DateTime.MinValue, | ||||
|                         UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : "", | ||||
|                         UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : string.Empty, | ||||
|                         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 | ||||
| @@ -339,13 +338,13 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|                     { | ||||
|                         Id = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("_id") | ||||
|                             ? result["role"]["_id"]?.ToString() ?? "" | ||||
|                             : "", | ||||
|                             : string.Empty, | ||||
|                         Name = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("name") | ||||
|                             ? result["role"]["name"]?.AsString ?? "" | ||||
|                             : "", | ||||
|                             : string.Empty, | ||||
|                         Description = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("description") | ||||
|                             ? result["role"]["description"]?.AsString ?? "" | ||||
|                             : "", | ||||
|                             : string.Empty, | ||||
|                         Applications = result.Contains("role") && result["role"].IsBsonDocument && | ||||
|                        result["role"].AsBsonDocument.Contains("applications") && | ||||
|                        result["role"]["applications"].IsBsonArray | ||||
| @@ -389,12 +388,12 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|                             result["role"].AsBsonDocument.Contains("createdBy") && | ||||
|                             !result["role"]["createdBy"].IsBsonNull | ||||
|                             ? result["role"]["createdBy"].AsString | ||||
|                             : "", | ||||
|                             : string.Empty, | ||||
|                         UpdatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||
|                             result["role"].AsBsonDocument.Contains("updatedBy") && | ||||
|                             !result["role"]["updatedBy"].IsBsonNull | ||||
|                             ? result["role"]["updatedBy"].AsString | ||||
|                             : "" | ||||
|                             : string.Empty | ||||
|                     }, | ||||
|                     Permissions = result.Contains("permissions") && result["permissions"].IsBsonArray | ||||
|                         ? result["permissions"].AsBsonArray | ||||
| @@ -416,12 +415,12 @@ namespace Core.Thalos.Provider.Providers.Onboarding | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes an User by id. | ||||
|         /// Deletes an User by _id. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <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> DeleteUser(string _id, CancellationToken cancellationToken) | ||||
|         public async ValueTask<UserAdapter?> DeleteUser(string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var entity = await repository.DeleteOneAsync(doc => doc.Id == _id); | ||||
|  | ||||
|   | ||||
| @@ -24,6 +24,9 @@ namespace Core.Thalos.Provider | ||||
|             services.AddScoped<IUserProvider, UserProvider>(); | ||||
|             services.AddScoped<CollectionRepository<UserAdapter>>(); | ||||
|  | ||||
|             services.AddScoped<ITenantProvider, TenantProvider>(); | ||||
|             services.AddScoped<CollectionRepository<TenantAdapter>>(); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user