| | | 1 | | using Elsa.Identity.Models; |
| | | 2 | | using Microsoft.AspNetCore.Http; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Identity.Endpoints.Roles.Delete; |
| | | 5 | | |
| | | 6 | | internal static class RoleDeletionEndpointSupport |
| | | 7 | | { |
| | 0 | 8 | | public static Task SendOperationResultAsync(HttpContext context, RoleDeletionOperationResult result, CancellationTok |
| | 0 | 9 | | { |
| | 0 | 10 | | RoleDeletionOperationResult.Deleted => SendNoContentAsync(context), |
| | 0 | 11 | | RoleDeletionOperationResult.NotFound => SendErrorAsync(context, StatusCodes.Status404NotFound, "not_found", "The |
| | 0 | 12 | | RoleDeletionOperationResult.Forbidden => SendErrorAsync(context, StatusCodes.Status403Forbidden, "forbidden", "T |
| | 0 | 13 | | RoleDeletionOperationResult.Blocked blocked => SendErrorAsync(context, StatusCodes.Status409Conflict, "conflict" |
| | 0 | 14 | | RoleDeletionOperationResult.PreconditionFailed conflict => SendErrorAsync(context, StatusCodes.Status409Conflict |
| | 0 | 15 | | RoleDeletionOperationResult.ConfirmationRequired confirmation => SendErrorAsync(context, StatusCodes.Status400Ba |
| | 0 | 16 | | RoleDeletionOperationResult.Incomplete incomplete => SendErrorAsync(context, StatusCodes.Status409Conflict, "con |
| | 0 | 17 | | _ => throw new InvalidOperationException("Unknown role-deletion operation result.") |
| | 0 | 18 | | }; |
| | | 19 | | |
| | | 20 | | public static async Task SendInspectionResultAsync(HttpContext context, RoleDeletionInspectionResult result, Cancell |
| | | 21 | | { |
| | | 22 | | switch (result) |
| | | 23 | | { |
| | | 24 | | case RoleDeletionInspectionResult.Success success: |
| | 0 | 25 | | await context.Response.WriteAsJsonAsync(RoleDeletionImpactResponse.From(success.Impact), cancellationTok |
| | 0 | 26 | | break; |
| | | 27 | | case RoleDeletionInspectionResult.NotFound: |
| | 0 | 28 | | await SendErrorAsync(context, StatusCodes.Status404NotFound, "not_found", "The role was not found.", nul |
| | 0 | 29 | | break; |
| | | 30 | | case RoleDeletionInspectionResult.Forbidden: |
| | 0 | 31 | | await SendErrorAsync(context, StatusCodes.Status403Forbidden, "forbidden", "The caller may not inspect d |
| | | 32 | | break; |
| | | 33 | | } |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | private static Task SendNoContentAsync(HttpContext context) |
| | | 37 | | { |
| | 0 | 38 | | context.Response.StatusCode = StatusCodes.Status204NoContent; |
| | 0 | 39 | | return Task.CompletedTask; |
| | | 40 | | } |
| | | 41 | | |
| | | 42 | | private static Task SendErrorAsync(HttpContext context, int statusCode, string error, string message, object? detail |
| | | 43 | | { |
| | 0 | 44 | | context.Response.StatusCode = statusCode; |
| | 0 | 45 | | return context.Response.WriteAsJsonAsync(new RoleDeletionErrorResponse(error, message, details), cancellationTok |
| | | 46 | | } |
| | | 47 | | } |