Implement issue reporting and workflows
This commit is contained in:
1 parent
6ad3d5bbaa
commit
b80ec57589
23 files changed
+1407
-17
No files matched your search
@@ -21,6 +21,7 @@ internal sealed class AppExceptionHandler(IProblemDetailsService problemDetails)
|
||||
Title = "Neplatná vstupní data.",
|
||||
},
|
||||
AppException app => new ProblemDetails { Status = app.StatusCode, Title = app.Message },
|
||||
BadHttpRequestException request => new ProblemDetails { Status = request.StatusCode },
|
||||
_ => null,
|
||||
};
|
||||
|
||||
|
||||
@@ -42,4 +42,5 @@ public static class AuthenticationSetup
|
||||
public static class RateLimitPolicies
|
||||
{
|
||||
public const string Auth = "auth";
|
||||
public const string IssueWrites = "issue-writes";
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
using Microsoft.OpenApi;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Helpdesk.Api.Controllers;
|
||||
using Helpdesk.Application.Issues;
|
||||
|
||||
namespace Helpdesk.Api.Infrastructure;
|
||||
|
||||
@@ -30,6 +33,7 @@ public static class SwaggerSetup
|
||||
{
|
||||
[new OpenApiSecuritySchemeReference(SchemeId, document)] = [],
|
||||
});
|
||||
options.OperationFilter<IssueRequestBody>();
|
||||
|
||||
var xml = Path.Combine(AppContext.BaseDirectory, "Helpdesk.Api.xml");
|
||||
if (File.Exists(xml))
|
||||
@@ -38,3 +42,63 @@ public static class SwaggerSetup
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class IssueRequestBody : IOperationFilter
|
||||
{
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
if (context.MethodInfo.DeclaringType != typeof(IssuesController))
|
||||
return;
|
||||
|
||||
var create = context.MethodInfo.Name == nameof(IssuesController.Create);
|
||||
if (!create && context.MethodInfo.Name != nameof(IssuesController.Upload))
|
||||
return;
|
||||
|
||||
var properties = new Dictionary<string, IOpenApiSchema>
|
||||
{
|
||||
["files"] = new OpenApiSchema
|
||||
{
|
||||
Type = JsonSchemaType.Array,
|
||||
MinItems = 1,
|
||||
MaxItems = AttachmentLimits.MaxFiles,
|
||||
Items = new OpenApiSchema { Type = JsonSchemaType.String, Format = "binary" },
|
||||
},
|
||||
};
|
||||
var required = new HashSet<string> { "files" };
|
||||
if (create)
|
||||
{
|
||||
required = ["title", "description", "categoryId"];
|
||||
properties["title"] = new OpenApiSchema { Type = JsonSchemaType.String, MaxLength = 200 };
|
||||
properties["description"] = new OpenApiSchema { Type = JsonSchemaType.String };
|
||||
properties["categoryId"] = new OpenApiSchema { Type = JsonSchemaType.Integer };
|
||||
properties["buildingId"] = new OpenApiSchema { Type = JsonSchemaType.Integer };
|
||||
properties["locationDetail"] = new OpenApiSchema { Type = JsonSchemaType.String, MaxLength = 255 };
|
||||
}
|
||||
|
||||
var content = new Dictionary<string, OpenApiMediaType>
|
||||
{
|
||||
["multipart/form-data"] = new()
|
||||
{
|
||||
Schema = new OpenApiSchema
|
||||
{
|
||||
Type = JsonSchemaType.Object,
|
||||
Required = required,
|
||||
Properties = properties,
|
||||
},
|
||||
},
|
||||
};
|
||||
if (create)
|
||||
{
|
||||
content["application/json"] = new OpenApiMediaType
|
||||
{
|
||||
Schema = context.SchemaGenerator.GenerateSchema(typeof(CreateIssueRequest), context.SchemaRepository),
|
||||
};
|
||||
}
|
||||
|
||||
operation.RequestBody = new OpenApiRequestBody
|
||||
{
|
||||
Required = true,
|
||||
Content = content,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user