Compare commits
	
		
			2 Commits
		
	
	
		
			feature/im
			...
			feature/us
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | a36fd0e480 | ||
|   | 24efe5612c | 
							
								
								
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -350,6 +350,6 @@ ASALocalRun/ | ||||
| # Local History for Visual Studio | ||||
| .localhistory/ | ||||
|  | ||||
| /Core.Cerberos.DAL.API/CerberosDALSettings.development.json | ||||
| /Core.Cerberos.DAL.API/cerberosprivkey.pem | ||||
| /Core.Cerberos.DAL.API/cerberospubkey.pem | ||||
| /Core.Thalos.DAL.API/ThalosDALSettings.development.json | ||||
| /Core.Thalos.DAL.API/thalosprivkey.pem | ||||
| /Core.Thalos.DAL.API/thalospubkey.pem | ||||
| @@ -1,6 +0,0 @@ | ||||
| @Core.Cerberos.DAL.API_HostAddress = http://localhost:5211 | ||||
|  | ||||
| GET {{Core.Cerberos.DAL.API_HostAddress}}/weatherforecast/ | ||||
| Accept: application/json | ||||
|  | ||||
| ### | ||||
| @@ -1,24 +0,0 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net8.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <Compile Remove="Providers\Onboarding\UserService - Copy.cs" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Core.Blueprint.Storage" Version="0.3.0-alpha0049" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" /> | ||||
|     <PackageReference Include="MongoDB.Driver" Version="3.0.0" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Core.Cerberos.Domain\Core.Cerberos.Domain.csproj" /> | ||||
|     <ProjectReference Include="..\Core.Cerberos.Infraestructure\Core.Cerberos.Infrastructure.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
| @@ -1,627 +0,0 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="UserService.cs"> | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Cerberos.Infraestructure.Caching.Configs; | ||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using LSA.Core.Dapper.Service.Caching; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.Extensions.Logging; | ||||
| using Microsoft.Extensions.Options; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Bson.Serialization; | ||||
| using MongoDB.Driver; | ||||
| using System.Text.RegularExpressions; | ||||
| using Core.Blueprint.Storage.Contracts; | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
|  | ||||
| namespace Core.Cerberos.Provider.Providers.Onboarding | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="UserAdapter"/>. | ||||
|     /// </summary> | ||||
|     public class UserService(ILogger<UserService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, | ||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database, IBlobStorageProvider blobStorageProvider) : IUserService | ||||
|     { | ||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new User. | ||||
|         /// </summary> | ||||
|         /// <param name="newUser">The User to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async Task<UserAdapter> CreateUserService(UserRequest newUser) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var entity = newUser.ToAdapter(httpContextAccessor); | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).InsertOneAsync(entity); | ||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); | ||||
|  | ||||
|                 return entity; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"CreateUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an User by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async Task<UserAdapter> GetUserByIdService(string id) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByIdService", id); | ||||
|             var cachedData = await cacheService.GetAsync<UserAdapter>(cacheKey); | ||||
|  | ||||
|             if (cachedData is not null) return cachedData; | ||||
|  | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.And( | ||||
|                     Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), | ||||
|                     Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) | ||||
|                 ); | ||||
|  | ||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                             .Find(filter) | ||||
|                             .FirstOrDefaultAsync(); | ||||
|  | ||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); | ||||
|  | ||||
|                 await cacheService.SetAsync(cacheKey, user, cacheDuration); | ||||
|  | ||||
|                 return user; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"GetUserByIdService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the users. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async Task<IEnumerable<UserAdapter>> GetAllUsersService() | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsersService"); | ||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? []; | ||||
|  | ||||
|             if (cachedData.Any()) return cachedData; | ||||
|  | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); | ||||
|  | ||||
|                 var users = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                             .Find(filter) | ||||
|                             .ToListAsync(); | ||||
|  | ||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); | ||||
|                 await cacheService.SetAsync(cacheKey, users, cacheDuration); | ||||
|  | ||||
|                 return users; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"GetAllUsersService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an 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> | ||||
|         public async Task<UserAdapter> GetUserByEmailService(string? email) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.And( | ||||
|                     Builders<UserAdapter>.Filter.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")), | ||||
|                     Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) | ||||
|                 ); | ||||
|  | ||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                             .Find(filter) | ||||
|                             .FirstOrDefaultAsync(); | ||||
|  | ||||
|                 return user; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"GetUserByEmailService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Validates if a users exists by email.. | ||||
|         /// </summary> | ||||
|         /// <param name="email">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async Task<UserAdapter> ValidateUserExistenceService(string? email) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.And( | ||||
|                     Builders<UserAdapter>.Filter.Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")), | ||||
|                     Builders<UserAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) | ||||
|                 ); | ||||
|  | ||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                             .Find(filter) | ||||
|                             .FirstOrDefaultAsync(); | ||||
|  | ||||
|                 return user; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"ValidateUserExistenceService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes an User by id. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async Task<UserAdapter> DeleteUserService(string id) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter | ||||
|                     .Eq("_id", ObjectId.Parse(id)); | ||||
|  | ||||
|                 var update = Builders<UserAdapter>.Update | ||||
|                             .Set(v => v.Status, StatusEnum.Inactive); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var deletedUser = await database.GetCollection<UserAdapter>(CollectionNames.User).Find(filter).FirstAsync(); | ||||
|  | ||||
|                 return deletedUser; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"DeleteUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the 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> | ||||
|         public async Task<UserAdapter> ChangeUserStatusService(string id, StatusEnum newStatus) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter | ||||
|                     .Eq("_id", ObjectId.Parse(id)); | ||||
|  | ||||
|                 var update = Builders<UserAdapter>.Update | ||||
|                             .Set(v => v.Status, newStatus) | ||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) | ||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                                     .Find(filter) | ||||
|                                     .FirstOrDefaultAsync(); | ||||
|  | ||||
|                 return updatedUser; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"ChangeUserStatusService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a User by id. | ||||
|         /// </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> | ||||
|         public async Task<UserAdapter> UpdateUserService(UserAdapter entity, string id) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter | ||||
|                     .Eq("_id", ObjectId.Parse(id)); | ||||
|  | ||||
|                 var update = Builders<UserAdapter>.Update | ||||
|                             .Set(v => v.Email, entity.Email) | ||||
|                             .Set(v => v.Name, entity.Name) | ||||
|                             .Set(v => v.MiddleName, entity.MiddleName) | ||||
|                             .Set(v => v.LastName, entity.LastName) | ||||
|                             .Set(v => v.DisplayName, $"{entity.Name} {entity.MiddleName} {entity.LastName}") | ||||
|                             .Set(v => v.RoleId, entity.RoleId) | ||||
|                             .Set(v => v.Companies, entity.Companies) | ||||
|                             .Set(v => v.Projects, entity.Projects) | ||||
|                             .Set(v => v.Status, entity.Status) | ||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) | ||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var updatedUser = await GetUserByIdService(id); | ||||
|  | ||||
|                 return updatedUser; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"UpdateUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async Task<UserAdapter?> LogInUserService(string email) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter | ||||
|                     .Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")); | ||||
|  | ||||
|                 var update = Builders<UserAdapter>.Update | ||||
|                             .Set(v => v.LastLogIn, DateTime.UtcNow); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                                     .Find(filter) | ||||
|                                     .FirstAsync(); | ||||
|  | ||||
|                 return user; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"LogInUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs out the user's session. | ||||
|         /// </summary> | ||||
|         /// <param name="email">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async Task<UserAdapter> LogOutUserSessionService(string email) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter | ||||
|                     .Regex("email", new BsonRegularExpression($"^{Regex.Escape(email ?? "")}$", "i")); | ||||
|  | ||||
|  | ||||
|                 var update = Builders<UserAdapter>.Update | ||||
|                             .Set(v => v.LastLogOut, DateTime.UtcNow); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var user = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                                     .Find(filter) | ||||
|                                     .FirstAsync(); | ||||
|  | ||||
|                 return user; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"LogOutUserSessionService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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 Task<UserAdapter> AddCompanyToUserService(string userId, string companyId) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); | ||||
|                 var update = Builders<UserAdapter>.Update.AddToSet(v => v.Companies, companyId); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                                     .Find(filter) | ||||
|                                     .FirstOrDefaultAsync(); | ||||
|                 return updatedUser; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"AddCompanyToUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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 Task<UserAdapter> RemoveCompanyFromUserService(string userId, string companyId) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); | ||||
|                 var update = Builders<UserAdapter>.Update.Pull(v => v.Companies, companyId); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                                     .Find(filter) | ||||
|                                     .FirstOrDefaultAsync(); | ||||
|                 return updatedUser; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"RemoveCompanyFromUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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 Task<UserAdapter> AddProjectToUserService(string userId, string projectId) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); | ||||
|                 var update = Builders<UserAdapter>.Update.AddToSet(v => v.Projects, projectId); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                                      .Find(filter) | ||||
|                                      .FirstOrDefaultAsync(); | ||||
|                 return updatedUser; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"AddProjectToUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <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 Task<UserAdapter> RemoveProjectFromUserService(string userId, string projectId) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var filter = Builders<UserAdapter>.Filter.Eq("_id", ObjectId.Parse(userId)); | ||||
|                 var update = Builders<UserAdapter>.Update.Pull(v => v.Projects, projectId); | ||||
|  | ||||
|                 await database.GetCollection<UserAdapter>(CollectionNames.User).UpdateOneAsync(filter, update); | ||||
|  | ||||
|                 var updatedUser = await database.GetCollection<UserAdapter>(CollectionNames.User) | ||||
|                                     .Find(filter) | ||||
|                                     .FirstOrDefaultAsync(); | ||||
|                 return updatedUser; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"RemoveProjectFromUserService: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the token adapter 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> | ||||
|         public async Task<TokenAdapter?> GetTokenAdapter(string email) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var pipeline = new[] | ||||
|                 { | ||||
|                     new BsonDocument("$match", new BsonDocument | ||||
|                     { | ||||
|                         { "email", new BsonDocument | ||||
|                             { | ||||
|                                 { "$regex", $"^{Regex.Escape(email)}$" }, | ||||
|                                 { "$options", "i" } | ||||
|                             } | ||||
|                         }, | ||||
|                         { "status", StatusEnum.Active.ToString() } | ||||
|                     }), | ||||
|  | ||||
|                     new BsonDocument("$lookup", new BsonDocument | ||||
|                     { | ||||
|                         { "from", "Roles" }, | ||||
|                         { "localField", "roleId" }, | ||||
|                         { "foreignField", "_id" }, | ||||
|                         { "as", "role" } | ||||
|                     }), | ||||
|  | ||||
|                     new BsonDocument("$unwind", "$role"), | ||||
|                     new BsonDocument("$match", new BsonDocument("role.status", StatusEnum.Active.ToString())), | ||||
|  | ||||
|                     new BsonDocument("$addFields", new BsonDocument | ||||
|                     { | ||||
|                         { "role.permissions", new BsonDocument("$map", new BsonDocument | ||||
|                             { | ||||
|                                 { "input", "$role.permissions" }, | ||||
|                                 { "as", "perm" }, | ||||
|                                 { "in", new BsonDocument("$toObjectId", "$$perm") } | ||||
|                             }) | ||||
|                         }, | ||||
|                         { "role.modules", new BsonDocument("$map", new BsonDocument | ||||
|                             { | ||||
|                                 { "input", "$role.modules" }, | ||||
|                                 { "as", "mod" }, | ||||
|                                 { "in", new BsonDocument("$toObjectId", "$$mod") } | ||||
|                             }) | ||||
|                         } | ||||
|                     }), | ||||
|  | ||||
|                     new BsonDocument("$lookup", new BsonDocument | ||||
|                     { | ||||
|                         { "from", "Permissions" }, | ||||
|                         { "localField", "role.permissions" }, | ||||
|                         { "foreignField", "_id" }, | ||||
|                         { "as", "permissions" } | ||||
|                     }), | ||||
|                     new BsonDocument("$lookup", new BsonDocument | ||||
|                     { | ||||
|                         { "from", "Modules" }, | ||||
|                         { "localField", "role.modules" }, | ||||
|                         { "foreignField", "_id" }, | ||||
|                         { "as", "modules" } | ||||
|                     }), | ||||
|                     new BsonDocument("$project", new BsonDocument | ||||
|                     { | ||||
|                         { "_id", 1 }, | ||||
|                         { "guid", 1 }, | ||||
|                         { "email", 1 }, | ||||
|                         { "name", 1 }, | ||||
|                         { "middleName", 1 }, | ||||
|                         { "lastName", 1 }, | ||||
|                         { "displayName", 1 }, | ||||
|                         { "roleId", 1 }, | ||||
|                         { "companies", 1 }, | ||||
|                         { "projects", 1 }, | ||||
|                         { "lastLogIn", 1 }, | ||||
|                         { "lastLogOut", 1 }, | ||||
|                         { "createdBy", 1 }, | ||||
|                         { "updatedBy", 1 }, | ||||
|                         { "status", 1 }, | ||||
|                         { "createdAt", 1 }, | ||||
|                         { "updatedAt", 1 }, | ||||
|                         { "role._id", 1 }, | ||||
|                         { "role.name", 1 }, | ||||
|                         { "role.description", 1 }, | ||||
|                         { "role.applications", 1 }, | ||||
|                         { "role.permissions", 1 }, | ||||
|                         { "role.modules", 1 }, | ||||
|                         { "role.status", 1 }, | ||||
|                         { "role.createdAt", 1 }, | ||||
|                         { "role.updatedAt", 1 }, | ||||
|                         { "role.createdBy", 1 }, | ||||
|                         { "role.updatedBy", 1 }, | ||||
|                         { "permissions", 1 }, | ||||
|                         { "modules", 1 } | ||||
|                     }) | ||||
|                 }; | ||||
|  | ||||
|  | ||||
|                 var result = await database.GetCollection<BsonDocument>(CollectionNames.User) | ||||
|                     .Aggregate<BsonDocument>(pipeline) | ||||
|                     .FirstOrDefaultAsync(); | ||||
|  | ||||
|                 if (result is null) return null; | ||||
|  | ||||
|                 var tokenAdapter = new TokenAdapter | ||||
|                 { | ||||
|                     User = new UserAdapter | ||||
|                     { | ||||
|                         Id = result["_id"]?.ToString() ?? "", | ||||
|                         Guid = result["guid"].AsString, | ||||
|                         Email = result["email"].AsString, | ||||
|                         Name = result["name"].AsString, | ||||
|                         MiddleName = result["middleName"].AsString, | ||||
|                         LastName = result["lastName"].AsString, | ||||
|                         DisplayName = result["displayName"].AsString, | ||||
|                         RoleId = result["roleId"]?.ToString() ?? "", | ||||
|                         Companies = result["companies"].AsBsonArray | ||||
|                             .Select(c => c.AsString) | ||||
|                             .ToArray(), | ||||
|                         Projects = result["projects"].AsBsonArray | ||||
|                             .Select(c => c.AsString) | ||||
|                             .ToArray(), | ||||
|                         LastLogIn = result["lastLogIn"].ToUniversalTime(), | ||||
|                         LastLogOut = result["lastLogOut"].ToUniversalTime(), | ||||
|                         CreatedAt = result["createdAt"].ToUniversalTime(), | ||||
|                         CreatedBy = result["createdBy"].AsString, | ||||
|                         UpdatedAt = result["updatedAt"].ToUniversalTime(), | ||||
|                         UpdatedBy = result["updatedBy"].AsString, | ||||
|                         Status = (StatusEnum)Enum.Parse(typeof(StatusEnum), result["status"].AsString), | ||||
|                     }, | ||||
|                     Role = new RoleAdapter | ||||
|                     { | ||||
|                         Id = result["role"]["_id"]?.ToString() ?? "", | ||||
|                         Name = result["role"]["name"].AsString, | ||||
|                         Description = result["role"]["description"].AsString, | ||||
|                         Applications = result["role"]["applications"].AsBsonArray | ||||
|                             .Select(c => (ApplicationsEnum)c.AsInt32) | ||||
|                             .ToArray(), | ||||
|                         Modules = result["role"]["modules"].AsBsonArray | ||||
|                             .Select(c => c.ToString() ?? "") | ||||
|                             .ToArray(), | ||||
|                         Permissions = result["role"]["permissions"].AsBsonArray | ||||
|                             .Select(c => c.ToString() ?? "") | ||||
|                             .ToArray(), | ||||
|                         Status = (StatusEnum)Enum.Parse(typeof(StatusEnum), result["role"]["status"].AsString), | ||||
|                         CreatedAt = result["role"]["createdAt"].ToUniversalTime(), | ||||
|                         UpdatedAt = result["role"]["updatedAt"].ToUniversalTime(), | ||||
|                         CreatedBy = result["role"]["createdBy"].AsString, | ||||
|                         UpdatedBy = result["role"]["updatedBy"].AsString | ||||
|                     }, | ||||
|                     Permissions = result["permissions"].AsBsonArray | ||||
|                         .Select(permission => BsonSerializer.Deserialize<PermissionAdapter>(permission.AsBsonDocument)) | ||||
|                         .Where(permission => permission.Status == StatusEnum.Active) | ||||
|                         .ToList() | ||||
|                 }; | ||||
|  | ||||
|                 return tokenAdapter; | ||||
|  | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, $"GetTokenAdapter: Error in getting data - {ex.Message}"); | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
| # Visual Studio Version 17 | ||||
| VisualStudioVersion = 17.10.35027.167 | ||||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.DAL.API", "Core.Cerberos.DAL.API\Core.Cerberos.DAL.API.csproj", "{F00B4683-03B3-487A-9608-4B30675AA278}" | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.DAL.API", "Core.Thalos.DAL.API\Core.Thalos.DAL.API.csproj", "{F00B4683-03B3-487A-9608-4B30675AA278}" | ||||
| EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{2E7D918E-AB9F-44BF-A334-FD675C9B626E}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Domain", "Core.Cerberos.Domain\Core.Cerberos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}" | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Domain", "Core.Thalos.Domain\Core.Thalos.Domain.csproj", "{BE8E05D6-05B2-4317-B619-21853B7D21DB}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Infrastructure", "Core.Cerberos.Infraestructure\Core.Cerberos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}" | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Infrastructure", "Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj", "{43BD5F47-132F-4E78-83F1-A1FEED01A502}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Cerberos.Provider", "Core.Cerberos.Provider\Core.Cerberos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Thalos.Provider", "Core.Thalos.Provider\Core.Thalos.Provider.csproj", "{8CAE8380-475F-46B8-AF90-C495AAC58606}" | ||||
| EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" | ||||
| EndProject | ||||
| @@ -5,12 +5,12 @@ | ||||
| // *********************************************************************** | ||||
| 
 | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| 
 | ||||
