Refactor and enhance JSON handling with extensions
Refactored `ConfigExtensions.cs` to move `ConfigurationExtensions` to the `ReC.API.Extensions` namespace and re-added the `GetFakeProfileId` method. Introduced `JsonExtensions.cs` with a `JsonToDynamic` method for recursive JSON deserialization, simplifying nested JSON handling. Updated `OutResController.cs` and `RecActionController.cs` to use the new `JsonToDynamic` method, improving code readability and reducing duplication. Overall, modularized and cleaned up code for better maintainability.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ReC.API.Models;
|
||||
using ReC.API.Extensions;
|
||||
using ReC.Application.OutResults.Queries;
|
||||
using System.Net.Mime;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace ReC.API.Controllers;
|
||||
|
||||
@@ -34,8 +33,8 @@ public class OutResController(IMediator mediator, IConfiguration config) : Contr
|
||||
|
||||
return resultType switch
|
||||
{
|
||||
ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(JsonSerializer.Deserialize<dynamic>(res.Body)),
|
||||
ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(JsonSerializer.Deserialize<dynamic>(res.Header)),
|
||||
ResultType.Body => res.Body is null ? Ok(new object { }) : Ok(res.Body.JsonToDynamic()),
|
||||
ResultType.Header => res.Header is null ? Ok(new object { }) : Ok(res.Header.JsonToDynamic()),
|
||||
_ => Ok(res),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ReC.API.Extensions;
|
||||
using ReC.API.Models;
|
||||
using ReC.Application.RecActions.Commands;
|
||||
using ReC.Application.RecActions.Queries;
|
||||
|
||||
Reference in New Issue
Block a user