aboutsummaryrefslogtreecommitdiffstats
path: root/code/api
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-10-25 11:51:37 +0200
committerivarlovlie <git@ivarlovlie.no>2022-10-25 11:51:37 +0200
commit0005595703b2f3f7083ce4ba19bf5770057c75bd (patch)
tree193a897f61a9a5e566961601de4cf42ae85984a0 /code/api
parent585c5c8537eb21dfc9f16108548e63d9ced3d971 (diff)
downloadgreatoffice-0005595703b2f3f7083ce4ba19bf5770057c75bd.tar.xz
greatoffice-0005595703b2f3f7083ce4ba19bf5770057c75bd.zip
.
Diffstat (limited to 'code/api')
-rw-r--r--code/api/src/Data/Models/KnownProblemModel.cs1
-rw-r--r--code/api/src/Endpoints/EndpointBase.cs14
-rw-r--r--code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs2
-rw-r--r--code/api/src/Utilities/SwaggerDefaultValues.cs2
-rw-r--r--code/api/src/Utilities/SwaggerGenOptionsExtensions.cs8
5 files changed, 9 insertions, 18 deletions
diff --git a/code/api/src/Data/Models/KnownProblemModel.cs b/code/api/src/Data/Models/KnownProblemModel.cs
index 445d338..38b3eba 100644
--- a/code/api/src/Data/Models/KnownProblemModel.cs
+++ b/code/api/src/Data/Models/KnownProblemModel.cs
@@ -12,5 +12,4 @@ public class KnownProblemModel
public string Subtitle { get; set; }
public Dictionary<string, string> Errors { get; set; }
public string TraceId { get; set; }
- public string RequestId { get; set; }
} \ No newline at end of file
diff --git a/code/api/src/Endpoints/EndpointBase.cs b/code/api/src/Endpoints/EndpointBase.cs
index c088976..a2f55a6 100644
--- a/code/api/src/Endpoints/EndpointBase.cs
+++ b/code/api/src/Endpoints/EndpointBase.cs
@@ -1,8 +1,5 @@
-using System.Diagnostics;
-
namespace IOL.GreatOffice.Api.Endpoints;
-[ApiController]
public class EndpointBase : ControllerBase
{
/// <summary>
@@ -13,15 +10,12 @@ public class EndpointBase : ControllerBase
Id = User.FindFirstValue(AppClaims.USER_ID).AsGuid(),
};
- public ObjectResult KnownProblem(string title = default, string subtitle = default, Dictionary<string, string> errors = default) {
- return new ObjectResult(new KnownProblemModel {
+ public ActionResult KnownProblem(string title = default, string subtitle = default, Dictionary<string, string> errors = default) {
+ return BadRequest(new KnownProblemModel {
Title = title,
Subtitle = subtitle,
Errors = errors,
- TraceId = Activity.Current?.Id,
- RequestId = HttpContext.TraceIdentifier
- }) {
- StatusCode = (int) HttpStatusCode.BadRequest
- };
+ TraceId = HttpContext.TraceIdentifier
+ });
}
} \ No newline at end of file
diff --git a/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs b/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs
index 31ef7d0..4fe418b 100644
--- a/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs
+++ b/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs
@@ -1,12 +1,10 @@
namespace IOL.GreatOffice.Api.Endpoints.V1.Labels;
-/// <inheritdoc />
public class CreateLabelRoute : RouteBaseSync.WithRequest<TimeLabel.TimeLabelDto>.WithActionResult<TimeLabel.TimeLabelDto>
{
private readonly AppDbContext _context;
- /// <inheritdoc />
public CreateLabelRoute(AppDbContext context) {
_context = context;
}
diff --git a/code/api/src/Utilities/SwaggerDefaultValues.cs b/code/api/src/Utilities/SwaggerDefaultValues.cs
index 4b5c764..5e73fa8 100644
--- a/code/api/src/Utilities/SwaggerDefaultValues.cs
+++ b/code/api/src/Utilities/SwaggerDefaultValues.cs
@@ -27,7 +27,7 @@ public class SwaggerDefaultValues : IOperationFilter
var response = operation.Responses[responseKey];
foreach (var contentType in response.Content.Keys) {
- if (!responseType.ApiResponseFormats.Any(x => x.MediaType == contentType)) {
+ if (responseType.ApiResponseFormats.All(x => x.MediaType != contentType)) {
response.Content.Remove(contentType);
}
}
diff --git a/code/api/src/Utilities/SwaggerGenOptionsExtensions.cs b/code/api/src/Utilities/SwaggerGenOptionsExtensions.cs
index 0a7e07f..9b70194 100644
--- a/code/api/src/Utilities/SwaggerGenOptionsExtensions.cs
+++ b/code/api/src/Utilities/SwaggerGenOptionsExtensions.cs
@@ -1,5 +1,5 @@
#nullable enable
-using IOL.GreatOffice.Api.Endpoints.V1;
+using IOL.GreatOffice.Api.Endpoints;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Swashbuckle.AspNetCore.SwaggerGen;
@@ -10,7 +10,7 @@ public static class SwaggerGenOptionsExtensions
{
/// <summary>
/// Updates Swagger document to support ApiEndpoints.<br/><br/>
- /// For controllers inherited from <see cref="V1_EndpointBase"/>:<br/>
+ /// For controllers inherited from <see cref="EndpointBase"/>:<br/>
/// - Replaces action Tag with <c>[namespace]</c><br/>
/// </summary>
public static void UseApiEndpoints(this SwaggerGenOptions options) {
@@ -22,7 +22,7 @@ public static class SwaggerGenOptionsExtensions
throw new InvalidOperationException($"Unable to determine tag for endpoint: {api.ActionDescriptor.DisplayName}");
}
- if (actionDescriptor.ControllerTypeInfo.GetBaseTypesAndThis().Any(t => t == typeof(V1_EndpointBase))) {
+ if (actionDescriptor.ControllerTypeInfo.GetBaseTypesAndThis().Any(t => t == typeof(EndpointBase))) {
return new[] {
actionDescriptor.ControllerTypeInfo.Namespace?.Split('.').Last()
};
@@ -34,7 +34,7 @@ public static class SwaggerGenOptionsExtensions
}
public static IEnumerable<Type> GetBaseTypesAndThis(this Type type) {
- Type? current = type;
+ var current = type;
while (current != null) {
yield return current;
current = current.BaseType;