mirror of
https://github.com/hargata/lubelog.git
synced 2026-02-03 17:53:02 -06:00
Merge pull request #1240 from hargata/Hargata/pull.data.from.body
Hargata/pull.data.from.body
This commit is contained in:
commit
0be585195c
@ -78,6 +78,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -121,6 +121,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -124,6 +124,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId", "autoIncludeEquipment" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -105,6 +105,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -88,6 +88,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(results);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -89,6 +89,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -89,6 +89,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -121,6 +121,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -125,6 +125,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(OperationResponse.Failed($"No Recurring Taxes Updated Due To Error: {ex.Message}"));
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
@ -89,6 +89,7 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
[TypeFilter(typeof(QueryParamFilter), Arguments = new object[] { new string[] { "vehicleId" } })]
|
||||
[TypeFilter(typeof(APIKeyFilter), Arguments = new object[] { HouseholdPermission.Edit })]
|
||||
[TypeFilter(typeof(CollaboratorFilter), Arguments = new object[] { false, true, HouseholdPermission.Edit })]
|
||||
[HttpPost]
|
||||
|
||||
57
Filter/QueryParamFilter.cs
Normal file
57
Filter/QueryParamFilter.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CarCareTracker.Filter
|
||||
{
|
||||
public class QueryParamFilter: ActionFilterAttribute
|
||||
{
|
||||
private readonly string[] _queryParams;
|
||||
public QueryParamFilter(string[] queryParams)
|
||||
{
|
||||
_queryParams = queryParams;
|
||||
}
|
||||
public override async void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
Dictionary<string, string> paramDictionary = new Dictionary<string, string>{
|
||||
{ "vehicleId", "int"},
|
||||
{ "autoIncludeEquipment", "bool" }
|
||||
};
|
||||
if (_queryParams.Any(x => !filterContext.ActionArguments.ContainsKey(x)))
|
||||
{
|
||||
filterContext.HttpContext.Request.Body.Position = 0;
|
||||
var reader = new StreamReader(filterContext.HttpContext.Request.Body, Encoding.UTF8);
|
||||
var rawMessage = await reader.ReadToEndAsync();
|
||||
if (!string.IsNullOrWhiteSpace(rawMessage))
|
||||
{
|
||||
Dictionary<string, object> dynamicDictionary = JsonSerializer.Deserialize<Dictionary<string, object>>(rawMessage) ?? new Dictionary<string, object>();
|
||||
foreach (string queryParam in _queryParams)
|
||||
{
|
||||
if (!filterContext.ActionArguments.ContainsKey(queryParam) && dynamicDictionary.ContainsKey(queryParam))
|
||||
{
|
||||
if (paramDictionary.TryGetValue(queryParam, out string queryParamType))
|
||||
{
|
||||
if (queryParamType == "int")
|
||||
{
|
||||
filterContext.ActionArguments.Add(queryParam, int.Parse(dynamicDictionary[queryParam].ToString()));
|
||||
}
|
||||
else if (queryParamType == "bool")
|
||||
{
|
||||
filterContext.ActionArguments.Add(queryParam, bool.Parse(dynamicDictionary[queryParam].ToString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
filterContext.ActionArguments.Add(queryParam, dynamicDictionary[queryParam].ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filterContext.ActionArguments.Add(queryParam, dynamicDictionary[queryParam].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Middleware/BufferBody.cs
Normal file
16
Middleware/BufferBody.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace CarCareTracker.Middleware
|
||||
{
|
||||
public class BufferBody
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
public BufferBody(RequestDelegate next) =>
|
||||
_next = next;
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
context.Request.EnableBuffering();
|
||||
|
||||
await _next(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -191,6 +191,11 @@ app.UseStaticFiles(new StaticFileOptions
|
||||
}
|
||||
});
|
||||
|
||||
app.UseWhen(
|
||||
ctx => ctx.Request.Path.StartsWithSegments("/api") && ctx.Request.ContentType == "application/json",
|
||||
ab => ab.UseMiddleware<BufferBody>()
|
||||
);
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user