fix IgnoreDataCase

This commit is contained in:
2024-04-08 15:46:42 +08:00
parent dc901eeb6b
commit bcbddb95b4
2 changed files with 41 additions and 0 deletions

View File

@@ -120,6 +120,7 @@ public class GainfosController : ControllerBase
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[IgnoreDataCase]
[HttpPost("faces")]
public async Task<Dictionary<string, string>> GetFaceByUserCodesAsync(GetFaceByUserCodesRequest request)
{

View File

@@ -0,0 +1,40 @@
using System.Text;
using Kurisu.Core.Result;
using Kurisu.Core.Result.Abstractions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
namespace Dlhis.Basic.Organization.Filters;
[AttributeUsage(AttributeTargets.Method)]
public class IgnoreDataCaseAttribute : Attribute, IAsyncResultFilter
{
public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
if (context.Result is ObjectResult result)
{
var type = result.Value?.GetType();
if (type.IsGenericType && type.IsAssignableTo(typeof(IApiResult)))
{
var apiResult = result.Value as DefaultApiResult<object>;
var body = new
{
code = 200,
msg = "操作成功",
data = apiResult.Data
};
var json = JsonConvert.SerializeObject(body);
var bytes = Encoding.UTF8.GetBytes(json);
context.HttpContext.Response.ContentType = "application/json";
context.HttpContext.Response.ContentLength = bytes.Length;
await context.HttpContext.Response.BodyWriter.WriteAsync(bytes);
}
}
await next();
}
}