| @@ -37,7 +37,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesAsync() | ||||
|         { | ||||
| @@ -67,7 +67,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules) | ||||
|         { | ||||
| @@ -108,7 +108,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Read")] | ||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id) | ||||
|         { | ||||
| @@ -137,7 +137,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal e|ror.</response> | ||||
|         [HttpPost] | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule) | ||||
|         { | ||||
| @@ -168,7 +168,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateModuleAsync(ModuleAdapter entity, string id) | ||||
|         { | ||||
| @@ -200,7 +200,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("ModuleManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) | ||||
|         { | ||||
| @@ -5,12 +5,12 @@ | ||||
| // *********************************************************************** | ||||
| 
 | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| 
 | ||||
| @@ -37,7 +37,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllPermissionsAsync() | ||||
|         { | ||||
| @@ -67,7 +67,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("PermissionManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions) | ||||
|         { | ||||
| @@ -107,7 +107,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("PermissionManagement.Read")] | ||||
|         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id) | ||||
|         { | ||||
| @@ -136,7 +136,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal e|ror.</response> | ||||
|         [HttpPost] | ||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission) | ||||
|         { | ||||
| @@ -167,7 +167,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> UpdatePermissionAsync(PermissionAdapter entity, string id) | ||||
|         { | ||||
| @@ -199,7 +199,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Consumes(MimeTypes.ApplicationJson)] | ||||
|         [Produces(MimeTypes.ApplicationJson)] | ||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("PermissionManagement.Write")] | ||||
|         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) | ||||
|         { | ||||
| @@ -4,12 +4,12 @@ | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Asp.Versioning; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| 
 | ||||
| @@ -34,7 +34,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpGet] | ||||
|         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllRolesAsync() | ||||
|         { | ||||
| @@ -62,7 +62,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpGet] | ||||
|         [Route(Routes.Id)] | ||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("RoleManagement.Read")] | ||||
|         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id) | ||||
|         { | ||||
| @@ -91,7 +91,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpPost] | ||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole) | ||||
|         { | ||||
| @@ -121,7 +121,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpPut] | ||||
|         [Route(Routes.Id)] | ||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string id) | ||||
|         { | ||||
| @@ -151,7 +151,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpPatch] | ||||
|         [Route(Routes.ChangeStatus)] | ||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) | ||||
|         { | ||||
| @@ -181,7 +181,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpPost(Routes.AddApplication)] | ||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, | ||||
|                                                                    [FromRoute] ApplicationsEnum application) | ||||
| @@ -211,7 +211,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpDelete(Routes.RemoveApplication)] | ||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("RoleManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, | ||||
|                                                                         [FromRoute] ApplicationsEnum application) | ||||
| @@ -4,16 +4,15 @@ | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Asp.Versioning; | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Attributes; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Attributes; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Microsoft.AspNetCore.Authorization; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| using Microsoft.Graph; | ||||
| using UserRequest = Core.Cerberos.Domain.Contexts.Onboarding.Request.UserRequest; | ||||
| using UserRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | ||||
| 
 | ||||
