Skip to content

Commit 1c22c19

Browse files
committed
finish crud plugin
1 parent d31363e commit 1c22c19

12 files changed

Lines changed: 2881 additions & 22 deletions

NpgsqlRest/Defaults/DefaultEndpoint.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ internal static class DefaultEndpoint
9090
CrudType.Delete => Method.DELETE,
9191
_ => Method.POST
9292
};
93-
var requestParamType = method == Method.GET ? RequestParamType.QueryString : RequestParamType.BodyJson;
93+
var requestParamType = method == Method.GET || method == Method.DELETE ?
94+
RequestParamType.QueryString :
95+
RequestParamType.BodyJson;
9496

9597
var originalUrl = url;
9698
var originalMethod = method;

NpgsqlRest/MiddlewareExtension.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public static IApplicationBuilder UseNpgsqlRest(this IApplicationBuilder builder
7373
}
7474

7575
JsonObject? jsonObj = null;
76+
IDictionary<string, JsonNode?> bodyDict = default!;
7677
string? body = null;
7778

7879
var len = tupleArray.Length;
@@ -300,8 +301,6 @@ await options.ValidateParametersAsync(new(
300301
continue;
301302
}
302303
}
303-
304-
var bodyDict = (IDictionary<string, JsonNode?>)jsonObj;
305304
bool shouldContinue = false;
306305
foreach (var key in bodyDict.Keys)
307306
{
@@ -811,10 +810,14 @@ async Task ParseJsonBody()
811810
try
812811
{
813812
jsonObj = node?.AsObject();
813+
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
814+
bodyDict = jsonObj?.ToDictionary();
815+
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
814816
}
815-
catch (InvalidOperationException)
817+
catch (Exception e)
816818
{
817-
logger?.LogWarning("Could not parse JSON body {0}, skipping path {1}.", body, context.Request.Path);
819+
logger?.LogWarning("Could not parse JSON body {0}, skipping path {1}. Error: {2}",
820+
body, context.Request.Path, e.Message);
818821
}
819822
}
820823
}

NpgsqlRestTestWebApi/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
SourceCreated = sources =>
9898
{
99-
sources.Add(new CrudSource());
99+
sources.Add(new CrudSource());
100100
},
101101
});
102102
app.Run();
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"ConnectionStrings": {
3-
//"Default": "Host=127.0.0.1;Port=5432;Database=npgsql_rest_test;Username=postgres;Password=postgres"
3+
"Default": "Host=127.0.0.1;Port=5432;Database=npgsql_rest_test;Username=postgres;Password=postgres"
44
}
55
}

0 commit comments

Comments
 (0)