From 9176faa9d086ee63d57c47b821b161877cb497d3 Mon Sep 17 00:00:00 2001 From: MysticBoy Date: Mon, 10 Oct 2022 18:36:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E7=9A=84=20?= =?UTF-8?q?=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5=20=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=20StringEnumConverter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IoTSharp/Controllers/HealthChecksController.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/IoTSharp/Controllers/HealthChecksController.cs b/IoTSharp/Controllers/HealthChecksController.cs index fb695f84..47dc2342 100644 --- a/IoTSharp/Controllers/HealthChecksController.cs +++ b/IoTSharp/Controllers/HealthChecksController.cs @@ -10,9 +10,14 @@ using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using System.Linq; using IoTSharp.Contracts; +using Newtonsoft.Json.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Microsoft.AspNetCore.Mvc.Filters; namespace IoTSharp.Controllers { + [Route("api/[controller]")] [ApiController] public class HealthChecksController : ControllerBase @@ -30,9 +35,14 @@ namespace IoTSharp.Controllers /// [HttpGet()] [ProducesResponseType(StatusCodes.Status200OK)] - public async Task>> Get() + public async Task Get() { - + var _jsonSerializationSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + Converters = new[] { new StringEnumConverter() }, + DateTimeZoneHandling = DateTimeZoneHandling.Local + }; using (var scope = __serviceScopeFactory.CreateScope()) using (var db = scope.ServiceProvider.GetRequiredService()) { @@ -58,7 +68,8 @@ namespace IoTSharp.Controllers healthChecksExecutions.Add(execution); } } - return new ApiResult>(ApiCode.Success, "OK", healthChecksExecutions); + var responseContent = JsonConvert.SerializeObject(healthChecksExecutions, _jsonSerializationSettings); + return new JsonResult( healthChecksExecutions,_jsonSerializationSettings); } } } -- GitLab