| namespace LSA.Core.Kerberos.API.Controllers | ||||
| { | ||||
| @@ -25,7 +24,7 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|     [Produces(MimeTypes.ApplicationJson)] | ||||
|     [Consumes(MimeTypes.ApplicationJson)] | ||||
|     [ApiController] | ||||
|     public class UserController(IUserService service, ILogger<UserController> logger) : ControllerBase | ||||
|     public class UserController(IUserProvider service) : ControllerBase | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Gets all the users. | ||||
| @@ -36,21 +35,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpGet] | ||||
|         [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Read")] | ||||
|         public async Task<IActionResult> GetAllUsersService() | ||||
|         public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.GetAllUsersService(); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in GetAllUsersService"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -64,23 +54,18 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpGet] | ||||
|         [Route(Routes.Id)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Read")] | ||||
|         public async Task<IActionResult> GetUserByIdService([FromRoute] string id) | ||||
|         public async Task<IActionResult> GetUserById([FromRoute] string _id, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.GetUserByIdService(id); | ||||
|             var result = await service.GetUserById(_id, cancellationToken).ConfigureAwait(false); | ||||
| 
 | ||||
|                 if (result is null) return NotFound($"user with id: '{id}' not found"); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             if (result == null) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in GetUserByIdService"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|                 return NotFound("Entity not found"); | ||||
|             } | ||||
| 
 | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -94,22 +79,17 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpGet] | ||||
|         [Route(Routes.Email)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> GetUserByEmail([FromRoute] string email) | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.GetUserByEmailService(email); | ||||
|             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); | ||||
| 
 | ||||
|                 if (result is null) return NotFound($"user with email: '{email}' not found"); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             if (result == null) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in GetUserByIdEmail"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|                 return NotFound("User not found"); | ||||
|             } | ||||
| 
 | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -124,24 +104,16 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [Route("{email}/ValidateExistence")] | ||||
