Remove unnecessary code from user services
This commit is contained in:
		| @@ -222,86 +222,6 @@ namespace LSA.Core.Thalos.API.Controllers | |||||||
|             return Ok(result); |             return Ok(result); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a company to the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="companyId">The company identifier to add.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated companies.</response> |  | ||||||
|         /// <response code="404">The user or company not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [Route(Routes.AddCompany)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false); |  | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a company from the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="companyId">The company identifier to remove.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated companies.</response> |  | ||||||
|         /// <response code="404">The user or company not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpDelete] |  | ||||||
|         [Route(Routes.RemoveCompany)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ; |  | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a project to the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="projectId">The project identifier to add.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated projects.</response> |  | ||||||
|         /// <response code="404">The user or project not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [Route(Routes.AddProject)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false); |  | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a project from the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="projectId">The project identifier to remove.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated projects.</response> |  | ||||||
|         /// <response code="404">The user or project not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpDelete] |  | ||||||
|         [Route(Routes.RemoveProject)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); |  | ||||||
|             return Ok(result); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets a token for the user, including roles, permissions, and modules. |         /// Gets a token for the user, including roles, permissions, and modules. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|   | |||||||
| @@ -54,19 +54,5 @@ namespace Core.Thalos.Domain.Contexts.Onboarding.Request | |||||||
|         [BsonRepresentation(BsonType.ObjectId)] |         [BsonRepresentation(BsonType.ObjectId)] | ||||||
|         [JsonPropertyName("roleId")] |         [JsonPropertyName("roleId")] | ||||||
|         public string RoleId { get; set; } = null!; |         public string RoleId { get; set; } = null!; | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets or sets the array of companies associated with the user. |  | ||||||
|         /// </summary> |  | ||||||
|         [BsonElement("companies")] |  | ||||||
|         [JsonPropertyName("companies")] |  | ||||||
|         public string[] Companies { get; set; } = null!; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets or sets the array of projects associated with the user. |  | ||||||
|         /// </summary> |  | ||||||
|         [BsonElement("projects")] |  | ||||||
|         [JsonPropertyName("projects")] |  | ||||||
|         public string[]? Projects { get; set; } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ | |||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Core.Blueprint.KeyVault" Version="1.0.3" /> |     <PackageReference Include="Core.Blueprint.KeyVault" Version="1.0.3" /> | ||||||
|     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.7" /> |     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.8" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
| </Project> | </Project> | ||||||
|   | |||||||
| @@ -84,39 +84,6 @@ namespace Core.Thalos.Provider.Contracts | |||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); |         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a company to the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the company will be added.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a company from the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the company will be removed.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a project to the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the project will be added.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a project from the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the project will be removed.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken); |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the token adapter for a user. |         /// Gets the token adapter for a user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|   | |||||||
| @@ -209,92 +209,6 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|             return user; |             return user; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a company to the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the company will be added.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedCompanies = user.Companies.Append(companyId).Distinct().ToArray(); |  | ||||||
|             user.Companies = updatedCompanies; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a company from the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the company will be removed.</param> |  | ||||||
|         /// <param name="companyId">The identifier of the company to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedCompanies = user.Companies |  | ||||||
|                     ?.Where(c => c != companyId) |  | ||||||
|                     .ToArray(); |  | ||||||
|  |  | ||||||
|             user.Companies = updatedCompanies; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a project to the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user to whom the project will be added.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to add.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedProjects = user.Projects.Append(projectId).Distinct().ToArray(); |  | ||||||
|             user.Projects = updatedProjects; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a project from the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The identifier of the user from whom the project will be removed.</param> |  | ||||||
|         /// <param name="projectId">The identifier of the project to remove.</param> |  | ||||||
|         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> |  | ||||||
|         public async ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken) |  | ||||||
|         { |  | ||||||
|             var user = await repository.FindOneAsync( |  | ||||||
|                 u => u._Id == userId && |  | ||||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); |  | ||||||
|  |  | ||||||
|             var updatedProjects = user.Projects |  | ||||||
|                     ?.Where(c => c != projectId) |  | ||||||
|                     .ToArray(); |  | ||||||
|  |  | ||||||
|             user.Projects = updatedProjects; |  | ||||||
|  |  | ||||||
|             await repository.ReplaceOneAsync(user); |  | ||||||
|  |  | ||||||
|             return user; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets the token adapter for a user. |         /// Gets the token adapter for a user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
| @@ -411,18 +325,6 @@ namespace Core.Thalos.Provider.Providers.Onboarding | |||||||
|                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", |                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", | ||||||
|                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", |                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", | ||||||
|                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "", |                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "", | ||||||
|                         Companies = result.Contains("companies") && result["companies"].IsBsonArray |  | ||||||
|                             ? result["companies"].AsBsonArray |  | ||||||
|                                 .Where(c => c != null && !c.IsBsonNull) |  | ||||||
|                                 .Select(c => c.AsString) |  | ||||||
|                                 .ToArray() |  | ||||||
|                             : Array.Empty<string>(), |  | ||||||
|                         Projects = result.Contains("projects") && result["projects"].IsBsonArray |  | ||||||
|                             ? result["projects"].AsBsonArray |  | ||||||
|                                 .Where(p => p != null && !p.IsBsonNull) |  | ||||||
|                                 .Select(p => p.AsString) |  | ||||||
|                                 .ToArray() |  | ||||||
|                             : Array.Empty<string>(), |  | ||||||
|                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, |                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, | ||||||
|                         LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].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, |                         CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user