fix IgnoreDataCase
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user