|         [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] | ||||
|         [AllowAnonymous] | ||||
|         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email) | ||||
|         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.ValidateUserExistenceService(email); | ||||
|             var result = await service.ValidateUserExistence(email, cancellationToken).ConfigureAwait(false); | ||||
| 
 | ||||
|                 var existence = new UserExistenceAdapter | ||||
|                 { | ||||
|                     Existence = (result is not null) ? true : false | ||||
|                 }; | ||||
| 
 | ||||
|                 return Ok(existence); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             if (result == null) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in ValidateUserExistance"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|                 return NotFound("User not found"); | ||||
|             } | ||||
| 
 | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -155,26 +127,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpPost(Routes.Register)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, [FromRoute] bool sendInvitation) | ||||
|         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var user = await service.GetUserByEmailService(newUser.Email).ConfigureAwait(false); | ||||
| 
 | ||||
|                 if (user is not null) | ||||
|                     return UnprocessableEntity("There is a user with the same email registered in the database"); | ||||
| 
 | ||||
|                 var result = await service.CreateUserService(newUser).ConfigureAwait(false); | ||||
| 
 | ||||
|                 return Created("CreatedWithIdService", result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in CreateUserAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false); | ||||
|             return Created("CreatedWithIdAsync", result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -190,21 +148,18 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpPut] | ||||
|         [Route(Routes.Id)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string id) | ||||
|         public async Task<IActionResult> UpdateUserAsync([FromRoute] string _id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             if (_id != entity._Id?.ToString()) | ||||
|             { | ||||
|                 var result = await service.UpdateUserService(entity, id); | ||||
|                 return BadRequest("User ID mismatch"); | ||||
|             } | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in UpdateUserAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.UpdateUser(entity, cancellationToken).ConfigureAwait(false); | ||||
| 
 | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -218,23 +173,15 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpPatch(Routes.LogIn)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> LoginUserAsync([FromRoute] string email) | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.LogInUserService(email).ConfigureAwait(false); | ||||
|             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); | ||||
| 
 | ||||
|                 if (result is null) | ||||
|                     return new NotFoundObjectResult($"The user with email: '{email}' was not found"); | ||||
|             if (result is null) | ||||
|                 return new NotFoundObjectResult($"The user with email: '{email}' was not found"); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in LogInUserService"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -247,20 +194,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         /// <response code="500">The service internal error.</response> | ||||
|         [HttpPatch(Routes.LogOut)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email) | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.LogOutUserSessionService(email).ConfigureAwait(false); | ||||
|             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in LogOutUserSessionService"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             return Ok(result); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
| @@ -277,21 +216,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpPatch] | ||||
|         [Route(Routes.ChangeStatus)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) | ||||
|         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.ChangeUserStatusService(id, newStatus); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in ChangeUserStatus"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.ChangeUserStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -306,21 +236,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpPost] | ||||
|         [Route(Routes.AddCompany)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId) | ||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.AddCompanyToUserService(userId, companyId); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in AddCompanyToUserAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -335,21 +256,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpDelete] | ||||
|         [Route(Routes.RemoveCompany)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId) | ||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.RemoveCompanyFromUserService(userId, companyId); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in RemoveCompanyFromUserAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ; | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -364,21 +276,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpPost] | ||||
|         [Route(Routes.AddProject)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId) | ||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.AddProjectToUserService(userId, projectId); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in AddProjectToUserAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -393,21 +296,12 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpDelete] | ||||
|         [Route(Routes.RemoveProject)] | ||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] | ||||
|         [Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||
|         [Permission("UserManagement.Write")] | ||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId) | ||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var result = await service.RemoveProjectFromUserService(userId, projectId); | ||||
| 
 | ||||
|                 return Ok(result); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in RemoveProjectFromUserAsync"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             var result = await service.RemoveCompanyFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); | ||||
|             return Ok(result); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -421,22 +315,14 @@ namespace LSA.Core.Kerberos.API.Controllers | ||||
|         [HttpGet] | ||||
|         [Route("{email}/GetTokenAdapter")] | ||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email) | ||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||
|         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var tokenAdapter = await service.GetTokenAdapter(email); | ||||
|             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); | ||||
| 
 | ||||
|                 if (tokenAdapter == null) return NotFound($"User with email: {email} not found"); | ||||
|             if (tokenAdapter == null) return NotFound($"User with email: {email} not found"); | ||||
| 
 | ||||
|                 return Ok(tokenAdapter); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger.LogError(ex, "Error in GetTokenAdapter"); | ||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); | ||||
|             } | ||||
|             return Ok(tokenAdapter); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										6
									
								
								Core.Thalos.DAL.API/Core.Cerberos.DAL.API.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								Core.Thalos.DAL.API/Core.Cerberos.DAL.API.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| @Core.Thalos.DAL.API_HostAddress = http://localhost:5211 | ||||
|  | ||||
| GET {{Core.Thalos.DAL.API_HostAddress}}/weatherforecast/ | ||||
| Accept: application/json | ||||
|  | ||||
| ### | ||||
| @@ -16,12 +16,11 @@ | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Blueprint.Logging" Version="0.0.1" /> | ||||
|     <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Core.Cerberos.Domain\Core.Cerberos.Domain.csproj" /> | ||||
|     <ProjectReference Include="..\Core.Cerberos.Provider\Core.Cerberos.Provider.csproj" /> | ||||
|     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> | ||||
|     <ProjectReference Include="..\Core.Thalos.Provider\Core.Thalos.Provider.csproj" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
| @@ -1,7 +1,7 @@ | ||||
| using Core.Blueprint.Logging.Configuration; | ||||
| using Core.Cerberos.Adapters.Extensions; | ||||
| using Core.Cerberos.Adapters.Helpers; | ||||
| using Core.Cerberos.Provider; | ||||
| using Core.Thalos.Adapters.Extensions; | ||||
| using Core.Thalos.Adapters.Helpers; | ||||
| using Core.Thalos.Provider; | ||||
| using Microsoft.AspNetCore.RateLimiting; | ||||
| using Microsoft.AspNetCore.ResponseCompression; | ||||
| using System.IO.Compression; | ||||
| @@ -10,7 +10,7 @@ using System.Threading.RateLimiting; | ||||
| 
 | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
