Compare commits
	
		
			17 Commits
		
	
	
		
			main
			...
			feature/ad
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 99964d14b8 | ||
| 1ae0b600ae | |||
|   | 6cb0aea1a0 | ||
|   | 8207048c25 | ||
|   | f5b5f7d0f0 | ||
| ffc1afa8c9 | |||
|   | 1c38008e97 | ||
| c18c85959c | |||
|   | c3e1cfbf8d | ||
| 41da6d76f8 | |||
|   | a36fd0e480 | ||
|   | 24efe5612c | ||
|   | f05d1a4b7e | ||
|   | c2067700bc | ||
|   | d12d26bc82 | ||
|   | ae7ee3a93e | ||
|   | 4c8c115ff5 | 
							
								
								
									
										355
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										355
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,355 @@ | |||||||
|  | ## Ignore Visual Studio temporary files, build results, and | ||||||
|  | ## files generated by popular Visual Studio add-ons. | ||||||
|  | ## | ||||||
|  | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore | ||||||
|  |  | ||||||
|  | # User-specific files | ||||||
|  | *.rsuser | ||||||
|  | *.suo | ||||||
|  | *.user | ||||||
|  | *.userosscache | ||||||
|  | *.sln.docstates | ||||||
|  |  | ||||||
|  | # User-specific files (MonoDevelop/Xamarin Studio) | ||||||
|  | *.userprefs | ||||||
|  |  | ||||||
|  | # Mono auto generated files | ||||||
|  | mono_crash.* | ||||||
|  |  | ||||||
|  | # Build results | ||||||
|  | [Dd]ebug/ | ||||||
|  | [Dd]ebugPublic/ | ||||||
|  | [Rr]elease/ | ||||||
|  | [Rr]eleases/ | ||||||
|  | x64/ | ||||||
|  | x86/ | ||||||
|  | [Ww][Ii][Nn]32/ | ||||||
|  | [Aa][Rr][Mm]/ | ||||||
|  | [Aa][Rr][Mm]64/ | ||||||
|  | bld/ | ||||||
|  | [Bb]in/ | ||||||
|  | [Oo]bj/ | ||||||
|  | [Oo]ut/ | ||||||
|  | [Ll]og/ | ||||||
|  | [Ll]ogs/ | ||||||
|  |  | ||||||
|  | # Visual Studio 2015/2017 cache/options directory | ||||||
|  | .vs/ | ||||||
|  | # Uncomment if you have tasks that create the project's static files in wwwroot | ||||||
|  | #wwwroot/ | ||||||
|  |  | ||||||
|  | # Visual Studio 2017 auto generated files | ||||||
|  | Generated\ Files/ | ||||||
|  |  | ||||||
|  | # MSTest test Results | ||||||
|  | [Tt]est[Rr]esult*/ | ||||||
|  | [Bb]uild[Ll]og.* | ||||||
|  |  | ||||||
|  | # NUnit | ||||||
|  | *.VisualState.xml | ||||||
|  | TestResult.xml | ||||||
|  | nunit-*.xml | ||||||
|  |  | ||||||
|  | # Build Results of an ATL Project | ||||||
|  | [Dd]ebugPS/ | ||||||
|  | [Rr]eleasePS/ | ||||||
|  | dlldata.c | ||||||
|  |  | ||||||
|  | # Benchmark Results | ||||||
|  | BenchmarkDotNet.Artifacts/ | ||||||
|  |  | ||||||
|  | # .NET Core | ||||||
|  | project.lock.json | ||||||
|  | project.fragment.lock.json | ||||||
|  | artifacts/ | ||||||
|  |  | ||||||
|  | # ASP.NET Scaffolding | ||||||
|  | ScaffoldingReadMe.txt | ||||||
|  |  | ||||||
|  | # StyleCop | ||||||
|  | StyleCopReport.xml | ||||||
|  |  | ||||||
|  | # Files built by Visual Studio | ||||||
|  | *_i.c | ||||||
|  | *_p.c | ||||||
|  | *_h.h | ||||||
|  | *.ilk | ||||||
|  | *.meta | ||||||
|  | *.obj | ||||||
|  | *.iobj | ||||||
|  | *.pch | ||||||
|  | *.pdb | ||||||
|  | *.ipdb | ||||||
|  | *.pgc | ||||||
|  | *.pgd | ||||||
|  | *.rsp | ||||||
|  | *.sbr | ||||||
|  | *.tlb | ||||||
|  | *.tli | ||||||
|  | *.tlh | ||||||
|  | *.tmp | ||||||
|  | *.tmp_proj | ||||||
|  | *_wpftmp.csproj | ||||||
|  | *.log | ||||||
|  | *.vspscc | ||||||
|  | *.vssscc | ||||||
|  | .builds | ||||||
|  | *.pidb | ||||||
|  | *.svclog | ||||||
|  | *.scc | ||||||
|  |  | ||||||
|  | # Chutzpah Test files | ||||||
|  | _Chutzpah* | ||||||
|  |  | ||||||
|  | # Visual C++ cache files | ||||||
|  | ipch/ | ||||||
|  | *.aps | ||||||
|  | *.ncb | ||||||
|  | *.opendb | ||||||
|  | *.opensdf | ||||||
|  | *.sdf | ||||||
|  | *.cachefile | ||||||
|  | *.VC.db | ||||||
|  | *.VC.VC.opendb | ||||||
|  |  | ||||||
|  | # Visual Studio profiler | ||||||
|  | *.psess | ||||||
|  | *.vsp | ||||||
|  | *.vspx | ||||||
|  | *.sap | ||||||
|  |  | ||||||
|  | # Visual Studio Trace Files | ||||||
|  | *.e2e | ||||||
|  |  | ||||||
|  | # TFS 2012 Local Workspace | ||||||
|  | $tf/ | ||||||
|  |  | ||||||
|  | # Guidance Automation Toolkit | ||||||
|  | *.gpState | ||||||
|  |  | ||||||
|  | # ReSharper is a .NET coding add-in | ||||||
|  | _ReSharper*/ | ||||||
|  | *.[Rr]e[Ss]harper | ||||||
|  | *.DotSettings.user | ||||||
|  |  | ||||||
|  | # TeamCity is a build add-in | ||||||
|  | _TeamCity* | ||||||
|  |  | ||||||
|  | # DotCover is a Code Coverage Tool | ||||||
|  | *.dotCover | ||||||
|  |  | ||||||
|  | # AxoCover is a Code Coverage Tool | ||||||
|  | .axoCover/* | ||||||
|  | !.axoCover/settings.json | ||||||
|  |  | ||||||
|  | # Coverlet is a free, cross platform Code Coverage Tool | ||||||
|  | coverage*.json | ||||||
|  | coverage*.xml | ||||||
|  | coverage*.info | ||||||
|  |  | ||||||
|  | # Visual Studio code coverage results | ||||||
|  | *.coverage | ||||||
|  | *.coveragexml | ||||||
|  |  | ||||||
|  | # NCrunch | ||||||
|  | _NCrunch_* | ||||||
|  | .*crunch*.local.xml | ||||||
|  | nCrunchTemp_* | ||||||
|  |  | ||||||
|  | # MightyMoose | ||||||
|  | *.mm.* | ||||||
|  | AutoTest.Net/ | ||||||
|  |  | ||||||
|  | # Web workbench (sass) | ||||||
|  | .sass-cache/ | ||||||
|  |  | ||||||
|  | # Installshield output folder | ||||||
|  | [Ee]xpress/ | ||||||
|  |  | ||||||
|  | # DocProject is a documentation generator add-in | ||||||
|  | DocProject/buildhelp/ | ||||||
|  | DocProject/Help/*.HxT | ||||||
|  | DocProject/Help/*.HxC | ||||||
|  | DocProject/Help/*.hhc | ||||||
|  | DocProject/Help/*.hhk | ||||||
|  | DocProject/Help/*.hhp | ||||||
|  | DocProject/Help/Html2 | ||||||
|  | DocProject/Help/html | ||||||
|  |  | ||||||
|  | # Click-Once directory | ||||||
|  | publish/ | ||||||
|  |  | ||||||
|  | # Publish Web Output | ||||||
|  | *.[Pp]ublish.xml | ||||||
|  | *.azurePubxml | ||||||
|  | # Note: Comment the next line if you want to checkin your web deploy settings, | ||||||
|  | # but database connection strings (with potential passwords) will be unencrypted | ||||||
|  | *.pubxml | ||||||
|  | *.publishproj | ||||||
|  |  | ||||||
|  | # Microsoft Azure Web App publish settings. Comment the next line if you want to | ||||||
|  | # checkin your Azure Web App publish settings, but sensitive information contained | ||||||
|  | # in these scripts will be unencrypted | ||||||
|  | PublishScripts/ | ||||||
|  |  | ||||||
|  | # NuGet Packages | ||||||
|  | *.nupkg | ||||||
|  | # NuGet Symbol Packages | ||||||
|  | *.snupkg | ||||||
|  | # The packages folder can be ignored because of Package Restore | ||||||
|  | **/[Pp]ackages/* | ||||||
|  | # except build/, which is used as an MSBuild target. | ||||||
|  | !**/[Pp]ackages/build/ | ||||||
|  | # Uncomment if necessary however generally it will be regenerated when needed | ||||||
|  | #!**/[Pp]ackages/repositories.config | ||||||
|  | # NuGet v3's project.json files produces more ignorable files | ||||||
|  | *.nuget.props | ||||||
|  | *.nuget.targets | ||||||
|  |  | ||||||
|  | # Microsoft Azure Build Output | ||||||
|  | csx/ | ||||||
|  | *.build.csdef | ||||||
|  |  | ||||||
|  | # Microsoft Azure Emulator | ||||||
|  | ecf/ | ||||||
|  | rcf/ | ||||||
|  |  | ||||||
|  | # Windows Store app package directories and files | ||||||
|  | AppPackages/ | ||||||
|  | BundleArtifacts/ | ||||||
|  | Package.StoreAssociation.xml | ||||||
|  | _pkginfo.txt | ||||||
|  | *.appx | ||||||
|  | *.appxbundle | ||||||
|  | *.appxupload | ||||||
|  |  | ||||||
|  | # Visual Studio cache files | ||||||
|  | # files ending in .cache can be ignored | ||||||
|  | *.[Cc]ache | ||||||
|  | # but keep track of directories ending in .cache | ||||||
|  | !?*.[Cc]ache/ | ||||||
|  |  | ||||||
|  | # Others | ||||||
|  | ClientBin/ | ||||||
|  | ~$* | ||||||
|  | *~ | ||||||
|  | *.dbmdl | ||||||
|  | *.dbproj.schemaview | ||||||
|  | *.jfm | ||||||
|  | *.pfx | ||||||
|  | *.publishsettings | ||||||
|  | orleans.codegen.cs | ||||||
|  |  | ||||||
|  | # Including strong name files can present a security risk | ||||||
|  | # (https://github.com/github/gitignore/pull/2483#issue-259490424) | ||||||
|  | #*.snk | ||||||
|  |  | ||||||
|  | # Since there are multiple workflows, uncomment next line to ignore bower_components | ||||||
|  | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) | ||||||
|  | #bower_components/ | ||||||
|  |  | ||||||
|  | # RIA/Silverlight projects | ||||||
|  | Generated_Code/ | ||||||
|  |  | ||||||
|  | # Backup & report files from converting an old project file | ||||||
|  | # to a newer Visual Studio version. Backup files are not needed, | ||||||
|  | # because we have git ;-) | ||||||
|  | _UpgradeReport_Files/ | ||||||
|  | Backup*/ | ||||||
|  | UpgradeLog*.XML | ||||||
|  | UpgradeLog*.htm | ||||||
|  | ServiceFabricBackup/ | ||||||
|  | *.rptproj.bak | ||||||
|  |  | ||||||
|  | # SQL Server files | ||||||
|  | *.mdf | ||||||
|  | *.ldf | ||||||
|  | *.ndf | ||||||
|  |  | ||||||
|  | # Business Intelligence projects | ||||||
|  | *.rdl.data | ||||||
|  | *.bim.layout | ||||||
|  | *.bim_*.settings | ||||||
|  | *.rptproj.rsuser | ||||||
|  | *- [Bb]ackup.rdl | ||||||
|  | *- [Bb]ackup ([0-9]).rdl | ||||||
|  | *- [Bb]ackup ([0-9][0-9]).rdl | ||||||
|  |  | ||||||
|  | # Microsoft Fakes | ||||||
|  | FakesAssemblies/ | ||||||
|  |  | ||||||
|  | # GhostDoc plugin setting file | ||||||
|  | *.GhostDoc.xml | ||||||
|  |  | ||||||
|  | # Node.js Tools for Visual Studio | ||||||
|  | .ntvs_analysis.dat | ||||||
|  | node_modules/ | ||||||
|  |  | ||||||
|  | # Visual Studio 6 build log | ||||||
|  | *.plg | ||||||
|  |  | ||||||
|  | # Visual Studio 6 workspace options file | ||||||
|  | *.opt | ||||||
|  |  | ||||||
|  | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) | ||||||
|  | *.vbw | ||||||
|  |  | ||||||
|  | # Visual Studio LightSwitch build output | ||||||
|  | **/*.HTMLClient/GeneratedArtifacts | ||||||
|  | **/*.DesktopClient/GeneratedArtifacts | ||||||
|  | **/*.DesktopClient/ModelManifest.xml | ||||||
|  | **/*.Server/GeneratedArtifacts | ||||||
|  | **/*.Server/ModelManifest.xml | ||||||
|  | _Pvt_Extensions | ||||||
|  |  | ||||||
|  | # Paket dependency manager | ||||||
|  | .paket/paket.exe | ||||||
|  | paket-files/ | ||||||
|  |  | ||||||
|  | # FAKE - F# Make | ||||||
|  | .fake/ | ||||||
|  |  | ||||||
|  | # CodeRush personal settings | ||||||
|  | .cr/personal | ||||||
|  |  | ||||||
|  | # Python Tools for Visual Studio (PTVS) | ||||||
|  | __pycache__/ | ||||||
|  | *.pyc | ||||||
|  |  | ||||||
|  | # Cake - Uncomment if you are using it | ||||||
|  | # tools/** | ||||||
|  | # !tools/packages.config | ||||||
|  |  | ||||||
|  | # Tabs Studio | ||||||
|  | *.tss | ||||||
|  |  | ||||||
|  | # Telerik's JustMock configuration file | ||||||
|  | *.jmconfig | ||||||
|  |  | ||||||
|  | # BizTalk build output | ||||||
|  | *.btp.cs | ||||||
|  | *.btm.cs | ||||||
|  | *.odx.cs | ||||||
|  | *.xsd.cs | ||||||
|  |  | ||||||
|  | # OpenCover UI analysis results | ||||||
|  | OpenCover/ | ||||||
|  |  | ||||||
|  | # Azure Stream Analytics local run output | ||||||
|  | ASALocalRun/ | ||||||
|  |  | ||||||
|  | # MSBuild Binary and Structured Log | ||||||
|  | *.binlog | ||||||
|  |  | ||||||
|  | # NVidia Nsight GPU debugger configuration file | ||||||
|  | *.nvuser | ||||||
|  |  | ||||||
|  | # MFractors (Xamarin productivity tool) working folder | ||||||
|  | .mfractor/ | ||||||
|  |  | ||||||
|  | # Local History for Visual Studio | ||||||
|  | .localhistory/ | ||||||
|  |  | ||||||
|  | /Core.Thalos.DAL.API/ThalosDALSettings.development.json | ||||||
|  | /Core.Thalos.DAL.API/thalosprivkey.pem | ||||||
|  | /Core.Thalos.DAL.API/thalospubkey.pem | ||||||
| @@ -1,495 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="UserController.cs"> |  | ||||||
| //     Heath |  | ||||||
| // </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 Microsoft.AspNetCore.Authorization; |  | ||||||
| using Microsoft.AspNetCore.Mvc; |  | ||||||
| using Microsoft.Graph; |  | ||||||
| using UserRequest = Core.Cerberos.Domain.Contexts.Onboarding.Request.UserRequest; |  | ||||||
|  |  | ||||||
| namespace LSA.Core.Kerberos.API.Controllers |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all requests for user authentication. |  | ||||||
|     /// </summary> |  | ||||||
|     [ApiVersion("1.0")] |  | ||||||
|     [Route("api/v{api-version:apiVersion}/[controller]")] |  | ||||||
|     [Produces(MimeTypes.ApplicationJson)] |  | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |  | ||||||
|     [ApiController] |  | ||||||
|     public class UserController(IUserService service, ILogger<UserController> logger) : ControllerBase |  | ||||||
|     { |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the users. |  | ||||||
|         /// </summary>   |  | ||||||
|         /// <returns>The <see cref="IEnumerable{UserAdapter}"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The users found.</response> |  | ||||||
|         /// <response code="404">The users not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetAllUsersService() |  | ||||||
|         { |  | ||||||
|             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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the user by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The user identifier.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The user found.</response> |  | ||||||
|         /// <response code="404">The user not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetUserByIdService([FromRoute] string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetUserByIdService(id); |  | ||||||
|  |  | ||||||
|                 if (result is null) return NotFound($"user with id: '{id}' not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetUserByIdService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets the user by email. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The user found.</response> |  | ||||||
|         /// <response code="404">The user not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route(Routes.Email)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] |  | ||||||
|         public async Task<IActionResult> GetUserByEmail([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetUserByEmailService(email); |  | ||||||
|  |  | ||||||
|                 if (result is null) return NotFound($"user with email: '{email}' not found"); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetUserByIdEmail"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Validates if a user exists on the database. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>The <see cref="UserExistenceAdapter"/> found entity.</returns> |  | ||||||
|         /// <response code="200">The user found.</response> |  | ||||||
|         /// <response code="404">The user not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route("{email}/ValidateExistence")] |  | ||||||
|         [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [AllowAnonymous] |  | ||||||
|         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.ValidateUserExistenceService(email); |  | ||||||
|  |  | ||||||
|                 var existence = new UserExistenceAdapter |  | ||||||
|                 { |  | ||||||
|                     Existence = (result is not null) ? true : false |  | ||||||
|                 }; |  | ||||||
|  |  | ||||||
|                 return Ok(existence); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ValidateUserExistance"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="newUser">The user to be added.</param> |  | ||||||
|         /// <param name="sendInvitation">Sends an invitation in case of third party access.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> created entity.</returns> |  | ||||||
|         /// <response code="201">The user created.</response> |  | ||||||
|         /// <response code="422">The user could not be created.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost(Routes.Register)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, [FromRoute] bool sendInvitation) |  | ||||||
|         { |  | ||||||
|             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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a full user by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The user to update.</param> |  | ||||||
|         /// <param name="id">The user identifier.</param> |  | ||||||
|         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The user updated.</response> |  | ||||||
|         /// <response code="404">The user not found.</response> |  | ||||||
|         /// <response code="422">The user could not be updated.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPut] |  | ||||||
|         [Route(Routes.Id)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> UpdateUserAsync([FromBody] UserAdapter entity, [FromRoute] string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.UpdateUserService(entity, id); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdateUserAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs in the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User's email.</param> |  | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         /// <response code="200">The User found.</response> |  | ||||||
|         /// <response code="404">The User not found.</response> |  | ||||||
|         /// <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) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.LogInUserService(email).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Logs out the user. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The User's email.</param> |  | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         /// <response code="200">The User updated.</response> |  | ||||||
|         /// <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) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.LogOutUserSessionService(email).ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in LogOutUserSessionService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <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>The <see cref="UserAdapter"/> updated entity.</returns> |  | ||||||
|         /// <response code="200">The user updates.</response> |  | ||||||
|         /// <response code="404">The user not found.</response> |  | ||||||
|         /// <response code="422">The user could not be deleted.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch] |  | ||||||
|         [Route(Routes.ChangeStatus)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a company to the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="companyId">The company identifier to add.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated companies.</response> |  | ||||||
|         /// <response code="404">The user or company not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [Route(Routes.AddCompany)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId) |  | ||||||
|         { |  | ||||||
|             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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a company from the user's list of companies. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="companyId">The company identifier to remove.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated companies.</response> |  | ||||||
|         /// <response code="404">The user or company not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpDelete] |  | ||||||
|         [Route(Routes.RemoveCompany)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId) |  | ||||||
|         { |  | ||||||
|             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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds a project to the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="projectId">The project identifier to add.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated projects.</response> |  | ||||||
|         /// <response code="404">The user or project not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPost] |  | ||||||
|         [Route(Routes.AddProject)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId) |  | ||||||
|         { |  | ||||||
|             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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes a project from the user's list of projects. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="userId">The user identifier.</param> |  | ||||||
|         /// <param name="projectId">The project identifier to remove.</param> |  | ||||||
|         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> |  | ||||||
|         /// <response code="200">The user with the updated projects.</response> |  | ||||||
|         /// <response code="404">The user or project not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpDelete] |  | ||||||
|         [Route(Routes.RemoveProject)] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Write")] |  | ||||||
|         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId) |  | ||||||
|         { |  | ||||||
|             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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets a token for the user, including roles, permissions, and modules. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="email">The user's email.</param> |  | ||||||
|         /// <returns>The token adapter with user details, role, permissions, and modules.</returns> |  | ||||||
|         /// <response code="200">The token adapter with user details.</response> |  | ||||||
|         /// <response code="404">The user not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route("{email}/GetTokenAdapter")] |  | ||||||
|         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] |  | ||||||
|         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var tokenAdapter = await service.GetTokenAdapter(email); |  | ||||||
|  |  | ||||||
|                 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}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Get Consent Form PDF. |  | ||||||
|         /// </summary>   |  | ||||||
|         /// <returns>The <see cref="BlobDownloadUriAdapter"/> found pdf.</returns> |  | ||||||
|         /// <response code="200">The pdf found.</response> |  | ||||||
|         /// <response code="404">The pdf not found error.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpGet] |  | ||||||
|         [Route("GetConsentFormPDF")] |  | ||||||
|         [ProducesResponseType(typeof(BlobDownloadUriAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |  | ||||||
|         [Permission("UserManagement.Read")] |  | ||||||
|         public async Task<IActionResult> GetConsentFormPDFService() |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.GetConsentFormPDFService(); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetConsentFormPDFService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Accept user consent form. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="UserAdapter"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         /// <response code="200">The User found.</response> |  | ||||||
|         /// <response code="404">The User not found.</response> |  | ||||||
|         /// <response code="500">The service internal error.</response> |  | ||||||
|         [HttpPatch("AcceptUserConsentForm")] |  | ||||||
|         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] |  | ||||||
|         [Authorize(AuthenticationSchemes = $"{Schemes.HeathScheme}, {Schemes.AzureScheme}")] |  | ||||||
|         public async Task<IActionResult> AcceptUserConsentFormAsync() |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var result = await service.AcceptUserConsentFormService().ConfigureAwait(false); |  | ||||||
|  |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in AcceptUserConsentFormService"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,6 +0,0 @@ | |||||||
| @Core.Cerberos.DAL.API_HostAddress = http://localhost:5211 |  | ||||||
|  |  | ||||||
| GET {{Core.Cerberos.DAL.API_HostAddress}}/weatherforecast/ |  | ||||||
| Accept: application/json |  | ||||||
|  |  | ||||||
| ### |  | ||||||
| @@ -1,86 +0,0 @@ | |||||||
| using Core.Cerberos.Adapters.Extensions; |  | ||||||
| using Core.Cerberos.Adapters.Helpers; |  | ||||||
| using Core.Cerberos.Provider; |  | ||||||
| using Microsoft.AspNetCore.RateLimiting; |  | ||||||
| using Microsoft.AspNetCore.ResponseCompression; |  | ||||||
| using System.IO.Compression; |  | ||||||
| using System.Reflection; |  | ||||||
| using System.Threading.RateLimiting; |  | ||||||
|  |  | ||||||
| var builder = WebApplication.CreateBuilder(args); |  | ||||||
|  |  | ||||||
| var authSettings = AuthHelper.GetAuthSettings(builder, "cerberos_dal"); |  | ||||||
|  |  | ||||||
| builder.Services.ConfigureAuthentication(builder.Configuration, authSettings); |  | ||||||
|  |  | ||||||
| builder.Configuration.AddUserSecrets(Assembly.GetExecutingAssembly()).AddEnvironmentVariables(); |  | ||||||
|  |  | ||||||
| // Add services to the container. |  | ||||||
|  |  | ||||||
| builder.Services.AddControllers(); |  | ||||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); |  | ||||||
|  |  | ||||||
| builder.Services.AddCors(options => |  | ||||||
| { |  | ||||||
|     options.AddPolicy("AllowAll", policyBuilder => |  | ||||||
|         policyBuilder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); |  | ||||||
| }); |  | ||||||
| builder.Services.AddMvc().AddJsonOptions(options => |  | ||||||
| { |  | ||||||
|     options.JsonSerializerOptions.WriteIndented = true; |  | ||||||
|     options.JsonSerializerOptions.MaxDepth = 20; |  | ||||||
|     options.JsonSerializerOptions.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; |  | ||||||
| }); |  | ||||||
| builder.Services.Configure<BrotliCompressionProviderOptions>(options => |  | ||||||
| { |  | ||||||
|     options.Level = CompressionLevel.Fastest; |  | ||||||
| }); |  | ||||||
| builder.Services.Configure<GzipCompressionProviderOptions>(options => |  | ||||||
| { |  | ||||||
|     options.Level = CompressionLevel.SmallestSize; |  | ||||||
| }); |  | ||||||
| builder.Services.AddResponseCompression(options => |  | ||||||
| { |  | ||||||
|     options.EnableForHttps = true; |  | ||||||
|     options.Providers.Add<BrotliCompressionProvider>(); |  | ||||||
|     options.Providers.Add<GzipCompressionProvider>(); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
| builder.Services.AddRateLimiter(_ => _ |  | ||||||
|     .AddFixedWindowLimiter("fixed", options => |  | ||||||
|     { |  | ||||||
|         options.PermitLimit = 5; |  | ||||||
|         options.Window = TimeSpan.FromSeconds(10); |  | ||||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; |  | ||||||
|         options.QueueLimit = 2; |  | ||||||
|     }) |  | ||||||
|     .AddSlidingWindowLimiter("sliding", options => |  | ||||||
|     { |  | ||||||
|         options.PermitLimit = 5; |  | ||||||
|         options.Window = TimeSpan.FromSeconds(10); |  | ||||||
|         options.SegmentsPerWindow = 5; |  | ||||||
|         options.QueueProcessingOrder = QueueProcessingOrder.OldestFirst; |  | ||||||
|         options.QueueLimit = 2; |  | ||||||
|     })); |  | ||||||
|  |  | ||||||
| builder.Services.AddResponseCaching(); |  | ||||||
| builder.Services.AddControllers(); |  | ||||||
| builder.Services.AddEndpointsApiExplorer(); |  | ||||||
| builder.Services.AddSwagger(builder.Configuration, "Core.Cerberos.DAL.API.xml", authSettings); |  | ||||||
| builder.Services.AddVersioning(builder.Configuration); |  | ||||||
| builder.Services.AddLogging(); |  | ||||||
| builder.Services.AddProblemDetails(); |  | ||||||
|  |  | ||||||
|  |  | ||||||
| builder.Services.AddDALLayer(builder.Configuration); |  | ||||||
|  |  | ||||||
| var app = builder.Build(); |  | ||||||
|  |  | ||||||
| app.UseSwaggerUI(builder.Configuration, authSettings); |  | ||||||
| app.ConfigureSwagger(builder.Configuration); |  | ||||||
| app.UseHttpsRedirection(); |  | ||||||
| app.UseAuthorization(); |  | ||||||
| app.MapControllers(); |  | ||||||
|  |  | ||||||
| app.Run(); |  | ||||||
| @@ -1,8 +0,0 @@ | |||||||
| { |  | ||||||
|   "Logging": { |  | ||||||
|     "LogLevel": { |  | ||||||
|       "Default": "Information", |  | ||||||
|       "Microsoft.AspNetCore": "Warning" |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
| } |  | ||||||
| @@ -1,12 +0,0 @@ | |||||||
| { |  | ||||||
|   "Logging": { |  | ||||||
|     "LogLevel": { |  | ||||||
|       "Default": "Information", |  | ||||||
|       "Microsoft.AspNetCore": "Warning" |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
|   "AllowedHosts": "*", |  | ||||||
|   "Endpoints": { |  | ||||||
|     "AppConfigurationURI": "https://sandbox-hci-usc-appcg.azconfig.io" |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @@ -1,25 +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="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" /> |  | ||||||
|     <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,256 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="ModuleService.cs"> |  | ||||||
| //     Heath |  | ||||||
| // </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.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers.Onboarding |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all services and business rules related to <see cref="ModuleAdapter"/>. |  | ||||||
|     /// </summary> |  | ||||||
|     public class ModuleService(ILogger<ModuleService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, |  | ||||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database) : IModuleService |  | ||||||
|     { |  | ||||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Module. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Module to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<ModuleAdapter> CreateModuleService(ModuleRequest newModule) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var entity = newModule.ToAdapter(httpContextAccessor); |  | ||||||
|                 entity.Order = (entity.Order is not null) ? entity.Order : await GetLastOrderModule(newModule); |  | ||||||
|                 await database.GetCollection<ModuleAdapter>(CollectionNames.Module).InsertOneAsync(entity); |  | ||||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); |  | ||||||
|  |  | ||||||
|                 return entity; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"CreateModuleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Module by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Module identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns>0 |  | ||||||
|         public async Task<ModuleAdapter> GetModuleByIdService(string id) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleByIdService", id); |  | ||||||
|             var cachedData = await cacheService.GetAsync<ModuleAdapter>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter.And( |  | ||||||
|                     Builders<ModuleAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), |  | ||||||
|                     Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                 ); |  | ||||||
|  |  | ||||||
|                 var module = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, module, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return module; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetModuleByIdService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the modules. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<ModuleAdapter>> GetAllModulesService() |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesService"); |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; |  | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .SortBy(m => m.Application) |  | ||||||
|                                     .ThenBy(m => m.Order) |  | ||||||
|                                     .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllModulesService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the modules by modules identifier list. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="modules">The list of modules identifiers.</param> |  | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<ModuleAdapter>> GetAllModulesByListService(string[] modules) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByListService", modules); |  | ||||||
|  |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData != null && cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var objectIds = modules.Select(id => ObjectId.Parse(id)).ToArray(); |  | ||||||
|  |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter.In("_id", objectIds) |  | ||||||
|                                 & Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                           .Find(filter) |  | ||||||
|                                           .SortBy(m => m.Application) |  | ||||||
|                                           .ThenBy(m => m.Order) |  | ||||||
|                                           .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllModulesByListService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the module. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The module identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the module.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<ModuleAdapter> ChangeModuleStatusService(string id, StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<ModuleAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, newStatus) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<ModuleAdapter>(CollectionNames.Module).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedModule = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedModule; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ChangeModuleStatusService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Module by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Module to be updated.</param> |  | ||||||
|         /// <param name="id">The Module identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<ModuleAdapter> UpdateModuleService(ModuleAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<ModuleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<ModuleAdapter>.Update |  | ||||||
|                             .Set(v => v.Name, entity.Name) |  | ||||||
|                             .Set(v => v.Description, entity.Description) |  | ||||||
|                             .Set(v => v.Icon, entity.Icon) |  | ||||||
|                             .Set(v => v.Route, entity.Route) |  | ||||||
|                             .Set(v => v.Order, entity.Order) |  | ||||||
|                             .Set(v => v.Application, entity.Application) |  | ||||||
|                             .Set(v => v.Status, entity.Status) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<ModuleAdapter>(CollectionNames.Module).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedModule = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                             .Find(filter) |  | ||||||
|                                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedModule; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"UpdateModuleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private async Task<int?> GetLastOrderModule(ModuleRequest newModule) |  | ||||||
|         { |  | ||||||
|             var filter = Builders<ModuleAdapter>.Filter.And( |  | ||||||
|                 Builders<ModuleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()), |  | ||||||
|                 Builders<ModuleAdapter>.Filter.Eq("application", newModule.Application.ToString())); |  | ||||||
|  |  | ||||||
|             var maxOrderModule = await database.GetCollection<ModuleAdapter>(CollectionNames.Module) |  | ||||||
|                                                .Find(filter) |  | ||||||
|                                                .SortByDescending(m => m.Order) |  | ||||||
|                                                .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|             return (maxOrderModule is not null && maxOrderModule.Order is not null) ? maxOrderModule.Order : 0; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,234 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="PermissionService.cs"> |  | ||||||
| //     Heath |  | ||||||
| // </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.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers.Onboarding |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all services and business rules related to <see cref="PermissionAdapter"/>. |  | ||||||
|     /// </summary> |  | ||||||
|     public class PermissionService(ILogger<PermissionService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, |  | ||||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database) : IPermissionService |  | ||||||
|     { |  | ||||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Permission. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Permission to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<PermissionAdapter> CreatePermissionService(PermissionRequest newPermission) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var entity = newPermission.ToAdapter(httpContextAccessor); |  | ||||||
|                 await database.GetCollection<PermissionAdapter>(CollectionNames.Permission).InsertOneAsync(entity); |  | ||||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); |  | ||||||
|  |  | ||||||
|                 return entity; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"CreatePermissionService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Permission by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Permission identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns>0 |  | ||||||
|         public async Task<PermissionAdapter> GetPermissionByIdService(string id) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionByIdService", id); |  | ||||||
|             var cachedData = await cacheService.GetAsync<PermissionAdapter>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter.And( |  | ||||||
|                     Builders<PermissionAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), |  | ||||||
|                     Builders<PermissionAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                 ); |  | ||||||
|  |  | ||||||
|                 var permission = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, permission, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return permission; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetPermissionByIdService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the permissions. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<PermissionAdapter>> GetAllPermissionsService() |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsService"); |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; |  | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllPermissionsService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the permissions by permissions identifier list. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |  | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<PermissionAdapter>> GetAllPermissionsByListService(string[] permissions) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByListService", permissions); |  | ||||||
|  |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData != null && cachedData.Any()) return cachedData; |  | ||||||
|  |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var objectIds = permissions.Select(id => ObjectId.Parse(id)).ToArray(); |  | ||||||
|  |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter.In("_id", objectIds) |  | ||||||
|                                 & Builders<PermissionAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                           .Find(filter) |  | ||||||
|                                           .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllPermissionsByListService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the permission. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The permission identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the permission.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<PermissionAdapter> ChangePermissionStatusService(string id, StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<PermissionAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, newStatus) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<PermissionAdapter>(CollectionNames.Permission).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedPermission = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedPermission; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ChangePermissionStatusService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Permission by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Permission to be updated.</param> |  | ||||||
|         /// <param name="id">The Permission identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<PermissionAdapter> UpdatePermissionService(PermissionAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<PermissionAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<PermissionAdapter>.Update |  | ||||||
|                             .Set(v => v.Name, entity.Name) |  | ||||||
|                             .Set(v => v.Description, entity.Description) |  | ||||||
|                             .Set(v => v.AccessLevel, entity.AccessLevel) |  | ||||||
|                             .Set(v => v.Status, entity.Status) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<PermissionAdapter>(CollectionNames.Permission).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedPermission = await database.GetCollection<PermissionAdapter>(CollectionNames.Permission) |  | ||||||
|                                             .Find(filter) |  | ||||||
|                                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedPermission; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"UpdatePermissionService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,251 +0,0 @@ | |||||||
| // *********************************************************************** |  | ||||||
| // <copyright file="RoleService.cs"> |  | ||||||
| //     Heath |  | ||||||
| // </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.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider.Providers.Onboarding |  | ||||||
| { |  | ||||||
|     /// <summary> |  | ||||||
|     /// Handles all services and business rules related to <see cref="RoleAdapter"/>. |  | ||||||
|     /// </summary> |  | ||||||
|     public class RoleService(ILogger<RoleService> logger, IHttpContextAccessor httpContextAccessor, ICacheService cacheService, |  | ||||||
|         IOptions<CacheSettings> cacheSettings, IMongoDatabase database) : IRoleService |  | ||||||
|     { |  | ||||||
|         private readonly CacheSettings _cacheSettings = cacheSettings.Value; |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Creates a new Role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Role to be created.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> CreateRoleService(RoleRequest newRole) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var entity = newRole.ToAdapter(httpContextAccessor); |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).InsertOneAsync(entity); |  | ||||||
|                 entity.Id = (entity as dynamic ?? "").Id.ToString(); |  | ||||||
|  |  | ||||||
|                 return entity; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"CreateRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets an Role by identifier. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The Role identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> GetRoleByIdService(string id) |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleByIdService", id); |  | ||||||
|             var cachedData = await cacheService.GetAsync<RoleAdapter>(cacheKey); |  | ||||||
|  |  | ||||||
|             if (cachedData is not null) { return cachedData; } |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.And( |  | ||||||
|                         Builders<RoleAdapter>.Filter.Eq("_id", ObjectId.Parse(id)), |  | ||||||
|                         Builders<RoleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()) |  | ||||||
|                     ); |  | ||||||
|  |  | ||||||
|                 var role = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                 .Find(filter) |  | ||||||
|                             .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, role, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return role; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetRoleByIdService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Gets all the roles. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<IEnumerable<RoleAdapter>> GetAllRolesService() |  | ||||||
|         { |  | ||||||
|             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRolesService"); |  | ||||||
|             var cachedData = await cacheService.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? []; |  | ||||||
|  |  | ||||||
|             if (cachedData.Any()) return cachedData; |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.Eq("status", StatusEnum.Active.ToString()); |  | ||||||
|  |  | ||||||
|                 var roles = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                 .Find(filter) |  | ||||||
|                                 .ToListAsync(); |  | ||||||
|  |  | ||||||
|                 var cacheDuration = CacheHelper.GetCacheDuration(_cacheSettings); |  | ||||||
|  |  | ||||||
|                 await cacheService.SetAsync(cacheKey, roles, cacheDuration); |  | ||||||
|  |  | ||||||
|                 return roles; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"GetAllRolesService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Changes the status of the role. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="id">The role identifier.</param> |  | ||||||
|         /// <param name="newStatus">The new status of the role.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> ChangeRoleStatusService(string id, StatusEnum newStatus) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<RoleAdapter>.Update |  | ||||||
|                             .Set(v => v.Status, newStatus) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"ChangeRoleStatusService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Updates a Role by id. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="entity">The Role to be updated.</param> |  | ||||||
|         /// <param name="id">The Role identifier.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         public async Task<RoleAdapter> UpdateRoleService(RoleAdapter entity, string id) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter |  | ||||||
|                     .Eq("_id", ObjectId.Parse(id)); |  | ||||||
|  |  | ||||||
|                 var update = Builders<RoleAdapter>.Update |  | ||||||
|                             .Set(v => v.Name, entity.Name) |  | ||||||
|                             .Set(v => v.Description, entity.Description) |  | ||||||
|                             .Set(v => v.Applications, entity.Applications) |  | ||||||
|                             .Set(v => v.Modules, entity.Modules) |  | ||||||
|                             .Set(v => v.Permissions, entity.Permissions) |  | ||||||
|                             .Set(v => v.Status, entity.Status) |  | ||||||
|                             .Set(v => v.UpdatedBy, Helper.GetEmail(httpContextAccessor)) |  | ||||||
|                             .Set(v => v.UpdatedAt, DateTime.UtcNow); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|  |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"UpdateRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Adds an application to the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |  | ||||||
|         /// <param name="application">The application enum value to add.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         public async Task<RoleAdapter> AddApplicationToRoleService(string roleId, ApplicationsEnum application) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.Eq("_id", ObjectId.Parse(roleId)); |  | ||||||
|                 var update = Builders<RoleAdapter>.Update.AddToSet(r => r.Applications, application); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"AddApplicationToRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         /// <summary> |  | ||||||
|         /// Removes an application from the role's list of applications. |  | ||||||
|         /// </summary> |  | ||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |  | ||||||
|         /// <param name="application">The application enum value to remove.</param> |  | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |  | ||||||
|         public async Task<RoleAdapter> RemoveApplicationFromRoleService(string roleId, ApplicationsEnum application) |  | ||||||
|         { |  | ||||||
|             try |  | ||||||
|             { |  | ||||||
|                 var filter = Builders<RoleAdapter>.Filter.Eq("_id", ObjectId.Parse(roleId)); |  | ||||||
|                 var update = Builders<RoleAdapter>.Update.Pull(r => r.Applications, application); |  | ||||||
|  |  | ||||||
|                 await database.GetCollection<RoleAdapter>(CollectionNames.Role).UpdateOneAsync(filter, update); |  | ||||||
|  |  | ||||||
|                 var updatedRole = await database.GetCollection<RoleAdapter>(CollectionNames.Role) |  | ||||||
|                                     .Find(filter) |  | ||||||
|                                     .FirstOrDefaultAsync(); |  | ||||||
|                 return updatedRole; |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, $"RemoveApplicationFromRoleService: Error in getting data - {ex.Message}"); |  | ||||||
|                 throw new Exception(ex.Message, ex); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -1,104 +0,0 @@ | |||||||
| 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 LSA.Core.Dapper.Service.Caching; |  | ||||||
| using Microsoft.Extensions.Configuration; |  | ||||||
| using Microsoft.Extensions.DependencyInjection; |  | ||||||
| using Microsoft.Extensions.Logging; |  | ||||||
| using Microsoft.Extensions.Options; |  | ||||||
| using MongoDB.Driver; |  | ||||||
|  |  | ||||||
| namespace Core.Cerberos.Provider |  | ||||||
| { |  | ||||||
|     public static class ServiceCollectionExtensions |  | ||||||
|     { |  | ||||||
|         public static IServiceCollection AddDALLayer(this IServiceCollection services, IConfiguration configuration) |  | ||||||
|         { |  | ||||||
|             var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty; |  | ||||||
|  |  | ||||||
|             var connectionString = configuration.GetSection("ConnectionStrings:MongoDB").Value ?? string.Empty; |  | ||||||
|             var databaseName = configuration.GetSection("MongoDB:DatabaseName").Value ?? string.Empty; |  | ||||||
|             var audience = (environment == "Local") |  | ||||||
|                 ? configuration.GetSection("MongoDB:LocalAudience").Value |  | ||||||
|                 : configuration.GetSection("MongoDB:Audience").Value; |  | ||||||
|  |  | ||||||
|             if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(databaseName) || string.IsNullOrEmpty(audience)) |  | ||||||
|             { |  | ||||||
|                 throw new InvalidOperationException("Mongo connection is not configured correctly."); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             services.Configure<MongoConnSettings>(options => |  | ||||||
|             { |  | ||||||
|                 options.ConnectionString = connectionString; |  | ||||||
|                 options.Databasename = databaseName; |  | ||||||
|                 options.Audience = audience ?? string.Empty; |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddSingleton<IMongoClient>(serviceProvider => |  | ||||||
|             { |  | ||||||
|                 var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value; |  | ||||||
|                 var mongoClientSettings = MongoClientSettings.FromConnectionString(settings.ConnectionString); |  | ||||||
|                 mongoClientSettings.Credential = MongoCredential.CreateOidcCredential(new HeathOidcCallback(settings.Audience)); |  | ||||||
|                 return new MongoClient(mongoClientSettings); |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddSingleton<IMongoDatabase>(serviceProvider => |  | ||||||
|             { |  | ||||||
|                 var settings = serviceProvider.GetRequiredService<IOptions<MongoConnSettings>>().Value; |  | ||||||
|                 var client = serviceProvider.GetRequiredService<IMongoClient>(); |  | ||||||
|                 return client.GetDatabase(settings.Databasename); |  | ||||||
|             }); |  | ||||||
|  |  | ||||||
|             services.AddDALConfigurationLayer(); |  | ||||||
|             services.AddLogs(); |  | ||||||
|             services.AddRedisCacheService(configuration); |  | ||||||
|             services.AddBlobStorage(configuration); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddDALConfigurationLayer(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddHttpContextAccessor(); |  | ||||||
|  |  | ||||||
|             services.AddScoped<IUserService, UserService>(); |  | ||||||
|             services.AddScoped<IRoleService, RoleService>(); |  | ||||||
|             services.AddScoped<IPermissionService, PermissionService>(); |  | ||||||
|             services.AddScoped<IPermissionService, PermissionService>(); |  | ||||||
|             services.AddScoped<IModuleService, ModuleService>(); |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddLogs(this IServiceCollection services) |  | ||||||
|         { |  | ||||||
|             services.AddLogging(); |  | ||||||
|             var serviceProvider = services.BuildServiceProvider(); |  | ||||||
|             //var logger = serviceProvider.GetService<ILogger<DashboardDALService>>(); //Add for Markup class later TODO |  | ||||||
|  |  | ||||||
|             //services.AddSingleton(typeof(ILogger), logger); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         private static IServiceCollection AddRedisCacheService(this IServiceCollection services, IConfiguration configuration) |  | ||||||
|         { |  | ||||||
|             var source = configuration.GetSection("ConnectionStrings"); |  | ||||||
|  |  | ||||||
|             var redisConnectionString = source["Redis"]?.ToString(); |  | ||||||
|  |  | ||||||
|             if (string.IsNullOrEmpty(redisConnectionString)) |  | ||||||
|             { |  | ||||||
|                 throw new InvalidOperationException("Redis connection string is not configured."); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             services.AddSingleton<ICacheService>(provider => |  | ||||||
|                 new CacheService(redisConnectionString, provider.GetRequiredService<ILogger<CacheService>>())); |  | ||||||
|  |  | ||||||
|             return services; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 | |||||||
| # Visual Studio Version 17 | # Visual Studio Version 17 | ||||||
| VisualStudioVersion = 17.10.35027.167 | VisualStudioVersion = 17.10.35027.167 | ||||||
| MinimumVisualStudioVersion = 10.0.40219.1 | 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 | EndProject | ||||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{2E7D918E-AB9F-44BF-A334-FD675C9B626E}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Application", "Application", "{2E7D918E-AB9F-44BF-A334-FD675C9B626E}" | ||||||
| EndProject | 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 | 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 | 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 | EndProject | ||||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Presentation", "Presentation", "{36839283-6407-476A-BB33-F0EE90383E2B}" | ||||||
| EndProject | EndProject | ||||||
| @@ -1,20 +1,21 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="ModuleController.cs"> | // <copyright file="ModuleController.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Cerberos.Adapters; | using Core.Blueprint.Mongo; | ||||||
| using Core.Cerberos.Adapters.Attributes; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Adapters.Common.Constants; | using Core.Thalos.Adapters.Attributes; | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using Microsoft.Graph; | ||||||
|  | using ModuleRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.ModuleRequest; | ||||||
| 
 | 
 | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for module authentication. |     /// Handles all requests for module authentication. | ||||||
| @@ -24,7 +25,8 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     public class ModuleController(IModuleService service, ILogger<ModuleController> logger) : ControllerBase |     [AllowAnonymous] | ||||||
|  |     public class ModuleController(IModuleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the modules. |         /// Gets all the modules. | ||||||
| @@ -37,21 +39,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("ModuleManagement.Read, RoleManagement.Read")] |         //[Permission("ModuleManagement.Read, RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllModulesAsync() |         public async Task<IActionResult> GetAllModulesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetAllModules(cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.GetAllModulesService(); |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllModulesAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -67,31 +60,17 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<ModuleAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("ModuleManagement.Read")] |         //[Permission("ModuleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules) |         public async Task<IActionResult> GetAllModulesByList([FromBody] string[] modules, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (modules == null || !modules.Any()) |             if (modules == null || !modules.Any()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Module identifiers are required."); |                 return BadRequest("Module identifiers are required."); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             try |             var result = await service.GetAllModulesByList(modules, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.GetAllModulesByListService(modules); |  | ||||||
| 
 |  | ||||||
|                 if (result == null || !result.Any()) |  | ||||||
|                 { |  | ||||||
|                     return NotFound("No modules found for the given identifiers."); |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllModulesByList"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @@ -108,23 +87,18 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("ModuleManagement.Read")] |         //[Permission("ModuleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id) |         public async Task<IActionResult> GetModuleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetModuleById(id, cancellationToken).ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var result = await service.GetModuleByIdService(id); |  | ||||||
| 
 | 
 | ||||||
|                 if (result is null) return NotFound($"module with id: '{id}' not found"); |             if (result == null) | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |             { | ||||||
|                 logger.LogError(ex, "Error in GetModuleByIdAsync"); |                 return NotFound("Entity not found"); | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             return Ok(result); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -137,20 +111,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal e|ror.</response> |         /// <response code="500">The service internal e|ror.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status201Created)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("ModuleManagement.Write")] |         //[Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule) |         public async Task<IActionResult> CreateModuleAsync([FromBody] ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.CreateModule(newModule, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Created("CreatedWithIdAsync", result); | ||||||
|                 var result = await service.CreateModuleService(newModule).ConfigureAwait(false); |  | ||||||
|                 return Created("CreatedWithIdService", result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in CreateModuleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -168,21 +134,18 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("ModuleManagement.Write")] |         //[Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateModuleAsync(ModuleAdapter entity, string id) |         public async Task<IActionResult> UpdateModuleAsync([FromRoute] string id, ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             if (id != entity.Id?.ToString()) | ||||||
|             { |             { | ||||||
|                 var result = await service.UpdateModuleService(entity, id); |                 return BadRequest("Module ID mismatch"); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|                 return Ok(result); |             var result = await service.UpdateModule(entity, cancellationToken).ConfigureAwait(false); | ||||||
|             } | 
 | ||||||
|             catch (Exception ex) |             return Ok(result); | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdateModuleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -200,21 +163,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(ModuleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("ModuleManagement.Write")] |         //[Permission("ModuleManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |         public async Task<IActionResult> ChangeModuleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.ChangeModuleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.ChangeModuleStatusService(id, newStatus); |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ChangeModuleStatus"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -1,20 +1,21 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="PermissionController.cs"> | // <copyright file="PermissionController.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Cerberos.Adapters; | using Core.Blueprint.Mongo; | ||||||
| using Core.Cerberos.Adapters.Attributes; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Adapters.Common.Constants; | using Core.Thalos.Adapters.Attributes; | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Provider.Contracts; | ||||||
| using Core.Cerberos.Provider.Contracts; |  | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using Microsoft.Graph; | ||||||
|  | using PermissionRequest = Core.Thalos.Domain.Contexts.Onboarding.Request.PermissionRequest; | ||||||
| 
 | 
 | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for permission authentication. |     /// Handles all requests for permission authentication. | ||||||
| @@ -24,7 +25,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     public class PermissionController(IPermissionService service, ILogger<PermissionController> logger) : ControllerBase |     public class PermissionController(IPermissionProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions. |         /// Gets all the permissions. | ||||||
| @@ -37,21 +38,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("PermissionManagement.Read, RoleManagement.Read")] |         //[Permission("PermissionManagement.Read, RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsAsync() |         public async Task<IActionResult> GetAllPermissionsAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetAllPermissions(cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.GetAllPermissionsService(); |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllPermissionsAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -67,31 +59,17 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<PermissionAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("PermissionManagement.Read")] |         //[Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions) |         public async Task<IActionResult> GetAllPermissionsByList([FromBody] string[] permissions, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             if (permissions == null || !permissions.Any()) |             if (permissions == null || !permissions.Any()) | ||||||
|             { |             { | ||||||
|                 return BadRequest("Permission identifiers are required."); |                 return BadRequest("Permissions identifiers are required."); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             try |             var result = await service.GetAllPermissionsByList(permissions, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.GetAllPermissionsByListService(permissions); |  | ||||||
| 
 |  | ||||||
|                 if (result == null || !result.Any()) |  | ||||||
|                 { |  | ||||||
|                     return NotFound("No permissions found for the given identifiers."); |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllPermissionsByList"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -107,23 +85,18 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("PermissionManagement.Read")] |         //[Permission("PermissionManagement.Read")] | ||||||
|         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id) |         public async Task<IActionResult> GetPermissionByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetPermissionById(id, cancellationToken).ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var result = await service.GetPermissionByIdService(id); |  | ||||||
| 
 | 
 | ||||||
|                 if (result is null) return NotFound($"permission with id: '{id}' not found"); |             if (result == null) | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |             { | ||||||
|                 logger.LogError(ex, "Error in GetPermissionByIdAsync"); |                 return NotFound("Entity not found"); | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             return Ok(result); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -136,20 +109,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal e|ror.</response> |         /// <response code="500">The service internal e|ror.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status201Created)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("PermissionManagement.Write")] |         //[Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission) |         public async Task<IActionResult> CreatePermissionAsync([FromBody] PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.CreatePermission(newPermission, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Created("CreatedWithIdAsync", result); | ||||||
|                 var result = await service.CreatePermissionService(newPermission).ConfigureAwait(false); |  | ||||||
|                 return Created("CreatedWithIdService", result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in CreatePermissionAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -167,21 +132,18 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("PermissionManagement.Write")] |         //[Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdatePermissionAsync(PermissionAdapter entity, string id) |         public async Task<IActionResult> UpdatePermissionAsync([FromRoute] string id, PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             if (id != entity.Id?.ToString()) | ||||||
|             { |             { | ||||||
|                 var result = await service.UpdatePermissionService(entity, id); |                 return BadRequest("Permission ID mismatch"); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|                 return Ok(result); |             var result = await service.UpdatePermission(entity, cancellationToken).ConfigureAwait(false); | ||||||
|             } | 
 | ||||||
|             catch (Exception ex) |             return Ok(result); | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdatePermissionAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -199,21 +161,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [Consumes(MimeTypes.ApplicationJson)] |         [Consumes(MimeTypes.ApplicationJson)] | ||||||
|         [Produces(MimeTypes.ApplicationJson)] |         [Produces(MimeTypes.ApplicationJson)] | ||||||
|         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(PermissionAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("PermissionManagement.Write")] |         //[Permission("PermissionManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |         public async Task<IActionResult> ChangePermissionStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.ChangePermissionStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.ChangePermissionStatusService(id, newStatus); |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ChangePermissionStatus"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -1,19 +1,20 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="RoleController.cs"> | // <copyright file="RoleController.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Asp.Versioning; | using Asp.Versioning; | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Adapters.Attributes; | using Core.Thalos.Adapters.Attributes; | ||||||
| using Core.Cerberos.Adapters.Common.Constants; | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Cerberos.Provider.Contracts; | using Core.Thalos.Provider.Contracts; | ||||||
| using Microsoft.AspNetCore.Authorization; | using Microsoft.AspNetCore.Authorization; | ||||||
| using Microsoft.AspNetCore.Mvc; | using Microsoft.AspNetCore.Mvc; | ||||||
|  | using StatusEnum = Core.Blueprint.Mongo.StatusEnum; | ||||||
| 
 | 
 | ||||||
| namespace LSA.Core.Kerberos.API.Controllers | namespace LSA.Core.Thalos.API.Controllers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles all requests for role authentication. |     /// Handles all requests for role authentication. | ||||||
| @@ -23,7 +24,7 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|     [Produces(MimeTypes.ApplicationJson)] |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|     [Consumes(MimeTypes.ApplicationJson)] |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|     [ApiController] |     [ApiController] | ||||||
|     public class RoleController(IRoleService service, ILogger<RoleController> logger) : ControllerBase |     public class RoleController(IRoleProvider service) : ControllerBase | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all the roles. | ||||||
| @@ -34,21 +35,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(IEnumerable<RoleAdapter>), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("RoleManagement.Read")] |         //[Permission("RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetAllRolesAsync() |         public async Task<IActionResult> GetAllRolesAsync(CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetAllRoles(cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.GetAllRolesService(); |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in GetAllRolesAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -62,23 +54,18 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpGet] |         [HttpGet] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("RoleManagement.Read")] |         //[Permission("RoleManagement.Read")] | ||||||
|         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id) |         public async Task<IActionResult> GetRoleByIdAsync([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.GetRoleById(id, cancellationToken).ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 var result = await service.GetRoleByIdService(id); |  | ||||||
| 
 | 
 | ||||||
|                 if (result is null) return NotFound($"role with id: '{id}' not found"); |             if (result == null) | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |             { | ||||||
|                 logger.LogError(ex, "Error in GetRoleByIdAsync"); |                 return NotFound("Entity not found"); | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             return Ok(result); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -91,21 +78,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPost] |         [HttpPost] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status201Created)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole) |         public async Task<IActionResult> CreateRoleAsync([FromBody] RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.CreateRole(newRole, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Created("CreatedWithIdAsync", result); | ||||||
|                 var result = await service.CreateRoleService(newRole).ConfigureAwait(false); |  | ||||||
| 
 |  | ||||||
|                 return Created("CreatedWithIdService", result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in CreateRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -121,21 +99,18 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpPut] |         [HttpPut] | ||||||
|         [Route(Routes.Id)] |         [Route(Routes.Id)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> UpdateRoleAsync([FromBody] RoleAdapter entity, [FromRoute] string id) |         public async Task<IActionResult> UpdateRoleAsync([FromRoute] string id, [FromBody] RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             if (id != entity.Id?.ToString()) | ||||||
|             { |             { | ||||||
|                 var result = await service.UpdateRoleService(entity, id); |                 return BadRequest("Role ID mismatch"); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|                 return Ok(result); |             var result = await service.UpdateRole(entity, cancellationToken).ConfigureAwait(false); | ||||||
|             } | 
 | ||||||
|             catch (Exception ex) |             return Ok(result); | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in UpdateRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -151,22 +126,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         [HttpPatch] |         [HttpPatch] | ||||||
|         [Route(Routes.ChangeStatus)] |         [Route(Routes.ChangeStatus)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus) |         public async Task<IActionResult> ChangeRoleStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             try |             var result = await service.ChangeRoleStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var result = await service.ChangeRoleStatusService(id, newStatus); |  | ||||||
| 
 |  | ||||||
|                 return Ok(result); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in ChangeRoleStatus"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -181,22 +146,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpPost(Routes.AddApplication)] |         [HttpPost(Routes.AddApplication)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, |         public async Task<IActionResult> AddApplicationToRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|                                                                    [FromRoute] ApplicationsEnum application) |  | ||||||
|         { |         { | ||||||
|             try |             var result = await service.AddApplicationToRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var updatedRole = await service.AddApplicationToRoleService(roleId, application); |  | ||||||
| 
 |  | ||||||
|                 return Ok(updatedRole); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in AddApplicationToRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -211,21 +166,12 @@ namespace LSA.Core.Kerberos.API.Controllers | |||||||
|         /// <response code="500">The service internal error.</response> |         /// <response code="500">The service internal error.</response> | ||||||
|         [HttpDelete(Routes.RemoveApplication)] |         [HttpDelete(Routes.RemoveApplication)] | ||||||
|         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] |         [ProducesResponseType(typeof(RoleAdapter), StatusCodes.Status200OK)] | ||||||
|         [Authorize(AuthenticationSchemes = Schemes.HeathScheme)] |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|         [Permission("RoleManagement.Write")] |         //[Permission("RoleManagement.Write")] | ||||||
|         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, |         public async Task<IActionResult> RemoveApplicationFromRoleAsync([FromRoute] string roleId, [FromRoute] ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|                                                                         [FromRoute] ApplicationsEnum application) |  | ||||||
|         { |         { | ||||||
|             try |             var result = await service.RemoveApplicationFromRole(roleId, application, cancellationToken).ConfigureAwait(false); | ||||||
|             { |             return Ok(result); | ||||||
|                 var updatedRole = await service.RemoveApplicationFromRoleService(roleId, application); |  | ||||||
|                 return Ok(updatedRole); |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 logger.LogError(ex, "Error in RemoveApplicationFromRoleAsync"); |  | ||||||
|                 return StatusCode(500, $"Internal server error, ErrorMessage: {ex.Message}"); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
							
								
								
									
										328
									
								
								Core.Thalos.DAL.API/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										328
									
								
								Core.Thalos.DAL.API/Controllers/UserController.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,328 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="UserController.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using Asp.Versioning; | ||||||
|  | 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.Thalos.Domain.Contexts.Onboarding.Request.UserRequest; | ||||||
|  |  | ||||||
|  | namespace LSA.Core.Thalos.API.Controllers | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all requests for user authentication. | ||||||
|  |     /// </summary> | ||||||
|  |     [ApiVersion("1.0")] | ||||||
|  |     [Route("api/v{api-version:apiVersion}/[controller]")] | ||||||
|  |     [Produces(MimeTypes.ApplicationJson)] | ||||||
|  |     [Consumes(MimeTypes.ApplicationJson)] | ||||||
|  |     [ApiController] | ||||||
|  |     public class UserController(IUserProvider service) : ControllerBase | ||||||
|  |     { | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the users. | ||||||
|  |         /// </summary>   | ||||||
|  |         /// <returns>The <see cref="IEnumerable{UserAdapter}"/> found entity.</returns> | ||||||
|  |         /// <response code="200">The users found.</response> | ||||||
|  |         /// <response code="404">The users not found error.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [ProducesResponseType(typeof(IEnumerable<UserAdapter>), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetAllUsers(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetAllUsers(cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the user by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="id">The user identifier.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> | ||||||
|  |         /// <response code="200">The user found.</response> | ||||||
|  |         /// <response code="404">The user not found error.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Read")] | ||||||
|  |         public async Task<IActionResult> GetUserById([FromRoute] string id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetUserById(id, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |             { | ||||||
|  |                 return NotFound("Entity not found"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets the user by email. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> found entity.</returns> | ||||||
|  |         /// <response code="200">The user found.</response> | ||||||
|  |         /// <response code="404">The user not found error.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route(Routes.Email)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|  |         public async Task<IActionResult> GetUserByEmail([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.GetUserByEmail(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |             { | ||||||
|  |                 return NotFound("User not found"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Validates if a user exists on the database. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <returns>The <see cref="UserExistenceAdapter"/> found entity.</returns> | ||||||
|  |         /// <response code="200">The user found.</response> | ||||||
|  |         /// <response code="404">The user not found error.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route("{email}/ValidateExistence")] | ||||||
|  |         [ProducesResponseType(typeof(UserExistenceAdapter), StatusCodes.Status200OK)] | ||||||
|  |         [AllowAnonymous] | ||||||
|  |         public async Task<IActionResult> ValidateUserExistence([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.ValidateUserExistence(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result == null) | ||||||
|  |             { | ||||||
|  |                 return NotFound("User not found"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="newUser">The user to be added.</param> | ||||||
|  |         /// <param name="sendInvitation">Sends an invitation in case of third party access.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> created entity.</returns> | ||||||
|  |         /// <response code="201">The user created.</response> | ||||||
|  |         /// <response code="422">The user could not be created.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost(Routes.Register)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status201Created)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> CreateUserAsync([FromBody] UserRequest newUser, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.CreateUser(newUser, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Created("CreatedWithIdAsync", result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a full user by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The user to update.</param> | ||||||
|  |         /// <param name="id">The user identifier.</param> | ||||||
|  |         /// <returns>The <see cref="UserAdapter"/> updated entity.</returns> | ||||||
|  |         /// <response code="200">The user updated.</response> | ||||||
|  |         /// <response code="404">The user not found.</response> | ||||||
|  |         /// <response code="422">The user could not be updated.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPut] | ||||||
|  |         [Route(Routes.Id)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> UpdateUserAsync([FromRoute] string id, [FromBody] UserAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             if (id != entity.Id?.ToString()) | ||||||
|  |             { | ||||||
|  |                 return BadRequest("User ID mismatch"); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             var result = await service.UpdateUser(entity, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs in the user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User's email.</param> | ||||||
|  |         /// <returns>A <see cref="UserAdapter"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         /// <response code="200">The User found.</response> | ||||||
|  |         /// <response code="404">The User not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPatch(Routes.LogIn)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|  |         public async Task<IActionResult> LoginUserAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.LogInUser(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (result is null) | ||||||
|  |                 return new NotFoundObjectResult($"The user with email: '{email}' was not found"); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Logs out the user. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The User's email.</param> | ||||||
|  |         /// <returns>A <see cref="UserAdapter"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         /// <response code="200">The User updated.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPatch(Routes.LogOut)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|  |         public async Task<IActionResult> LogOutUserSessionAsync([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.LogOutUserSession(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             return Ok(result); | ||||||
|  |  | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <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>The <see cref="UserAdapter"/> updated entity.</returns> | ||||||
|  |         /// <response code="200">The user updates.</response> | ||||||
|  |         /// <response code="404">The user not found.</response> | ||||||
|  |         /// <response code="422">The user could not be deleted.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPatch] | ||||||
|  |         [Route(Routes.ChangeStatus)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> ChangeUserStatus([FromRoute] string id, [FromRoute] StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.ChangeUserStatus(id, newStatus, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds a company to the user's list of companies. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="companyId">The company identifier to add.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated companies.</response> | ||||||
|  |         /// <response code="404">The user or company not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost] | ||||||
|  |         [Route(Routes.AddCompany)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> AddCompanyToUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.AddCompanyToUser(userId, companyId, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes a company from the user's list of companies. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="companyId">The company identifier to remove.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated companies.</response> | ||||||
|  |         /// <response code="404">The user or company not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.RemoveCompany)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> RemoveCompanyFromUserAsync([FromRoute] string userId, [FromRoute] string companyId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.RemoveCompanyFromUser(userId, companyId, cancellationToken).ConfigureAwait(false); ; | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds a project to the user's list of projects. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="projectId">The project identifier to add.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated projects.</response> | ||||||
|  |         /// <response code="404">The user or project not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpPost] | ||||||
|  |         [Route(Routes.AddProject)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> AddProjectToUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.AddProjectToUser(userId, projectId, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes a project from the user's list of projects. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The user identifier.</param> | ||||||
|  |         /// <param name="projectId">The project identifier to remove.</param> | ||||||
|  |         /// <returns>The updated <see cref="UserAdapter"/> entity.</returns> | ||||||
|  |         /// <response code="200">The user with the updated projects.</response> | ||||||
|  |         /// <response code="404">The user or project not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpDelete] | ||||||
|  |         [Route(Routes.RemoveProject)] | ||||||
|  |         [ProducesResponseType(typeof(UserAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = Schemes.DefaultScheme)] | ||||||
|  |         //[Permission("UserManagement.Write")] | ||||||
|  |         public async Task<IActionResult> RemoveProjectFromUserAsync([FromRoute] string userId, [FromRoute] string projectId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var result = await service.RemoveProjectFromUser(userId, projectId, cancellationToken).ConfigureAwait(false); | ||||||
|  |             return Ok(result); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets a token for the user, including roles, permissions, and modules. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="email">The user's email.</param> | ||||||
|  |         /// <returns>The token adapter with user details, role, permissions, and modules.</returns> | ||||||
|  |         /// <response code="200">The token adapter with user details.</response> | ||||||
|  |         /// <response code="404">The user not found.</response> | ||||||
|  |         /// <response code="500">The service internal error.</response> | ||||||
|  |         [HttpGet] | ||||||
|  |         [Route("{email}/GetTokenAdapter")] | ||||||
|  |         [ProducesResponseType(typeof(TokenAdapter), StatusCodes.Status200OK)] | ||||||
|  |         //[Authorize(AuthenticationSchemes = $"{Schemes.DefaultScheme}, {Schemes.AzureScheme}")] | ||||||
|  |         public async Task<IActionResult> GetTokenAdapter([FromRoute] string email, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var tokenAdapter = await service.GetToken(email, cancellationToken).ConfigureAwait(false); | ||||||
|  |  | ||||||
|  |             if (tokenAdapter == null) return NotFound($"User with email: {email} not found"); | ||||||
|  |  | ||||||
|  |             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 | ||||||
|  |  | ||||||
|  | ### | ||||||
| @@ -15,12 +15,12 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" /> |     <PackageReference Include="Core.Blueprint.Logging" Version="1.0.0" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <ProjectReference Include="..\Core.Cerberos.Domain\Core.Cerberos.Domain.csproj" /> |     <ProjectReference Include="..\Core.Thalos.Domain\Core.Thalos.Domain.csproj" /> | ||||||
|     <ProjectReference Include="..\Core.Cerberos.Provider\Core.Cerberos.Provider.csproj" /> |     <ProjectReference Include="..\Core.Thalos.Provider\Core.Thalos.Provider.csproj" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </Project> | ||||||
							
								
								
									
										71
									
								
								Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Core.Thalos.DAL.API/Extensions/SwaggerExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | |||||||
|  | using Asp.Versioning.ApiExplorer; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using Microsoft.OpenApi.Any; | ||||||
|  | using Swashbuckle.AspNetCore.SwaggerGen; | ||||||
|  | using Swashbuckle.AspNetCore.SwaggerUI; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.DAL.API.Extensions | ||||||
|  | { | ||||||
|  |     public static class SwaggerExtensions | ||||||
|  |     { | ||||||
|  |         public static void AddSwagger(this IServiceCollection services) | ||||||
|  |         { | ||||||
|  |             services.AddEndpointsApiExplorer(); | ||||||
|  |             services.AddSwaggerGen(); | ||||||
|  |             services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>(); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public static void ConfigureSwagger(this WebApplication app) | ||||||
|  |         { | ||||||
|  |             app.UseSwagger(); | ||||||
|  |             app.UseSwaggerUI(options => | ||||||
|  |             { | ||||||
|  |                 foreach (var version in app.DescribeApiVersions().Select(version => version.GroupName)) | ||||||
|  |                     options.SwaggerEndpoint($"/swagger/{version}/swagger.json", version); | ||||||
|  |  | ||||||
|  |                 options.DisplayRequestDuration(); | ||||||
|  |                 options.EnableTryItOutByDefault(); | ||||||
|  |                 options.DocExpansion(DocExpansion.None); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |         public static IServiceCollection AddVersioning(this IServiceCollection services) | ||||||
|  |         { | ||||||
|  |             services.AddApiVersioning(options => options.ReportApiVersions = true) | ||||||
|  |                    .AddApiExplorer(options => | ||||||
|  |                    { | ||||||
|  |                        options.GroupNameFormat = "'v'VVV"; | ||||||
|  |                        options.SubstituteApiVersionInUrl = true; | ||||||
|  |                    }); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> | ||||||
|  |     { | ||||||
|  |         private readonly IApiVersionDescriptionProvider _provider; | ||||||
|  |  | ||||||
|  |         public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) | ||||||
|  |         { | ||||||
|  |             _provider = provider; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public void Configure(SwaggerGenOptions options) | ||||||
|  |         { | ||||||
|  |             foreach (var description in _provider.ApiVersionDescriptions) | ||||||
|  |                 options.SwaggerDoc(description.GroupName, new() | ||||||
|  |                 { | ||||||
|  |                     Title = AppDomain.CurrentDomain.FriendlyName, | ||||||
|  |                     Version = description.ApiVersion.ToString() | ||||||
|  |                 }); | ||||||
|  |  | ||||||
|  |             //Map ALL Values Format TODO | ||||||
|  |             options.MapType<DateOnly>(() => new() | ||||||
|  |             { | ||||||
|  |                 Format = "date", | ||||||
|  |                 Example = new OpenApiString(DateOnly.MinValue.ToString()) | ||||||
|  |             }); | ||||||
|  |  | ||||||
|  |             options.CustomSchemaIds(type => type.ToString().Replace("+", ".")); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										82
									
								
								Core.Thalos.DAL.API/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								Core.Thalos.DAL.API/Program.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,82 @@ | |||||||
|  | using Core.Blueprint.Caching.Configuration; | ||||||
|  | using Core.Blueprint.DAL.Mongo.Configuration; | ||||||
|  | using Core.Blueprint.Logging.Configuration; | ||||||
|  | using Core.Thalos.Adapters.Extensions; | ||||||
|  | using Core.Thalos.DAL.API.Extensions; | ||||||
|  | using Core.Thalos.Provider; | ||||||
|  | using Microsoft.AspNetCore.HttpLogging; | ||||||
|  | using System.Reflection; | ||||||
|  | using System.Text.Json.Serialization; | ||||||
|  |  | ||||||
|  | var builder = WebApplication.CreateBuilder(args); | ||||||
|  |  | ||||||
|  | builder.Services.AddEndpointsApiExplorer(); | ||||||
|  | builder.Services.AddSwaggerGen(); | ||||||
|  | builder.Configuration | ||||||
|  |     .AddUserSecrets(Assembly.GetExecutingAssembly()) | ||||||
|  |     .AddEnvironmentVariables(); | ||||||
|  |  | ||||||
|  | builder.Services.AddResponseCompression(); | ||||||
|  | builder.Services.AddProblemDetails(); | ||||||
|  | builder.Services.AddMemoryCache(); | ||||||
|  | builder.Services.AddLogs(builder); | ||||||
|  | builder.Services.AddRedis(builder.Configuration); | ||||||
|  | builder.Services.AddMongoLayer(builder.Configuration); | ||||||
|  | builder.Services.AddDALLayerServices(builder.Configuration); | ||||||
|  |  | ||||||
|  | builder.Host.ConfigureServices((context, services) => | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     services.AddLogging(); | ||||||
|  |     services.AddControllers(); | ||||||
|  |     services.AddProblemDetails(); | ||||||
|  |     services.AddCors(options | ||||||
|  |         => options.AddDefaultPolicy(policyBuilder | ||||||
|  |             => policyBuilder | ||||||
|  |                 .AllowAnyOrigin() | ||||||
|  |                 .AllowAnyHeader() | ||||||
|  |                 .AllowAnyMethod())); | ||||||
|  |  | ||||||
|  |     builder.Services.Configure<Microsoft.AspNetCore.Http.Json.JsonOptions>(options => | ||||||
|  |     { | ||||||
|  |         options.SerializerOptions.Converters.Add(new JsonStringEnumConverter()); | ||||||
|  |     }); | ||||||
|  |  | ||||||
|  |     services | ||||||
|  |         .AddEndpointsApiExplorer() | ||||||
|  |         .AddVersioning() | ||||||
|  |         .AddSwagger(); | ||||||
|  |  | ||||||
|  |     services.AddHealthChecks(); | ||||||
|  |     services.AddHttpLogging(options => options.LoggingFields = HttpLoggingFields.All); | ||||||
|  |  | ||||||
|  |     builder.Services.AddOutputCache(options => | ||||||
|  |     { | ||||||
|  |         options.AddBasePolicy(builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(10))); | ||||||
|  |         options.AddPolicy("Expire20", builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(20))); | ||||||
|  |         options.AddPolicy("Expire30", builder => | ||||||
|  |             builder.Expire(TimeSpan.FromSeconds(30))); | ||||||
|  |     }); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | var app = builder.Build(); | ||||||
|  |  | ||||||
|  | app.UseSwagger(); | ||||||
|  | app.UseSwaggerUI(); | ||||||
|  | app.UseAuthentication(); | ||||||
|  | app.UseAuthorization(); | ||||||
|  | app.MapControllers(); | ||||||
|  | app.UseCors(); | ||||||
|  | app.ConfigureSwagger(); | ||||||
|  | app.UseHttpsRedirection(); | ||||||
|  | app.UseStaticFiles(); | ||||||
|  | app.UseRouting(); | ||||||
|  | app.UseResponseCompression(); | ||||||
|  | app.UseOutputCache(); | ||||||
|  | app.UseResponseCaching(); | ||||||
|  | app.UseLogging(builder.Configuration); | ||||||
|  | app.MapHealthChecks("/health"); | ||||||
|  |  | ||||||
|  | app.Run(); | ||||||
							
								
								
									
										22
									
								
								Core.Thalos.DAL.API/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Core.Thalos.DAL.API/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://localhost:27017", | ||||||
|  |     "Redis": "localhost:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										22
									
								
								Core.Thalos.DAL.API/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								Core.Thalos.DAL.API/appsettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | { | ||||||
|  |   "Logging": { | ||||||
|  |     "LogLevel": { | ||||||
|  |       "Default": "Information", | ||||||
|  |       "Microsoft.AspNetCore": "Warning" | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "AllowedHosts": "*", | ||||||
|  |   "ConnectionStrings": { | ||||||
|  |     "MongoDB": "mongodb://admin_agile:Admin%40agileWebs@portainer.white-enciso.pro:27017/?authMechanism=SCRAM-SHA-256", | ||||||
|  |     "Redis": "localhost:6379" | ||||||
|  |   }, | ||||||
|  |   "MongoDb": { | ||||||
|  |     "DatabaseName": "Thalos", | ||||||
|  |     "LocalAudience": "" | ||||||
|  |   }, | ||||||
|  |   "DetailedErrors": true, | ||||||
|  |   "UseRedisCache": true, | ||||||
|  |   "CacheSettings": { | ||||||
|  |     "DefaultCacheDurationInMinutes": 3 | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -5,7 +5,7 @@ | |||||||
|     "KeyVault": "" //KeyVault Uri |     "KeyVault": "" //KeyVault Uri | ||||||
|   }, |   }, | ||||||
|   "MongoDb": { |   "MongoDb": { | ||||||
|     "DatabaseName": "Cerberos" |     "DatabaseName": "Thalos" | ||||||
|   }, |   }, | ||||||
|   "CacheSettings": { |   "CacheSettings": { | ||||||
|     "DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes |     "DefaultCacheDurationInMinutes": 3 // Default cache duration set to 3 minutes | ||||||
| @@ -22,11 +22,11 @@ | |||||||
|     "CallbackPath": "", // Path for redirect after authentication |     "CallbackPath": "", // Path for redirect after authentication | ||||||
|     "Scopes": "" // Access scopes for user permissions |     "Scopes": "" // Access scopes for user permissions | ||||||
|   }, |   }, | ||||||
|   "HeathCerberosApp": { |   "ThalosApp": { | ||||||
|     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) |     "AuthorizationUrl": "", // URL for authorization endpoint (STORED IN KEY VAULT) | ||||||
|     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) |     "TokenUrl": "", // URL for token endpoint (STORED IN KEY VAULT) | ||||||
|     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) |     "Scope": "", // Scope for application permissions (STORED IN KEY VAULT) | ||||||
|     "ClientId": "" // Client ID for Kerberos application (STORED IN KEY VAULT) |     "ClientId": "" // Client ID for Thalos application (STORED IN KEY VAULT) | ||||||
|   }, |   }, | ||||||
|   "MicrosoftGraph": { |   "MicrosoftGraph": { | ||||||
|     "Scopes": "", // Scopes for Microsoft Graph API access |     "Scopes": "", // Scopes for Microsoft Graph API access | ||||||
| @@ -1,14 +1,14 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="ModuleMapper.cs"> | // <copyright file="ModuleMapper.cs"> | ||||||
| //    HEATH | //    AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Microsoft.AspNetCore.Http; | using Microsoft.AspNetCore.Http; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using System.Security.Claims; | using System.Security.Claims; | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles mappings between |     /// Handles mappings between | ||||||
| @@ -1,14 +1,14 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="PermissionMapper.cs"> | // <copyright file="PermissionMapper.cs"> | ||||||
| //    HEATH | //    AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Microsoft.AspNetCore.Http; | using Microsoft.AspNetCore.Http; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using System.Security.Claims; | using System.Security.Claims; | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles mappings between |     /// Handles mappings between | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="RoleMapper.cs"> | // <copyright file="RoleMapper.cs"> | ||||||
| //    HEATH | //    AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Microsoft.AspNetCore.Http; | using Microsoft.AspNetCore.Http; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using System.Security.Claims; | using System.Security.Claims; | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles mappings between |     /// Handles mappings between | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="UserMapper.cs"> | // <copyright file="UserMapper.cs"> | ||||||
| //    HEATH | //    AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Microsoft.AspNetCore.Http; | using Microsoft.AspNetCore.Http; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using System.Security.Claims; | using System.Security.Claims; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Mappers | namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Handles mappings between |     /// Handles mappings between | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="ModuleRequest.cs"> | // <copyright file="ModuleRequest.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding modules. |     /// Data transfer object (DTO) for adding modules. | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="PermissionRequest.cs"> | // <copyright file="PermissionRequest.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Core.Cerberos.Adapters.Common.Constants; | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding permissions. |     /// Data transfer object (DTO) for adding permissions. | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="RoleRequest.cs"> | // <copyright file="RoleRequest.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using MongoDB.Bson; | using MongoDB.Bson; | ||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding a role. |     /// Data transfer object (DTO) for adding a role. | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="UserAddDto.cs"> | // <copyright file="UserAddDto.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| @@ -8,7 +8,7 @@ using MongoDB.Bson; | |||||||
| using MongoDB.Bson.Serialization.Attributes; | using MongoDB.Bson.Serialization.Attributes; | ||||||
| using System.Text.Json.Serialization; | using System.Text.Json.Serialization; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Domain.Contexts.Onboarding.Request | namespace Core.Thalos.Domain.Contexts.Onboarding.Request | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Data transfer object (DTO) for adding a user. |     /// Data transfer object (DTO) for adding a user. | ||||||
| @@ -7,7 +7,7 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" /> |     <PackageReference Include="Core.Thalos.BuildingBlocks" Version="1.0.2" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </Project> | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| using Core.Cerberos.Infraestructure.Caching.Configs; | using Core.Thalos.Infraestructure.Caching.Configs; | ||||||
| 
 | 
 | ||||||
| namespace LSA.Core.Dapper.Service.Caching | namespace LSA.Core.Dapper.Service.Caching | ||||||
| { | { | ||||||
| @@ -1,5 +1,5 @@ | |||||||
| using Azure.Identity; | using Azure.Identity; | ||||||
| using Core.Cerberos.Infraestructure.Caching.Contracts; | using Core.Thalos.Infraestructure.Caching.Contracts; | ||||||
| using Microsoft.Extensions.Logging; | using Microsoft.Extensions.Logging; | ||||||
| using StackExchange.Redis; | using StackExchange.Redis; | ||||||
| using System.Text.Json; | using System.Text.Json; | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| namespace Core.Cerberos.Infraestructure.Caching.Configs | namespace Core.Thalos.Infraestructure.Caching.Configs | ||||||
| { | { | ||||||
|     public class CacheSettings |     public class CacheSettings | ||||||
|     { |     { | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| namespace Core.Cerberos.Infraestructure.Caching.Contracts | namespace Core.Thalos.Infraestructure.Caching.Contracts | ||||||
| { | { | ||||||
|     public interface ICacheService |     public interface ICacheService | ||||||
|     { |     { | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| using Microsoft.Extensions.Configuration; | using Microsoft.Extensions.Configuration; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Infraestructure.Contexts.Mongo | namespace Core.Thalos.Infraestructure.Contexts.Mongo | ||||||
| { | { | ||||||
|     public class ConnectionStringProvider(IConfiguration configuration) : IConnectionStringProvider |     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 | public interface IMongoConnSettings | ||||||
| { | { | ||||||
| @@ -7,7 +7,6 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Core.Cerberos.Adapters" Version="0.3.0-alpha0042" /> |  | ||||||
|     <PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" /> |     <PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" /> | ||||||
|     <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" /> |     <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" /> | ||||||
|     <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" /> |     <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" /> | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| namespace Core.Cerberos.Infraestructure.PerformanceCacheService | namespace Core.Thalos.Infraestructure.PerformanceCacheService | ||||||
| { | { | ||||||
|     [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] |     [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)] | ||||||
|     public class CacheAttribute : Attribute |     public class CacheAttribute : Attribute | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="IModuleService.cs"> | // <copyright file="IModuleService.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Cerberos.Adapters; | using Core.Blueprint.Mongo; | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|     public interface IModuleService |     public interface IModuleProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Module. |         /// Creates a new Module. | ||||||
| @@ -17,7 +17,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="entity">The Module to be created.</param> |         /// <param name="entity">The Module to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<ModuleAdapter> CreateModuleService(ModuleRequest newModule); |         ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Module by identifier. |         /// Gets an Module by identifier. | ||||||
| @@ -25,14 +25,14 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The Module identifier.</param> |         /// <param name="id">The Module identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<ModuleAdapter> GetModuleByIdService(string id); |         ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all the roles. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing |         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<IEnumerable<ModuleAdapter>> GetAllModulesService(); |         ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions by permissions identifier list. |         /// Gets all the permissions by permissions identifier list. | ||||||
| @@ -40,7 +40,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |         /// <param name="permissions">The list of permissions identifiers.</param> | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing |         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<IEnumerable<ModuleAdapter>> GetAllModulesByListService(string[] permissions); |         ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the permission. |         /// Changes the status of the permission. | ||||||
| @@ -50,7 +50,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="ModuleAdapter"/> updated entity.</returns> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<ModuleAdapter> ChangeModuleStatusService(string id, StatusEnum newStatus); |         ValueTask<ModuleAdapter> ChangeModuleStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Module by id. |         /// Updates a Module by id. | ||||||
| @@ -59,6 +59,6 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The Module identifier.</param> |         /// <param name="id">The Module identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<ModuleAdapter> UpdateModuleService(ModuleAdapter entity, string id); |         ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="IPermissionService.cs"> | // <copyright file="IPermissionService.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Cerberos.Adapters; | using Core.Blueprint.Mongo; | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|     public interface IPermissionService |     public interface IPermissionProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Permission. |         /// Creates a new Permission. | ||||||
| @@ -17,7 +17,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="entity">The Permission to be created.</param> |         /// <param name="entity">The Permission to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<PermissionAdapter> CreatePermissionService(PermissionRequest newPermission); |         ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Permission by identifier. |         /// Gets an Permission by identifier. | ||||||
| @@ -25,14 +25,14 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The Permission identifier.</param> |         /// <param name="id">The Permission identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<PermissionAdapter> GetPermissionByIdService(string id); |         ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all the roles. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing |         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<IEnumerable<PermissionAdapter>> GetAllPermissionsService(); |         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the permissions by permissions identifier list. |         /// Gets all the permissions by permissions identifier list. | ||||||
| @@ -40,7 +40,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="permissions">The list of permissions identifiers.</param> |         /// <param name="permissions">The list of permissions identifiers.</param> | ||||||
|         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing |         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<IEnumerable<PermissionAdapter>> GetAllPermissionsByListService(string[] permissions); |         ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the permission. |         /// Changes the status of the permission. | ||||||
| @@ -50,7 +50,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="PermissionAdapter"/> updated entity.</returns> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<PermissionAdapter> ChangePermissionStatusService(string id, StatusEnum newStatus); |         ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Permission by id. |         /// Updates a Permission by id. | ||||||
| @@ -59,6 +59,6 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The Permission identifier.</param> |         /// <param name="id">The Permission identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<PermissionAdapter> UpdatePermissionService(PermissionAdapter entity, string id); |         ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -1,15 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="IRoleService.cs"> | // <copyright file="IRoleService.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Adapters.Common.Enums; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|     public interface IRoleService |     public interface IRoleProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new Role. |         /// Creates a new Role. | ||||||
| @@ -17,7 +17,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="entity">The Role to be created.</param> |         /// <param name="entity">The Role to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<RoleAdapter> CreateRoleService(RoleRequest newRole); |         ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an Role by identifier. |         /// Gets an Role by identifier. | ||||||
| @@ -25,14 +25,14 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The Role identifier.</param> |         /// <param name="id">The Role identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<RoleAdapter> GetRoleByIdService(string id); |         ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets all the roles. |         /// Gets all the roles. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing |         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<IEnumerable<RoleAdapter>> GetAllRolesService(); |         ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the role. |         /// Changes the status of the role. | ||||||
| @@ -42,7 +42,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> |         /// <returns>The <see cref="RoleAdapter"/> updated entity.</returns> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<RoleAdapter> ChangeRoleStatusService(string id, StatusEnum newStatus); |         ValueTask<RoleAdapter> ChangeRoleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a Role by id. |         /// Updates a Role by id. | ||||||
| @@ -51,7 +51,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The Role identifier.</param> |         /// <param name="id">The Role identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<RoleAdapter> UpdateRoleService(RoleAdapter entity, string id); |         ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Adds an application to the role's list of applications. |         /// Adds an application to the role's list of applications. | ||||||
| @@ -59,7 +59,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="roleId">The identifier of the role to which the application will be added.</param> |         /// <param name="roleId">The identifier of the role to which the application will be added.</param> | ||||||
|         /// <param name="application">The application enum value to add.</param> |         /// <param name="application">The application enum value to add.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||||
|         Task<RoleAdapter> AddApplicationToRoleService(string roleId, ApplicationsEnum application); |         ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Removes an application from the role's list of applications. |         /// Removes an application from the role's list of applications. | ||||||
| @@ -67,6 +67,6 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> |         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> | ||||||
|         /// <param name="application">The application enum value to remove.</param> |         /// <param name="application">The application enum value to remove.</param> | ||||||
|         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||||
|         Task<RoleAdapter> RemoveApplicationFromRoleService(string roleId, ApplicationsEnum application); |         ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -1,16 +1,15 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="IUserService.cs"> | // <copyright file="IUserService.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| using Core.Blueprint.Storage.Adapters; | using Core.Blueprint.Mongo; | ||||||
| using Core.Cerberos.Adapters; | using Core.Thalos.Adapters; | ||||||
| using Core.Cerberos.Adapters.Common.Enums; | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
| using Core.Cerberos.Domain.Contexts.Onboarding.Request; |  | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Contracts | namespace Core.Thalos.Provider.Contracts | ||||||
| { | { | ||||||
|     public interface IUserService |     public interface IUserProvider | ||||||
|     { |     { | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Creates a new User. |         /// Creates a new User. | ||||||
| @@ -18,7 +17,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="entity">The User to be created.</param> |         /// <param name="entity">The User to be created.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter> CreateUserService(UserRequest newUser); |         ValueTask<UserAdapter> CreateUser(UserRequest newUser, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an User by identifier. |         /// Gets an User by identifier. | ||||||
| @@ -26,7 +25,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="id">The User identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter> GetUserByIdService(string id); |         ValueTask<UserAdapter> GetUserById(string _id, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
| @@ -34,7 +33,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing |         /// <returns>A <see cref="{Task{IEnumerable{UserAdapter}}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<IEnumerable<UserAdapter>> GetAllUsersService(); |         ValueTask<IEnumerable<UserAdapter>> GetAllUsers(CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Gets an User by email. |         /// Gets an User by email. | ||||||
| @@ -42,7 +41,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="email">The User email.</param> |         /// <param name="email">The User email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter> GetUserByEmailService(string? email); |         ValueTask<UserAdapter> GetUserByEmail(string? email, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Validates if a users exists by email. |         /// Validates if a users exists by email. | ||||||
| @@ -50,7 +49,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="eamil">The User email.</param> |         /// <param name="eamil">The User email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter> ValidateUserExistenceService(string? email); |         ValueTask<UserExistenceAdapter> ValidateUserExistence(string? email, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Changes the status of the user. |         /// 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> |         /// <param name="newStatus">The new status of the user.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter> ChangeUserStatusService(string id, StatusEnum newStatus); |         ValueTask<UserAdapter> ChangeUserStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Updates a User by id. |         /// Updates a User by id. | ||||||
| @@ -68,7 +67,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="id">The User identifier.</param> |         /// <param name="id">The User identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter> UpdateUserService(UserAdapter entity, string id); |         ValueTask<UserAdapter> UpdateUser(UserAdapter entity, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Logs in the user. |         /// Logs in the user. | ||||||
| @@ -76,7 +75,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="email">The User's email.</param> |         /// <param name="email">The User's email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter?> LogInUserService(string email); |         ValueTask<UserAdapter?> LogInUser(string email, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Logs out the user's session. |         /// Logs out the user's session. | ||||||
| @@ -84,7 +83,7 @@ namespace Core.Cerberos.Provider.Contracts | |||||||
|         /// <param name="email">The User's email.</param> |         /// <param name="email">The User's email.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter> LogOutUserSessionService(string email); |         ValueTask<UserAdapter?> LogOutUserSession(string email, CancellationToken cancellationToken); | ||||||
| 
 | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Adds a company to the user's list of companies. |         /// 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="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> |         /// <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> |         /// <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> |         /// <summary> | ||||||
|         /// Removes a company from the user's list of companies. |         /// 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="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> |         /// <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> |         /// <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> |         /// <summary> | ||||||
|         /// Adds a project to the user's list of projects. |         /// 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="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> |         /// <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> |         /// <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> |         /// <summary> | ||||||
| @@ -117,27 +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="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> |         /// <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> |         /// <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> |         /// <summary> | ||||||
|         /// Gets the token adapter for a user. |         /// Gets the token adapter for a user. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         /// <param name="email">The user's email.</param> |         /// <param name="email">The user's email.</param> | ||||||
|         /// <returns>A <see cref="{Task{TokenAdapter}}"/> representing the asynchronous execution of the service.</returns> |         /// <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> |         /// <summary> | ||||||
|         /// Get Consent Form PDF. |         /// Delete an User by identifier. | ||||||
|         /// </summary> |  | ||||||
|         /// <returns>A <see cref="{Task{BlobDownloadUriAdapter}}"/> representing |  | ||||||
|         /// the asynchronous execution of the service.</returns> |  | ||||||
|         Task<BlobDownloadUriAdapter> GetConsentFormPDFService(); |  | ||||||
| 
 |  | ||||||
|         /// <summary> |  | ||||||
|         /// Accept user consent form. |  | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  |         /// <param name="id">The User identifier.</param> | ||||||
|         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing |         /// <returns>A <see cref="{Task{UserAdapter}}"/> representing | ||||||
|         /// the asynchronous execution of the service.</returns> |         /// the asynchronous execution of the service.</returns> | ||||||
|         Task<UserAdapter?> AcceptUserConsentFormService(); |         ValueTask<UserAdapter> DeleteUser(string _id, CancellationToken cancellationToken); | ||||||
|     } |     } | ||||||
| } | } | ||||||
							
								
								
									
										24
									
								
								Core.Thalos.Provider/Core.Thalos.Provider.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Core.Thalos.Provider/Core.Thalos.Provider.csproj
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | |||||||
|  | <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.Mongo" Version="1.0.0" /> | ||||||
|  |     <PackageReference Include="Core.Blueprint.Redis" Version="1.0.0" /> | ||||||
|  |     <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; | using MongoDB.Driver; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Providers | namespace Core.Thalos.Provider.Providers | ||||||
| { | { | ||||||
|     public class BaseProvider |     public class BaseProvider | ||||||
|     { |     { | ||||||
| @@ -1,9 +1,9 @@ | |||||||
| using Azure.Core; | using Azure.Core; | ||||||
| using Azure.Identity; | using Azure.Identity; | ||||||
| using Core.Cerberos.Adapters.Common.Constants; | using Core.Thalos.Adapters.Common.Constants; | ||||||
| using MongoDB.Driver.Authentication.Oidc; | using MongoDB.Driver.Authentication.Oidc; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Providers | namespace Core.Thalos.Provider.Providers | ||||||
| { | { | ||||||
|     public class HeathOidcCallback : IOidcCallback |     public class HeathOidcCallback : IOidcCallback | ||||||
|     { |     { | ||||||
| @@ -1,13 +1,13 @@ | |||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| // <copyright file="Helper.cs"> | // <copyright file="Helper.cs"> | ||||||
| //     Heath | //     AgileWebs | ||||||
| // </copyright> | // </copyright> | ||||||
| // *********************************************************************** | // *********************************************************************** | ||||||
| 
 | 
 | ||||||
| using Microsoft.AspNetCore.Http; | using Microsoft.AspNetCore.Http; | ||||||
| using System.Security.Claims; | using System.Security.Claims; | ||||||
| 
 | 
 | ||||||
| namespace Core.Cerberos.Provider.Providers | namespace Core.Thalos.Provider.Providers | ||||||
| { | { | ||||||
|     /// <summary> |     /// <summary> | ||||||
|     /// Provides helper methods for common operations. |     /// Provides helper methods for common operations. | ||||||
							
								
								
									
										155
									
								
								Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										155
									
								
								Core.Thalos.Provider/Providers/Onboarding/ModuleProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,155 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="ModuleService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Blueprint.Caching.Helpers; | ||||||
|  | using Mapster; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using MongoDB.Driver; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Blueprint.Caching.Contracts; | ||||||
|  | using Core.Blueprint.Caching.Adapters; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="ModuleAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class ModuleProvider : IModuleProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<ModuleAdapter> repository; | ||||||
|  |         private readonly CacheSettings cacheSettings; | ||||||
|  |         private readonly ICacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  |         public ModuleProvider(CollectionRepository<ModuleAdapter> repository, | ||||||
|  |             ICacheProvider cacheProvider, | ||||||
|  |             IOptions<CacheSettings> cacheSettings) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  |             this.cacheSettings = cacheSettings.Value; | ||||||
|  |             this.cacheProvider = cacheProvider; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Module. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Module to be created.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<ModuleAdapter> CreateModule(ModuleRequest newModule, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var moduleCollection = newModule.Adapt<ModuleAdapter>(); | ||||||
|  |  | ||||||
|  |             await repository.InsertOneAsync(moduleCollection); | ||||||
|  |  | ||||||
|  |             return moduleCollection; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets an Module by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="id">The Module identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns>0 | ||||||
|  |         public async ValueTask<ModuleAdapter> GetModuleById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModuleById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<ModuleAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|  |             var module = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, module); | ||||||
|  |  | ||||||
|  |             return module; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the modules. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <returns>A <see cref="{Task{IEnumerbale{ModuleAdapter}}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModules(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetModules"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var modules = await repository.AsQueryable(); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, modules); | ||||||
|  |  | ||||||
|  |             return modules; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the modules by modules identifier list. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="modules">The list of modules identifiers.</param> | ||||||
|  |         /// <returns>A <see cref="Task{IEnumerable{ModuleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<IEnumerable<ModuleAdapter>> GetAllModulesByList(string[] modules, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllModulesByList", modules); | ||||||
|  |  | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<ModuleAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var builder = Builders<ModuleAdapter>.Filter; | ||||||
|  |             var filters = new List<FilterDefinition<ModuleAdapter>>(); | ||||||
|  |  | ||||||
|  |             if (modules != null || !modules.Any()) | ||||||
|  |             { | ||||||
|  |                 filters.Add(builder.In(x => x._Id, modules)); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|  |  | ||||||
|  |             var modulesList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, modulesList); | ||||||
|  |  | ||||||
|  |             return modulesList; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the module. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="id">The module identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the module.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<ModuleAdapter> ChangeModuleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(id); | ||||||
|  |             entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(entity); | ||||||
|  |  | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Module by id. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Module to be updated.</param> | ||||||
|  |         /// <param name="id">The Module identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{ModuleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<ModuleAdapter> UpdateModule(ModuleAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             await repository.ReplaceOneAsync(entity); | ||||||
|  |  | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										156
									
								
								Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										156
									
								
								Core.Thalos.Provider/Providers/Onboarding/PermissionProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,156 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="PermissionService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using Core.Blueprint.Caching.Adapters; | ||||||
|  | using Core.Blueprint.Caching.Contracts; | ||||||
|  | using Core.Blueprint.Caching.Helpers; | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using MongoDB.Driver; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="PermissionAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class PermissionProvider : IPermissionProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<PermissionAdapter> repository; | ||||||
|  |         private readonly CacheSettings cacheSettings; | ||||||
|  |         private readonly ICacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  |         public PermissionProvider(CollectionRepository<PermissionAdapter> repository, | ||||||
|  |             ICacheProvider cacheProvider, | ||||||
|  |             IOptions<CacheSettings> cacheSettings | ||||||
|  |             ) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  |             this.cacheSettings = cacheSettings.Value; | ||||||
|  |             this.cacheProvider = cacheProvider; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Permission to be created.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<PermissionAdapter> CreatePermission(PermissionRequest newPermission, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var permissionCollection = newPermission.Adapt<PermissionAdapter>(); | ||||||
|  |  | ||||||
|  |             await repository.InsertOneAsync(permissionCollection); | ||||||
|  |  | ||||||
|  |             return permissionCollection; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets an Permission by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="id">The Permission identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns>0 | ||||||
|  |         public async ValueTask<PermissionAdapter> GetPermissionById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetPermissionById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<PermissionAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             //if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|  |             var permission = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, permission); | ||||||
|  |  | ||||||
|  |             return permission; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the permissions. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <returns>A <see cref="{Task{IEnumerbale{PermissionAdapter}}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissions(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissions"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var permissions = await repository.AsQueryable(); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, permissions); | ||||||
|  |  | ||||||
|  |             return permissions; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the permissions by permissions identifier list. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="permissions">The list of permissions identifiers.</param> | ||||||
|  |         /// <returns>A <see cref="Task{IEnumerable{PermissionAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<IEnumerable<PermissionAdapter>> GetAllPermissionsByList(string[] permissions, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllPermissionsByList", permissions); | ||||||
|  |  | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<PermissionAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var builder = Builders<PermissionAdapter>.Filter; | ||||||
|  |             var filters = new List<FilterDefinition<PermissionAdapter>>(); | ||||||
|  |  | ||||||
|  |             if (permissions != null || !permissions.Any()) | ||||||
|  |             { | ||||||
|  |                 filters.Add(builder.In(x => x._Id, permissions)); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             var finalFilter = filters.Any() ? builder.And(filters) : builder.Empty; | ||||||
|  |  | ||||||
|  |             var permissionsList = await repository.FilterByMongoFilterAsync(finalFilter); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, permissionsList); | ||||||
|  |  | ||||||
|  |             return permissionsList; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the permission. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="id">The permission identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the permission.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<PermissionAdapter> ChangePermissionStatus(string id, StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(id); | ||||||
|  |             entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(entity); | ||||||
|  |  | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Permission by id. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Permission to be updated.</param> | ||||||
|  |         /// <param name="id">The Permission identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{PermissionAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<PermissionAdapter> UpdatePermission(PermissionAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             await repository.ReplaceOneAsync(entity); | ||||||
|  |  | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										173
									
								
								Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								Core.Thalos.Provider/Providers/Onboarding/RoleProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,173 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="RoleService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  | using Core.Blueprint.Caching.Adapters; | ||||||
|  | using Core.Blueprint.Caching.Contracts; | ||||||
|  | using Core.Blueprint.Caching.Helpers; | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
|  | using Core.Thalos.Domain.Contexts.Onboarding.Request; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using Microsoft.Graph; | ||||||
|  | using MongoDB.Bson; | ||||||
|  | using MongoDB.Bson.Serialization; | ||||||
|  | using MongoDB.Driver; | ||||||
|  | using System.ComponentModel.Design; | ||||||
|  | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider.Providers.Onboarding | ||||||
|  | { | ||||||
|  |     /// <summary> | ||||||
|  |     /// Handles all services and business rules related to <see cref="RoleAdapter"/>. | ||||||
|  |     /// </summary> | ||||||
|  |     public class RoleProvider : IRoleProvider | ||||||
|  |     { | ||||||
|  |         private readonly CollectionRepository<RoleAdapter> repository; | ||||||
|  | 		private readonly CacheSettings cacheSettings; | ||||||
|  | 		private readonly ICacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  | 		public RoleProvider(CollectionRepository<RoleAdapter> repository, | ||||||
|  | 		    ICacheProvider cacheProvider, | ||||||
|  | 			IOptions<CacheSettings> cacheSettings | ||||||
|  | 			) | ||||||
|  |         { | ||||||
|  |             this.repository = repository; | ||||||
|  |             this.repository.CollectionInitialization(); | ||||||
|  | 			this.cacheSettings = cacheSettings.Value; | ||||||
|  | 			this.cacheProvider = cacheProvider; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Creates a new Role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Role to be created.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<RoleAdapter> CreateRole(RoleRequest newRole, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var roleCollection = newRole.Adapt<RoleAdapter>(); | ||||||
|  |  | ||||||
|  |             await repository.InsertOneAsync(roleCollection); | ||||||
|  |  | ||||||
|  |             return roleCollection; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets an Role by identifier. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="id">The Role identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<RoleAdapter> GetRoleById(string _id, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetRoleById", _id); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<RoleAdapter>(cacheKey); | ||||||
|  |  | ||||||
|  |             if (cachedData is not null) { return cachedData; } | ||||||
|  |  | ||||||
|  |             var role = await repository.FindByIdAsync(_id); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, role); | ||||||
|  |  | ||||||
|  |             return role; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Gets all the roles. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <returns>A <see cref="{Task{IEnumerbale{RoleAdapter}}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<IEnumerable<RoleAdapter>> GetAllRoles(CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var cacheKey = CacheKeyHelper.GenerateCacheKey(this, "GetAllRoles"); | ||||||
|  |             var cachedData = await cacheProvider.GetAsync<IEnumerable<RoleAdapter>>(cacheKey) ?? []; | ||||||
|  |  | ||||||
|  |             if (cachedData.Any()) return cachedData; | ||||||
|  |  | ||||||
|  |             var roles = await repository.AsQueryable(); | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, roles); | ||||||
|  |  | ||||||
|  |             return roles; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Changes the status of the role. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="id">The role identifier.</param> | ||||||
|  |         /// <param name="newStatus">The new status of the role.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<RoleAdapter> ChangeRoleStatus(string id, Core.Blueprint.Mongo.StatusEnum newStatus, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var entity = await repository.FindByIdAsync(id); | ||||||
|  |             entity.Status = newStatus; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(entity); | ||||||
|  |  | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Updates a Role by id. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="entity">The Role to be updated.</param> | ||||||
|  |         /// <param name="id">The Role identifier.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing | ||||||
|  |         /// the asynchronous execution of the service.</returns> | ||||||
|  |         public async ValueTask<RoleAdapter> UpdateRole(RoleAdapter entity, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             await repository.ReplaceOneAsync(entity); | ||||||
|  |  | ||||||
|  |             return entity; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Adds an application to the role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The identifier of the role to which the application will be added.</param> | ||||||
|  |         /// <param name="application">The application enum value to add.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||||
|  |         public async ValueTask<RoleAdapter> AddApplicationToRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var role = await repository.FindOneAsync( | ||||||
|  |                 u => u._Id == roleId && | ||||||
|  |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             var updatedApplications = role.Applications.Append(application).Distinct().ToArray(); | ||||||
|  |             role.Applications = updatedApplications; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(role); | ||||||
|  |  | ||||||
|  |             return role; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes an application from the role's list of applications. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="roleId">The identifier of the role from which the application will be removed.</param> | ||||||
|  |         /// <param name="application">The application enum value to remove.</param> | ||||||
|  |         /// <returns>A <see cref="{Task{RoleAdapter}}"/> representing the asynchronous operation, with the updated role object.</returns> | ||||||
|  |         public async ValueTask<RoleAdapter> RemoveApplicationFromRole(string roleId, ApplicationsEnum application, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var role = await repository.FindOneAsync( | ||||||
|  |                 u => u._Id == roleId && | ||||||
|  |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             var updatedApplications = role.Applications | ||||||
|  |                     ?.Where(c => c != application) | ||||||
|  |                     .ToArray(); | ||||||
|  |  | ||||||
|  |             role.Applications = updatedApplications; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(role); | ||||||
|  |  | ||||||
|  |             return role; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										532
									
								
								Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										532
									
								
								Core.Thalos.Provider/Providers/Onboarding/UserProvider.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,532 @@ | |||||||
|  | // *********************************************************************** | ||||||
|  | // <copyright file="UserService.cs"> | ||||||
|  | //     AgileWebs | ||||||
|  | // </copyright> | ||||||
|  | // *********************************************************************** | ||||||
|  |  | ||||||
|  | using Core.Blueprint.Caching.Adapters; | ||||||
|  | using Core.Blueprint.Caching.Contracts; | ||||||
|  | using Core.Blueprint.Caching.Helpers; | ||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Adapters.Common.Enums; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Mapster; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using MongoDB.Bson; | ||||||
|  | using MongoDB.Bson.Serialization; | ||||||
|  | using MongoDB.Driver; | ||||||
|  | using System.Reflection; | ||||||
|  | using System.Text.RegularExpressions; | ||||||
|  |  | ||||||
|  | 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 ICacheProvider cacheProvider; | ||||||
|  |  | ||||||
|  | 		public UserProvider(CollectionRepository<UserAdapter> repository, | ||||||
|  |             ICacheProvider 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<UserExistenceAdapter> 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); | ||||||
|  |  | ||||||
|  |             UserExistenceAdapter userExistance = new UserExistenceAdapter(); | ||||||
|  |  | ||||||
|  |             userExistance.Existence = (user != null) ? true : false; | ||||||
|  |  | ||||||
|  |             await cacheProvider.SetAsync(cacheKey, userExistance); | ||||||
|  |  | ||||||
|  |             return userExistance; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <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.Projects = updatedProjects; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(user); | ||||||
|  |  | ||||||
|  |             return user; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// Removes a project from the user's list of projects. | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="userId">The identifier of the user from whom the project will be removed.</param> | ||||||
|  |         /// <param name="projectId">The identifier of the project to remove.</param> | ||||||
|  |         /// <returns>A <see cref="Task{UserAdapter}"/> representing the asynchronous operation, with the updated user object.</returns> | ||||||
|  |         public async ValueTask<UserAdapter> RemoveProjectFromUser(string userId, string projectId, CancellationToken cancellationToken) | ||||||
|  |         { | ||||||
|  |             var user = await repository.FindOneAsync( | ||||||
|  |                 u => u._Id == userId && | ||||||
|  |                 u.Status == Core.Blueprint.Mongo.StatusEnum.Active); | ||||||
|  |  | ||||||
|  |             var updatedProjects = user.Projects | ||||||
|  |                     ?.Where(c => c != projectId) | ||||||
|  |                     .ToArray(); | ||||||
|  |  | ||||||
|  |             user.Projects = updatedProjects; | ||||||
|  |  | ||||||
|  |             await repository.ReplaceOneAsync(user); | ||||||
|  |  | ||||||
|  |             return user; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         /// <summary> | ||||||
|  |         /// 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.Contains("guid") && !result["guid"].IsBsonNull ? result["guid"].AsString : "", | ||||||
|  |                         Email = result.Contains("email") && !result["email"].IsBsonNull ? result["email"].AsString : "", | ||||||
|  |                         Name = result.Contains("name") && !result["name"].IsBsonNull ? result["name"].AsString : "", | ||||||
|  |                         MiddleName = result.Contains("middleName") && !result["middleName"].IsBsonNull ? result["middleName"].AsString : "", | ||||||
|  |                         LastName = result.Contains("lastName") && !result["lastName"].IsBsonNull ? result["lastName"].AsString : "", | ||||||
|  |                         DisplayName = result.Contains("displayName") && !result["displayName"].IsBsonNull ? result["displayName"].AsString : "", | ||||||
|  |                         RoleId = result.Contains("roleId") && !result["roleId"].IsBsonNull ? result["roleId"].ToString() : "", | ||||||
|  |                         Companies = result.Contains("companies") && result["companies"].IsBsonArray | ||||||
|  |                             ? result["companies"].AsBsonArray | ||||||
|  |                                 .Where(c => c != null && !c.IsBsonNull) | ||||||
|  |                                 .Select(c => c.AsString) | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                                         Projects = result.Contains("projects") && result["projects"].IsBsonArray | ||||||
|  |                             ? result["projects"].AsBsonArray | ||||||
|  |                                 .Where(p => p != null && !p.IsBsonNull) | ||||||
|  |                                 .Select(p => p.AsString) | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                         LastLogIn = result.Contains("lastLogIn") && !result["lastLogIn"].IsBsonNull ? result["lastLogIn"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         LastLogOut = result.Contains("lastLogOut") && !result["lastLogOut"].IsBsonNull ? result["lastLogOut"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         CreatedAt = result.Contains("createdAt") && !result["createdAt"].IsBsonNull ? result["createdAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         CreatedBy = result.Contains("createdBy") && !result["createdBy"].IsBsonNull ? result["createdBy"].AsString : "", | ||||||
|  |                         UpdatedAt = result.Contains("updatedAt") && !result["updatedAt"].IsBsonNull ? result["updatedAt"].ToUniversalTime() : DateTime.MinValue, | ||||||
|  |                         UpdatedBy = result.Contains("updatedBy") && !result["updatedBy"].IsBsonNull ? result["updatedBy"].AsString : "", | ||||||
|  |                         Status = result.Contains("status") && !result["status"].IsBsonNull | ||||||
|  |                             ? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["status"].AsString) | ||||||
|  |                             : Core.Blueprint.Mongo.StatusEnum.Inactive | ||||||
|  |                     }, | ||||||
|  |                     Role = new RoleAdapter | ||||||
|  |                     { | ||||||
|  |                         Id = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("_id") | ||||||
|  |                             ? result["role"]["_id"]?.ToString() ?? "" | ||||||
|  |                             : "", | ||||||
|  |                         Name = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("name") | ||||||
|  |                             ? result["role"]["name"]?.AsString ?? "" | ||||||
|  |                             : "", | ||||||
|  |                         Description = result.Contains("role") && result["role"].IsBsonDocument && result["role"].AsBsonDocument.Contains("description") | ||||||
|  |                             ? result["role"]["description"]?.AsString ?? "" | ||||||
|  |                             : "", | ||||||
|  |                         Applications = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                        result["role"].AsBsonDocument.Contains("applications") && | ||||||
|  |                        result["role"]["applications"].IsBsonArray | ||||||
|  |                             ? result["role"]["applications"].AsBsonArray | ||||||
|  |                                 .Where(app => app != null && app.IsInt32) | ||||||
|  |                                 .Select(app => (ApplicationsEnum)app.AsInt32) | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<ApplicationsEnum>(), | ||||||
|  |                         Modules = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("modules") && | ||||||
|  |                             result["role"]["modules"].IsBsonArray | ||||||
|  |                             ? result["role"]["modules"].AsBsonArray | ||||||
|  |                                 .Where(m => m != null) | ||||||
|  |                                 .Select(m => m.ToString() ?? "") | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                         Permissions = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("permissions") && | ||||||
|  |                             result["role"]["permissions"].IsBsonArray | ||||||
|  |                             ? result["role"]["permissions"].AsBsonArray | ||||||
|  |                                 .Where(p => p != null) | ||||||
|  |                                 .Select(p => p.ToString() ?? "") | ||||||
|  |                                 .ToArray() | ||||||
|  |                             : Array.Empty<string>(), | ||||||
|  |                         Status = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                              result["role"].AsBsonDocument.Contains("status") && | ||||||
|  |                              !result["role"]["status"].IsBsonNull | ||||||
|  |                             ? (Core.Blueprint.Mongo.StatusEnum)Enum.Parse(typeof(Core.Blueprint.Mongo.StatusEnum), result["role"]["status"].AsString) | ||||||
|  |                             : Core.Blueprint.Mongo.StatusEnum.Inactive, | ||||||
|  |                         CreatedAt = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("createdAt") && | ||||||
|  |                             !result["role"]["createdAt"].IsBsonNull | ||||||
|  |                             ? result["role"]["createdAt"].ToUniversalTime() | ||||||
|  |                             : DateTime.MinValue, | ||||||
|  |                         UpdatedAt = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("updatedAt") && | ||||||
|  |                             !result["role"]["updatedAt"].IsBsonNull | ||||||
|  |                             ? result["role"]["updatedAt"].ToUniversalTime() | ||||||
|  |                             : DateTime.MinValue, | ||||||
|  |                         CreatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("createdBy") && | ||||||
|  |                             !result["role"]["createdBy"].IsBsonNull | ||||||
|  |                             ? result["role"]["createdBy"].AsString | ||||||
|  |                             : "", | ||||||
|  |                         UpdatedBy = result.Contains("role") && result["role"].IsBsonDocument && | ||||||
|  |                             result["role"].AsBsonDocument.Contains("updatedBy") && | ||||||
|  |                             !result["role"]["updatedBy"].IsBsonNull | ||||||
|  |                             ? result["role"]["updatedBy"].AsString | ||||||
|  |                             : "" | ||||||
|  |                     }, | ||||||
|  |                     Permissions = result.Contains("permissions") && result["permissions"].IsBsonArray | ||||||
|  |                         ? result["permissions"].AsBsonArray | ||||||
|  |                             .Where(p => p != null && p.IsBsonDocument) | ||||||
|  |                             .Select(p => BsonSerializer.Deserialize<PermissionAdapter>(p.AsBsonDocument)) | ||||||
|  |                             .Where(p => p.Status == Core.Blueprint.Mongo.StatusEnum.Active) | ||||||
|  |                             .ToList() | ||||||
|  |                         : new List<PermissionAdapter>() | ||||||
|  |                 }; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |                 return tokenAdapter; | ||||||
|  |  | ||||||
|  |             } | ||||||
|  |             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; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										65
									
								
								Core.Thalos.Provider/ServiceCollectionExtensions.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								Core.Thalos.Provider/ServiceCollectionExtensions.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | |||||||
|  | using Core.Blueprint.Mongo; | ||||||
|  | using Core.Thalos.Adapters; | ||||||
|  | using Core.Thalos.Infraestructure.Caching.Contracts; | ||||||
|  | using Core.Thalos.Infraestructure.Contexts.Mongo; | ||||||
|  | using Core.Thalos.Provider.Contracts; | ||||||
|  | using Core.Thalos.Provider.Providers; | ||||||
|  | using Core.Thalos.Provider.Providers.Onboarding; | ||||||
|  | using LSA.Core.Dapper.Service.Caching; | ||||||
|  | using Microsoft.Extensions.Configuration; | ||||||
|  | using Microsoft.Extensions.DependencyInjection; | ||||||
|  | using Microsoft.Extensions.Logging; | ||||||
|  | using Microsoft.Extensions.Options; | ||||||
|  | using MongoDB.Driver; | ||||||
|  |  | ||||||
|  | namespace Core.Thalos.Provider | ||||||
|  | { | ||||||
|  |     public static class ServiceCollectionExtensions | ||||||
|  |     { | ||||||
|  |         public static IServiceCollection AddDALLayerServices(this IServiceCollection services, IConfiguration configuration) | ||||||
|  |         { | ||||||
|  |             //Mongo | ||||||
|  |             services.AddScoped<IModuleProvider, ModuleProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<ModuleAdapter>>(); | ||||||
|  |  | ||||||
|  |             services.AddScoped<IPermissionProvider, PermissionProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<PermissionAdapter>>(); | ||||||
|  |  | ||||||
|  |             services.AddScoped<IRoleProvider, RoleProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<RoleAdapter>>(); | ||||||
|  |  | ||||||
|  |             services.AddScoped<IUserProvider, UserProvider>(); | ||||||
|  |             services.AddScoped<CollectionRepository<UserAdapter>>(); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         private static IServiceCollection AddLogs(this IServiceCollection services) | ||||||
|  |         { | ||||||
|  |             services.AddLogging(); | ||||||
|  |             var serviceProvider = services.BuildServiceProvider(); | ||||||
|  |             //var logger = serviceProvider.GetService<ILogger<DashboardDALService>>(); //Add for Markup class later TODO | ||||||
|  |  | ||||||
|  |             //services.AddSingleton(typeof(ILogger), logger); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         private static IServiceCollection AddRedisCacheService(this IServiceCollection services, IConfiguration configuration) | ||||||
|  |         { | ||||||
|  |             var source = configuration.GetSection("ConnectionStrings"); | ||||||
|  |  | ||||||
|  |             var redisConnectionString = source["Redis"]?.ToString(); | ||||||
|  |  | ||||||
|  |             if (string.IsNullOrEmpty(redisConnectionString)) | ||||||
|  |             { | ||||||
|  |                 throw new InvalidOperationException("Redis connection string is not configured."); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             services.AddSingleton<ICacheService>(provider => | ||||||
|  |                 new CacheService(redisConnectionString, provider.GetRequiredService<ILogger<CacheService>>())); | ||||||
|  |  | ||||||
|  |             return services; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user