From e90b6a2e05646d634bb80d4ec3b9c1a27589ee48 Mon Sep 17 00:00:00 2001 From: noremacskich Date: Mon, 21 Oct 2024 02:18:08 -0500 Subject: [PATCH] Ran csharpier --- .../DTOs/PotentialParentsDto.cs | 2 +- .../ExpressionTextSectionRepository.cs | 9 +- .../DTOs/AvailableParentsDto.cs | 2 +- .../DTOs/SectionTypeDto.cs | 2 +- .../ExpressionSubSectionsEndpoints.cs | 142 +++++++++++------- .../Helpers/ExpressionHelpers.cs | 10 +- .../EditExpressionSubSectionTextRequest.cs | 2 +- .../EditExpressionSectionResponse.cs | 2 +- .../Responses/ExpressionBaseResponse.cs | 2 +- .../ExpressionSectionOptionsResponse.cs | 2 +- 10 files changed, 100 insertions(+), 75 deletions(-) diff --git a/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/DTOs/PotentialParentsDto.cs b/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/DTOs/PotentialParentsDto.cs index ab0fc6a..9b95b0b 100644 --- a/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/DTOs/PotentialParentsDto.cs +++ b/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/DTOs/PotentialParentsDto.cs @@ -5,4 +5,4 @@ public class PotentialParentsDto public int Id { get; set; } public string Name { get; set; } public List SubSections { get; set; } -} \ No newline at end of file +} diff --git a/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/ExpressionTextSectionRepository.cs b/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/ExpressionTextSectionRepository.cs index f3731a0..42bf2e1 100644 --- a/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/ExpressionTextSectionRepository.cs +++ b/api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/ExpressionTextSectionRepository.cs @@ -155,10 +155,11 @@ public async Task DeleteExpressionTextSectionAsync(int id) public async Task> GetExpressionId(string expressionName) { - var expression = await context.Expressions - .FirstOrDefaultAsync(x => x.Name.ToLower() == expressionName.ToLower()); - - if(expression is null) + var expression = await context.Expressions.FirstOrDefaultAsync(x => + x.Name.ToLower() == expressionName.ToLower() + ); + + if (expression is null) return Result.Fail(new NotFoundFailure("Expression")); return expression.Id; diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/AvailableParentsDto.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/AvailableParentsDto.cs index 9abb2e6..3bc1995 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/AvailableParentsDto.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/AvailableParentsDto.cs @@ -5,4 +5,4 @@ public class AvailableParentsDto public int Id { get; set; } public string Name { get; set; } public List SubSections { get; set; } = new(); -} \ No newline at end of file +} diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/SectionTypeDto.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/SectionTypeDto.cs index 60cb579..d005118 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/SectionTypeDto.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/DTOs/SectionTypeDto.cs @@ -5,4 +5,4 @@ public class SectionTypeDto public int Id { get; set; } public string Name { get; set; } = null!; public string? Description { get; set; } -} \ No newline at end of file +} diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/ExpressionSubSectionsEndpoints.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/ExpressionSubSectionsEndpoints.cs index aacadee..71a07f9 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/ExpressionSubSectionsEndpoints.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/ExpressionSubSectionsEndpoints.cs @@ -24,105 +24,133 @@ internal static void AddExpressionSubsectionEndpoints(this WebApplication app) endpointGroup .MapGet( "{name}", - async Task>> - (string name, HttpContext httpContext, IExpressionTextSectionRepository repository) => + async Task>> ( + string name, + HttpContext httpContext, + IExpressionTextSectionRepository repository + ) => { var expressionIdResult = await repository.GetExpressionId(name); if (expressionIdResult.HasNotFound(out var notFound)) return notFound; expressionIdResult.ThrowIfErrorNotHandled(); - - var sections = await repository.GetExpressionTextSections(expressionIdResult.Value); - + + var sections = await repository.GetExpressionTextSections( + expressionIdResult.Value + ); + var hasEditPolicy = await httpContext.UserHasPolicyAsync( Policies.ExpressionEditorPolicy ); - - return TypedResults.Ok( new ExpressionBaseResponse() - { - ExpressionId = expressionIdResult.Value, - ExpressionSections = ExpressionHelpers.BuildExpressionPage(sections), - CanEditPolicy = hasEditPolicy - }); + + return TypedResults.Ok( + new ExpressionBaseResponse() + { + ExpressionId = expressionIdResult.Value, + ExpressionSections = ExpressionHelpers.BuildExpressionPage(sections), + CanEditPolicy = hasEditPolicy + } + ); } ) .RequireAuthorization(); - + endpointGroup .MapGet( "{expressionId}/{sectionId}", - async Task>> - (int expressionId, int sectionId, IExpressionTextSectionRepository repository) => + async Task>> ( + int expressionId, + int sectionId, + IExpressionTextSectionRepository repository + ) => { var sectionResult = await repository.GetExpressionTextSection(sectionId); - + if (sectionResult.HasNotFound(out var sectionNotFound)) return sectionNotFound; sectionResult.ThrowIfErrorNotHandled(); - - return TypedResults.Ok(new EditExpressionSectionResponse() - { - Name = sectionResult.Value.Name, - Content = sectionResult.Value.Content, - ParentId = sectionResult.Value.ParentId, - SectionTypeId = sectionResult.Value.SectionTypeId - }); + + return TypedResults.Ok( + new EditExpressionSectionResponse() + { + Name = sectionResult.Value.Name, + Content = sectionResult.Value.Content, + ParentId = sectionResult.Value.ParentId, + SectionTypeId = sectionResult.Value.SectionTypeId + } + ); } ) .RequirePolicyAuthorization(Policies.ExpressionEditorPolicy); - + endpointGroup .MapGet( "{expressionId}/{sectionId}/options", - async Task>> - (int expressionId, int sectionId, IExpressionTextSectionRepository repository) => + async Task>> ( + int expressionId, + int sectionId, + IExpressionTextSectionRepository repository + ) => { - var optionsResult = await repository.GetExpressionTextSectionOptions(new GetExpressionTestSectionOptionsDto() - { - ExpressionId = expressionId, - SectionId = sectionId == 0 ? null : sectionId // Handle Create (0 = null) - }); - + var optionsResult = await repository.GetExpressionTextSectionOptions( + new GetExpressionTestSectionOptionsDto() + { + ExpressionId = expressionId, + SectionId = sectionId == 0 ? null : sectionId // Handle Create (0 = null) + } + ); + if (optionsResult.HasNotFound(out var notFound)) return notFound; optionsResult.ThrowIfErrorNotHandled(); - - return TypedResults.Ok(new ExpressionSectionOptionsResponse() - { - SectionTypes = optionsResult.Value.ExpressionSectionTypes.Select(x => new SectionTypeDto() + + return TypedResults.Ok( + new ExpressionSectionOptionsResponse() { - Id = x.Id, - Name = x.Name, - Description = x.Description - }).ToList(), - AvailableParents = ExpressionHelpers.BuildAvailableParentTree(optionsResult.Value.AvailableParents) - - }); + SectionTypes = optionsResult + .Value.ExpressionSectionTypes.Select(x => new SectionTypeDto() + { + Id = x.Id, + Name = x.Name, + Description = x.Description + }) + .ToList(), + AvailableParents = ExpressionHelpers.BuildAvailableParentTree( + optionsResult.Value.AvailableParents + ) + } + ); } ) .RequirePolicyAuthorization(Policies.ExpressionEditorPolicy); - + endpointGroup .MapPut( "{expressionId}/{sectionId}", - async Task> - (int expressionId, int sectionId, EditExpressionSubSectionTextRequest request, IExpressionTextSectionRepository repository) => + async Task> ( + int expressionId, + int sectionId, + EditExpressionSubSectionTextRequest request, + IExpressionTextSectionRepository repository + ) => { - var results = await repository.EditExpressionTextSectionAsync(new EditExpressionTextSectionDto() - { - Id = sectionId, - ExpressionId = expressionId, - Name = request.Name, - Content = request.Content, - SectionTypeId = request.SectionTypeId - }); - + var results = await repository.EditExpressionTextSectionAsync( + new EditExpressionTextSectionDto() + { + Id = sectionId, + ExpressionId = expressionId, + Name = request.Name, + Content = request.Content, + SectionTypeId = request.SectionTypeId + } + ); + if (results.HasNotFound(out var notFound)) return notFound; if (results.HasValidationError(out var validationProblem)) return validationProblem; results.ThrowIfErrorNotHandled(); - + return TypedResults.NoContent(); } ) diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Helpers/ExpressionHelpers.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Helpers/ExpressionHelpers.cs index 43241cb..cd2d4f2 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Helpers/ExpressionHelpers.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Helpers/ExpressionHelpers.cs @@ -27,7 +27,7 @@ List dbSections return sections; } - + public static List BuildAvailableParentTree( List dbSections ) @@ -36,11 +36,7 @@ List dbSections foreach (var dbSection in dbSections) { - var dto = new AvailableParentsDto() - { - Name = dbSection.Name, - Id = dbSection.Id - }; + var dto = new AvailableParentsDto() { Name = dbSection.Name, Id = dbSection.Id }; dto.SubSections = BuildAvailableParentTree(dbSection.SubSections); @@ -49,4 +45,4 @@ List dbSections return sections; } -} \ No newline at end of file +} diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Requests/EditExpressionSubSectionTextRequest.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Requests/EditExpressionSubSectionTextRequest.cs index 6df7aee..22e2861 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Requests/EditExpressionSubSectionTextRequest.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Requests/EditExpressionSubSectionTextRequest.cs @@ -5,4 +5,4 @@ public class EditExpressionSubSectionTextRequest public string Name { get; set; } = null!; public string Content { get; set; } = null!; public int SectionTypeId { get; set; } -} \ No newline at end of file +} diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/EditExpressionSectionResponse.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/EditExpressionSectionResponse.cs index 6d9c0fc..13c012a 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/EditExpressionSectionResponse.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/EditExpressionSectionResponse.cs @@ -7,4 +7,4 @@ public class EditExpressionSectionResponse public string Content { get; set; } public int? ParentId { get; set; } public int SectionTypeId { get; set; } -} \ No newline at end of file +} diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionBaseResponse.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionBaseResponse.cs index a41f502..efe58dc 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionBaseResponse.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionBaseResponse.cs @@ -7,4 +7,4 @@ public class ExpressionBaseResponse public int ExpressionId { get; set; } public List ExpressionSections { get; set; } public bool CanEditPolicy { get; set; } -} \ No newline at end of file +} diff --git a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionSectionOptionsResponse.cs b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionSectionOptionsResponse.cs index 62a1b21..4d62eb5 100644 --- a/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionSectionOptionsResponse.cs +++ b/api/ExpressedRealms.Server/EndPoints/ExpressionEndpoints/Responses/ExpressionSectionOptionsResponse.cs @@ -6,4 +6,4 @@ public class ExpressionSectionOptionsResponse { public List AvailableParents { get; set; } public List SectionTypes { get; set; } -} \ No newline at end of file +}