| 
 | ||||
| var authSettings = AuthHelper.GetAuthSettings(builder, "cerberos_dal"); | ||||
| var authSettings = AuthHelper.GetAuthSettings(builder, "thalos_dal"); | ||||
| 
 | ||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); | ||||
| 
 | ||||
| @@ -70,7 +70,7 @@ builder.Services.AddRateLimiter(_ => _ | ||||
| builder.Services.AddResponseCaching(); | ||||
| builder.Services.AddControllers(); | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwagger(builder.Configuration, "Core.Cerberos.DAL.API.xml", authSettings); | ||||
| builder.Services.AddSwagger(builder.Configuration, "Core.Thalos.DAL.API.xml", authSettings); | ||||
| builder.Services.AddVersioning(builder.Configuration); | ||||
| builder.Services.AddLogging(); | ||||
| builder.Services.AddProblemDetails(); | ||||
| @@ -5,7 +5,7 @@ | ||||
|     "KeyVault": "" //KeyVault Uri | ||||
|   }, | ||||
|   "MongoDb": { | ||||
|     "DatabaseName": "Cerberos" | ||||
|     "DatabaseName": "Thalos" | ||||
|   }, | ||||
|   "CacheSettings": { | ||||
|     "DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes | ||||
| @@ -22,7 +22,7 @@ | ||||
|     "CallbackPath": "", // Path for redirect after authentication | ||||
|     "Scopes": "" // Access scopes for user permissions | ||||
|   }, | ||||
|   "HeathCerberosApp": { | ||||
|   "ThalosApp": { | ||||
|     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) | ||||
|     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) | ||||
|     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) | ||||
| @@ -1,14 +1,14 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="ModuleMapper.cs"> | ||||
| //    HEATH | ||||
| //    AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using MongoDB.Bson; | ||||
| using System.Security.Claims; | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles mappings between | ||||
| @@ -1,14 +1,14 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="PermissionMapper.cs"> | ||||
| //    HEATH | ||||
| //    AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using MongoDB.Bson; | ||||
| using System.Security.Claims; | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles mappings between | ||||
| @@ -1,15 +1,15 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="RoleMapper.cs"> | ||||
| //    HEATH | ||||
| //    AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| 
 | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using MongoDB.Bson; | ||||
| using System.Security.Claims; | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles mappings between | ||||
| @@ -1,15 +1,15 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="UserMapper.cs"> | ||||
| //    HEATH | ||||
| //    AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using MongoDB.Bson; | ||||
| using System.Security.Claims; | ||||
| 
 | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles mappings between | ||||
| @@ -4,12 +4,12 @@ | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| 
 | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Bson.Serialization.Attributes; | ||||
| using System.Text.Json.Serialization; | ||||
| 
 | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Data transfer object (DTO) for adding modules. | ||||
| @@ -4,12 +4,12 @@ | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| 
 | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Bson.Serialization.Attributes; | ||||
| using System.Text.Json.Serialization; | ||||
| 
 | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Data transfer object (DTO) for adding permissions. | ||||
| @@ -4,12 +4,12 @@ | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| 
 | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Bson.Serialization.Attributes; | ||||
| using System.Text.Json.Serialization; | ||||
| 
 | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Data transfer object (DTO) for adding a role. | ||||
| @@ -8,7 +8,7 @@ using MongoDB.Bson; | ||||
| using MongoDB.Bson.Serialization.Attributes; | ||||
| using System.Text.Json.Serialization; | ||||
| 
 | ||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | ||||
| namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Data transfer object (DTO) for adding a user. | ||||
| @@ -7,7 +7,7 @@ | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Cerberos.Building.Blocks" Version="0.0.3" /> | ||||
|     <PackageReference Include="Thalos.Building.Blocks" Version="0.0.2" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
| @@ -1,4 +1,4 @@ | ||||
| using Core.Cerberos.Infraestructure.Caching.Configs; | ||||
| using Core.Thalos.Infraestructure.Caching.Configs; | ||||
| 
 | ||||
| namespace LSA.Core.Dapper.Service.Caching | ||||
| { | ||||
| @@ -1,5 +1,5 @@ | ||||
| using Azure.Identity; | ||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; | ||||
| using Core.Thalos.Infraestructure.Caching.Contracts; | ||||
| using Microsoft.Extensions.Logging; | ||||
| using StackExchange.Redis; | ||||
| using System.Text.Json; | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace Core.Cerberos.Infraestructure.Caching.Configs | ||||
| namespace Core.Thalos.Infraestructure.Caching.Configs | ||||
| { | ||||
|     public class CacheSettings | ||||
|     { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace Core.Cerberos.Infraestructure.Caching.Contracts | ||||
| namespace Core.Thalos.Infraestructure.Caching.Contracts | ||||
| { | ||||
|     public interface ICacheService | ||||
|     { | ||||
| @@ -1,6 +1,6 @@ | ||||
| using Microsoft.Extensions.Configuration; | ||||
| 
 | ||||
| namespace Core.Cerberos.Infraestructure.Contexts.Mongo | ||||
| namespace Core.Thalos.Infraestructure.Contexts.Mongo | ||||
| { | ||||
|     public class ConnectionStringProvider(IConfiguration configuration) : IConnectionStringProvider | ||||
|     { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace Core.Cerberos.Infraestructure.Contexts.Mongo; | ||||
| namespace Core.Thalos.Infraestructure.Contexts.Mongo; | ||||
| 
 | ||||
| public interface IMongoConnSettings | ||||
| { | ||||
| @@ -1,4 +1,4 @@ | ||||
| namespace Core.Cerberos.Infraestructure.PerformanceCacheService | ||||
| namespace Core.Thalos.Infraestructure.PerformanceCacheService | ||||
| { | ||||
|     [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] | ||||
|     public class CacheAttribute : Attribute | ||||
| @@ -3,11 +3,11 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Contracts | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     public interface IModuleService | ||||
|     { | ||||
| @@ -3,11 +3,11 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Contracts | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     public interface IPermissionService | ||||
|     { | ||||
| @@ -3,11 +3,11 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Contracts | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     public interface IRoleService | ||||
|     { | ||||
| @@ -3,14 +3,13 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Blueprint.Storage.Adapters; | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Contracts | ||||
| namespace Core.Thalos.Provider.Contracts | ||||
| { | ||||
|     public interface IUserService | ||||
|     public interface IUserProvider | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// Creates a new User. | ||||
| @@ -18,7 +17,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="entity">The User to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter> CreateUserService(UserRequest newUser); | ||||
|         ValueTask<UserAdapter> CreateUser(UserRequest newUser, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Gets an User by identifier. | ||||
| @@ -26,7 +25,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter> GetUserByIdService(string id); | ||||
|         ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken); | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -34,7 +33,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<IEnumerable<UserAdapter>> GetAllUsersService(); | ||||
|         ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Gets an User by email. | ||||
| @@ -42,7 +41,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="email">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter> GetUserByEmailService(string? email); | ||||
|         ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Validates if a users exists by email. | ||||
| @@ -50,7 +49,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="eamil">The User email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter> ValidateUserExistenceService(string? email); | ||||
|         ValueTask<UserAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Changes the status of the user. | ||||
| @@ -59,7 +58,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="newStatus">The new status of the user.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter> ChangeUserStatusService(string id, StatusEnum newStatus); | ||||
|         ValueTask<UserAdapter> ChangeUserStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Updates a User by id. | ||||
| @@ -68,7 +67,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="id">The User identifier.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter> UpdateUserService(UserAdapter entity, string id); | ||||
|         ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
| @@ -76,7 +75,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="email">The User's email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter?> LogInUserService(string email); | ||||
|         ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Logs out the user's session. | ||||
| @@ -84,7 +83,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <param name="email">The User's email.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         Task<UserAdapter> LogOutUserSessionService(string email); | ||||
|         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Adds a company to the user's list of companies. | ||||
| @@ -92,7 +91,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <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> | ||||
|         Task<UserAdapter> AddCompanyToUserService(string userId, string companyId); | ||||
|         ValueTask<UserAdapter> AddCompanyToUser(string userId, string companyId, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Removes a company from the user's list of companies. | ||||
| @@ -100,7 +99,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <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> | ||||
|         Task<UserAdapter> RemoveCompanyFromUserService(string userId, string companyId); | ||||
|         ValueTask<UserAdapter> RemoveCompanyFromUser(string userId, string companyId, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Adds a project to the user's list of projects. | ||||
| @@ -108,7 +107,7 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <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> | ||||
|         Task<UserAdapter> AddProjectToUserService(string userId, string projectId); | ||||
|         ValueTask<UserAdapter> AddProjectToUser(string userId, string projectId, CancellationToken cancellationToken); | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
| @@ -117,13 +116,21 @@ namespace Core.Cerberos.Provider.Contracts | ||||
|         /// <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> | ||||
|         Task<UserAdapter> RemoveProjectFromUserService(string userId, string projectId); | ||||
|         ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Gets the token adapter 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> | ||||
|         Task<TokenAdapter?> GetTokenAdapter(string email); | ||||
|         ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Delete an User by 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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										25
									
								
								Core.Thalos.Provider/Core.Thalos.Provider.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								Core.Thalos.Provider/Core.Thalos.Provider.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net8.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <Compile Remove="Providers\Onboarding\UserService - Copy.cs" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Blueprint.Mongo" Version="0.0.3" /> | ||||
|     <PackageReference Include="Blueprint.Redis" Version="0.0.1" /> | ||||
|     <PackageReference Include="BuildingBlocks.Library" Version="0.0.1" /> | ||||
|     <PackageReference Include="Mapster" Version="7.4.2-pre02" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> | ||||
|     <ProjectReference Include="..\Core.Thalos.Infraestructure\Core.Thalos.Infrastructure.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
| @@ -1,6 +1,6 @@ | ||||
| using MongoDB.Driver; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Providers | ||||
| namespace Core.Thalos.Provider.Providers | ||||
| { | ||||
|     public class BaseProvider | ||||
|     { | ||||
| @@ -1,9 +1,9 @@ | ||||
| using Azure.Core; | ||||
| using Azure.Identity; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using MongoDB.Driver.Authentication.Oidc; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Providers | ||||
| namespace Core.Thalos.Provider.Providers | ||||
| { | ||||
|     public class HeathOidcCallback : IOidcCallback | ||||
|     { | ||||
| @@ -7,7 +7,7 @@ | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using System.Security.Claims; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Providers | ||||
| namespace Core.Thalos.Provider.Providers | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Provides helper methods for common operations. | ||||
| @@ -3,14 +3,14 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Cerberos.Infraestructure.Caching.Configs; | ||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Mappers; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Infraestructure.Caching.Configs; | ||||
| using Core.Thalos.Infraestructure.Caching.Contracts; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using LSA.Core.Dapper.Service.Caching; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.Extensions.Logging; | ||||
| @@ -18,7 +18,7 @@ using Microsoft.Extensions.Options; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Driver; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Providers.Onboarding | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="ModuleAdapter"/>. | ||||
| @@ -180,7 +180,7 @@ namespace Core.Cerberos.Provider.Providers.Onboarding | ||||
|                     .Eq("_id", ObjectId.Parse(id)); | ||||
| 
 | ||||
|                 var update = Builders<ModuleAdapter>.Update | ||||
|                             .Set(v => v.Status, newStatus) | ||||
|                             //.Set(v => v.Status, newStatus) | ||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) | ||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); | ||||
| 
 | ||||
| @@ -3,14 +3,14 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Cerberos.Infraestructure.Caching.Configs; | ||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Mappers; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Infraestructure.Caching.Configs; | ||||
| using Core.Thalos.Infraestructure.Caching.Contracts; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using LSA.Core.Dapper.Service.Caching; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.Extensions.Logging; | ||||
| @@ -18,7 +18,7 @@ using Microsoft.Extensions.Options; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Driver; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Providers.Onboarding | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="PermissionAdapter"/>. | ||||
| @@ -175,7 +175,7 @@ namespace Core.Cerberos.Provider.Providers.Onboarding | ||||
|                     .Eq("_id", ObjectId.Parse(id)); | ||||
| 
 | ||||
|                 var update = Builders<PermissionAdapter>.Update | ||||
|                             .Set(v => v.Status, newStatus) | ||||
|                             //.Set(v => v.Status, newStatus) | ||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) | ||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); | ||||
| 
 | ||||
| @@ -3,14 +3,14 @@ | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
| using Core.Cerberos.Adapters; | ||||
| using Core.Cerberos.Adapters.Common.Constants; | ||||
| using Core.Cerberos.Adapters.Common.Enums; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Mappers; | ||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Cerberos.Infraestructure.Caching.Configs; | ||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Constants; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Mappers; | ||||
| using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||
| using Core.Thalos.Infraestructure.Caching.Configs; | ||||
| using Core.Thalos.Infraestructure.Caching.Contracts; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using LSA.Core.Dapper.Service.Caching; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.Extensions.Logging; | ||||
| @@ -18,7 +18,7 @@ using Microsoft.Extensions.Options; | ||||
| using MongoDB.Bson; | ||||
| using MongoDB.Driver; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider.Providers.Onboarding | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="RoleAdapter"/>. | ||||
| @@ -134,7 +134,7 @@ namespace Core.Cerberos.Provider.Providers.Onboarding | ||||
|                     .Eq("_id", ObjectId.Parse(id)); | ||||
| 
 | ||||
|                 var update = Builders<RoleAdapter>.Update | ||||
|                             .Set(v => v.Status, newStatus) | ||||
|                             //.Set(v => v.Status, newStatus) | ||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) | ||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); | ||||
| 
 | ||||
							
								
								
									
										471
									
								
								Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										471
									
								
								Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,471 @@ | ||||
| // *********************************************************************** | ||||
| // <copyright file="UserService.cs"> | ||||
| //     AgileWebs | ||||
| // </copyright> | ||||
| // *********************************************************************** | ||||
|  | ||||
| using Core.Thalos.Adapters; | ||||
| using Core.Thalos.Adapters.Common.Enums; | ||||
| using Core.Blueprint.Mongo; | ||||
| using Core.Blueprint.Redis; | ||||
| using Core.Blueprint.Redis.Helpers; | ||||
| using Mapster; | ||||
| using Microsoft.Extensions.Options; | ||||
| using MongoDB.Driver; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using MongoDB.Bson; | ||||
| using System.Text.RegularExpressions; | ||||
| using MongoDB.Bson.Serialization; | ||||
|  | ||||
| namespace Core.Thalos.Provider.Providers.Onboarding | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Handles all services and business rules related to <see cref="UserAdapter"/>. | ||||
|     /// </summary> | ||||
|     public class UserProvider : IUserProvider | ||||
|     { | ||||
|         private readonly CollectionRepository<UserAdapter> repository; | ||||
|         private readonly CacheSettings cacheSettings; | ||||
|         private readonly IRedisCacheProvider cacheProvider; | ||||
|  | ||||
|         public UserProvider(CollectionRepository<UserAdapter> repository, | ||||
|         IRedisCacheProvider cacheProvider, IOptions<CacheSettings> cacheSettings) | ||||
|         { | ||||
|             this.repository = repository; | ||||
|             this.repository.CollectionInitialization(); | ||||
|             this.cacheSettings = cacheSettings.Value; | ||||
|             this.cacheProvider = cacheProvider; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Creates a new User. | ||||
|         /// </summary> | ||||
|         /// <param name="newUser">The User to be created.</param> | ||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async ValueTask<UserAdapter> CreateUser(Core.Thalos.Domain.Contexts.Onboarding.Request.UserRequest newUser, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var userCollection = newUser.Adapt<UserAdapter>(); | ||||
|  | ||||
|             await repository.InsertOneAsync(userCollection); | ||||
|  | ||||
|             return userCollection; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an User by identifier. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User 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) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserById", _id); | ||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||
|  | ||||
|             if (cachedData is not null) { return cachedData; } | ||||
|  | ||||
|             var user = await repository.FindByIdAsync(_id); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, user); | ||||
|  | ||||
|             return user; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets all the users. | ||||
|         /// </summary> | ||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing | ||||
|         /// the asynchronous execution of the service.</returns> | ||||
|         public async ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllUsers"); | ||||
|             var cachedData = await cacheProvider.GetAsync<IEnumerable<UserAdapter>>(cacheKey) ?? []; | ||||
|  | ||||
|             if (cachedData.Any()) return cachedData; | ||||
|  | ||||
|             var users = await repository.AsQueryable(); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, users); | ||||
|  | ||||
|             return users; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets an 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> | ||||
|         public async ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||
|  | ||||
|             if (cachedData is not null) { return cachedData; } | ||||
|  | ||||
|             var user = await repository.FindOneAsync( | ||||
|                 u => u.Email == email &&  | ||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, user); | ||||
|  | ||||
|             return user; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Validates if a users exists by email.. | ||||
|         /// </summary> | ||||
|         /// <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> ValidateUserExistence(string? email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetUserByEmail", email); | ||||
|             var cachedData = await cacheProvider.GetAsync<UserAdapter>(cacheKey); | ||||
|  | ||||
|             if (cachedData is not null) { return cachedData; } | ||||
|  | ||||
|             var user = await repository.FindOneAsync( | ||||
|                 u => u.Email == email && | ||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||
|  | ||||
|             await cacheProvider.SetAsync(cacheKey, user); | ||||
|  | ||||
|             return user; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Changes the status of the 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> | ||||
|         public async ValueTask<UserAdapter> ChangeUserStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var entity = await repository.FindByIdAsync(id); | ||||
|             entity.Status = newStatus; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Updates a User by id. | ||||
|         /// </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> | ||||
|         public async ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken) | ||||
|         { | ||||
|             await repository.ReplaceOneAsync(entity); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs in the user. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User 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) | ||||
|         { | ||||
|             var user = await repository.FindOneAsync( | ||||
|                 u => u.Email == email && | ||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||
|  | ||||
|             user.LastLogIn = DateTime.UtcNow; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(user); | ||||
|  | ||||
|             return user; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Logs out the user's session. | ||||
|         /// </summary> | ||||
|         /// <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?> LogOutUserSession(string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var user = await repository.FindOneAsync( | ||||
|                 u => u.Email == email && | ||||
|                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||
|  | ||||
|             user.LastLogOut = DateTime.UtcNow; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(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.Companies = 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.Companies = updatedProjects; | ||||
|  | ||||
|             await repository.ReplaceOneAsync(user); | ||||
|  | ||||
|             return user; | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Gets the token adapter 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> | ||||
|         public async ValueTask<TokenAdapter?> GetToken(string email, CancellationToken cancellationToken) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var pipeline = new[] | ||||
|                 { | ||||
|                     new BsonDocument("$match", new BsonDocument | ||||
|                     { | ||||
|                         { "email", new BsonDocument | ||||
|                             { | ||||
|                                 { "$regex", $"^{Regex.Escape(email)}$" }, | ||||
|                                 { "$options", "i" } | ||||
|                             } | ||||
|                         }, | ||||
|                         { "status", Core.Blueprint.Mongo.StatusEnum.Active.ToString() } | ||||
|                     }), | ||||
|  | ||||
|                     new BsonDocument("$lookup", new BsonDocument | ||||
|                     { | ||||
|                         { "from", "Roles" }, | ||||
|                         { "localField", "roleId" }, | ||||
|                         { "foreignField", "_id" }, | ||||
|                         { "as", "role" } | ||||
|                     }), | ||||
|  | ||||
|                     new BsonDocument("$unwind", "$role"), | ||||
|                     new BsonDocument("$match", new BsonDocument("role.status", Core.Blueprint.Mongo.StatusEnum.Active.ToString())), | ||||
|  | ||||
|                     new BsonDocument("$addFields", new BsonDocument | ||||
|                     { | ||||
|                         { "role.permissions", new BsonDocument("$map", new BsonDocument | ||||
|                             { | ||||
|                                 { "input", "$role.permissions" }, | ||||
|                                 { "as", "perm" }, | ||||
|                                 { "in", new BsonDocument("$toObjectId", "$$perm") } | ||||
|                             }) | ||||
|                         }, | ||||
|                         { "role.modules", new BsonDocument("$map", new BsonDocument | ||||
|                             { | ||||
|                                 { "input", "$role.modules" }, | ||||
|                                 { "as", "mod" }, | ||||
|                                 { "in", new BsonDocument("$toObjectId", "$$mod") } | ||||
|                             }) | ||||
|                         } | ||||
|                     }), | ||||
|  | ||||
|                     new BsonDocument("$lookup", new BsonDocument | ||||
|                     { | ||||
|                         { "from", "Permissions" }, | ||||
|                         { "localField", "role.permissions" }, | ||||
|                         { "foreignField", "_id" }, | ||||
|                         { "as", "permissions" } | ||||
|                     }), | ||||
|                     new BsonDocument("$lookup", new BsonDocument | ||||
|                     { | ||||
|                         { "from", "Modules" }, | ||||
|                         { "localField", "role.modules" }, | ||||
|                         { "foreignField", "_id" }, | ||||
|                         { "as", "modules" } | ||||
|                     }), | ||||
|                     new BsonDocument("$project", new BsonDocument | ||||
|                     { | ||||
|                         { "_id", 1 }, | ||||
|                         { "guid", 1 }, | ||||
|                         { "email", 1 }, | ||||
|                         { "name", 1 }, | ||||
|                         { "middleName", 1 }, | ||||
|                         { "lastName", 1 }, | ||||
|                         { "displayName", 1 }, | ||||
|                         { "roleId", 1 }, | ||||
|                         { "companies", 1 }, | ||||
|                         { "projects", 1 }, | ||||
|                         { "lastLogIn", 1 }, | ||||
|                         { "lastLogOut", 1 }, | ||||
|                         { "createdBy", 1 }, | ||||
|                         { "updatedBy", 1 }, | ||||
|                         { "status", 1 }, | ||||
|                         { "createdAt", 1 }, | ||||
|                         { "updatedAt", 1 }, | ||||
|                         { "role._id", 1 }, | ||||
|                         { "role.name", 1 }, | ||||
|                         { "role.description", 1 }, | ||||
|                         { "role.applications", 1 }, | ||||
|                         { "role.permissions", 1 }, | ||||
|                         { "role.modules", 1 }, | ||||
|                         { "role.status", 1 }, | ||||
|                         { "role.createdAt", 1 }, | ||||
|                         { "role.updatedAt", 1 }, | ||||
|                         { "role.createdBy", 1 }, | ||||
|                         { "role.updatedBy", 1 }, | ||||
|                         { "permissions", 1 }, | ||||
|                         { "modules", 1 } | ||||
|                     }) | ||||
|                 }; | ||||
|  | ||||
|                 var result = await repository.FindOnePipelineAsync<BsonDocument>(pipeline); | ||||
|  | ||||
|                 if (result is null) return null; | ||||
|  | ||||
|                 var tokenAdapter = new TokenAdapter | ||||
|                 { | ||||
|                     User = new UserAdapter | ||||
|                     { | ||||
|                         Id = result["_id"]?.ToString() ?? "", | ||||
|                         Guid = result["guid"].AsString, | ||||
|                         Email = result["email"].AsString, | ||||
|                         Name = result["name"].AsString, | ||||
|                         MiddleName = result["middleName"].AsString, | ||||
|                         LastName = result["lastName"].AsString, | ||||
|                         DisplayName = result["displayName"].AsString, | ||||
|                         RoleId = result["roleId"]?.ToString() ?? "", | ||||
|                         Companies = result["companies"].AsBsonArray | ||||
|                             .Select(c => c.AsString) | ||||
|                             .ToArray(), | ||||
|                         Projects = result["projects"].AsBsonArray | ||||
|                             .Select(c => c.AsString) | ||||
|                             .ToArray(), | ||||
|                         LastLogIn = result["lastLogIn"].ToUniversalTime(), | ||||
|                         LastLogOut = result["lastLogOut"].ToUniversalTime(), | ||||
|                         CreatedAt = result["createdAt"].ToUniversalTime(), | ||||
|                         CreatedBy = result["createdBy"].AsString, | ||||
|                         UpdatedAt = result["updatedAt"].ToUniversalTime(), | ||||
|                         UpdatedBy = result["updatedBy"].AsString, | ||||
|                         Status = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString), | ||||
|                     }, | ||||
|                     Role = new RoleAdapter | ||||
|                     { | ||||
|                         Id = result["role"]["_id"]?.ToString() ?? "", | ||||
|                         Name = result["role"]["name"].AsString, | ||||
|                         Description = result["role"]["description"].AsString, | ||||
|                         Applications = result["role"]["applications"].AsBsonArray | ||||
|                             .Select(c => (ApplicationsEnum)c.AsInt32) | ||||
|                             .ToArray(), | ||||
|                         Modules = result["role"]["modules"].AsBsonArray | ||||
|                             .Select(c => c.ToString() ?? "") | ||||
|                             .ToArray(), | ||||
|                         Permissions = result["role"]["permissions"].AsBsonArray | ||||
|                             .Select(c => c.ToString() ?? "") | ||||
|                             .ToArray(), | ||||
|                         Status = (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["role"]["status"].AsString), | ||||
|                         CreatedAt = result["role"]["createdAt"].ToUniversalTime(), | ||||
|                         UpdatedAt = result["role"]["updatedAt"].ToUniversalTime(), | ||||
|                         CreatedBy = result["role"]["createdBy"].AsString, | ||||
|                         UpdatedBy = result["role"]["updatedBy"].AsString | ||||
|                     }, | ||||
|                     Permissions = result["permissions"].AsBsonArray | ||||
|                         .Select(permission => BsonSerializer.Deserialize<PermissionAdapter>(permission.AsBsonDocument)) | ||||
|                         .Where(permission => permission.Status == Core.Blueprint.Mongo.StatusEnum.Active) | ||||
|                         .ToList() | ||||
|                 }; | ||||
|  | ||||
|                 return tokenAdapter; | ||||
|  | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 throw new Exception(ex.Message, ex); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes an User by id. | ||||
|         /// </summary> | ||||
|         /// <param name="id">The User 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) | ||||
|         { | ||||
|             var entity = await repository.DeleteOneAsync(doc => doc.Id == _id); | ||||
|  | ||||
|             return entity; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,9 +1,8 @@ | ||||
| using Core.Blueprint.Storage.Configuration; | ||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; | ||||
| using Core.Cerberos.Infraestructure.Contexts.Mongo; | ||||
| using Core.Cerberos.Provider.Contracts; | ||||
| using Core.Cerberos.Provider.Providers; | ||||
| using Core.Cerberos.Provider.Providers.Onboarding; | ||||
| using Core.Thalos.Infraestructure.Caching.Contracts; | ||||
| using Core.Thalos.Infraestructure.Contexts.Mongo; | ||||
| using Core.Thalos.Provider.Contracts; | ||||
| using Core.Thalos.Provider.Providers; | ||||
| using Core.Thalos.Provider.Providers.Onboarding; | ||||
| using LSA.Core.Dapper.Service.Caching; | ||||
| using Microsoft.Extensions.Configuration; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| @@ -11,7 +10,7 @@ using Microsoft.Extensions.Logging; | ||||
| using Microsoft.Extensions.Options; | ||||
| using MongoDB.Driver; | ||||
| 
 | ||||
| namespace Core.Cerberos.Provider | ||||
| namespace Core.Thalos.Provider | ||||
| { | ||||
|     public static class ServiceCollectionExtensions | ||||
|     { | ||||
| @@ -55,7 +54,6 @@ namespace Core.Cerberos.Provider | ||||
|             services.AddDALConfigurationLayer(); | ||||
|             services.AddLogs(); | ||||
|             services.AddRedisCacheService(configuration); | ||||
|             services.AddBlobStorage(configuration); | ||||
| 
 | ||||
|             return services; | ||||
|         } | ||||
| @@ -65,7 +63,7 @@ namespace Core.Cerberos.Provider | ||||
|         { | ||||
|             services.AddHttpContextAccessor(); | ||||
| 
 | ||||
|             services.AddScoped<IUserService, UserService>(); | ||||
|             services.AddScoped<IUserProvider, UserProvider>(); | ||||
|             services.AddScoped<IRoleService, RoleService>(); | ||||
|             services.AddScoped<IPermissionService, PermissionService>(); | ||||
|             services.AddScoped<IPermissionService, PermissionService>(); | ||||
		Reference in New Issue
	
	Block a user