diff options
author | crupest <crupest@outlook.com> | 2022-12-17 19:07:23 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-12-20 20:32:53 +0800 |
commit | 8b7bbe2b70f25bc493bf11bd4d0e484e65d22523 (patch) | |
tree | ed55de998706e6805f71614d20d2602d1b3b599f /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs | |
parent | 106e7492d8e8d07ccf50f2d13b5685f5838a52d8 (diff) | |
download | crupest-8b7bbe2b70f25bc493bf11bd4d0e484e65d22523.tar.gz crupest-8b7bbe2b70f25bc493bf11bd4d0e484e65d22523.tar.bz2 crupest-8b7bbe2b70f25bc493bf11bd4d0e484e65d22523.zip |
Develop secret api. v41
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs')
-rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs index 8df444c..7331273 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs @@ -17,7 +17,7 @@ public static class CrudWebApplicationExtensions var key = context.Request.RouteValues["key"]?.ToString(); if (key == null) { - await context.ResponseMessageAsync("Please specify a key."); + await context.ResponseMessageAsync("Please specify a key in path."); return; } @@ -33,6 +33,36 @@ public static class CrudWebApplicationExtensions await context.ResponseJsonAsync(crudService.JsonHelper.ConvertEntityToDictionary(crudService.GetByKey(key))); }); + app.MapPatch(path + "/{key}", async (context) => + { + var crudService = context.RequestServices.GetRequiredService<CrudService<TEntity>>(); + var key = context.Request.RouteValues["key"]?.ToString(); + if (key == null) + { + await context.ResponseMessageAsync("Please specify a key in path."); + return; + } + + var jsonDocument = await context.Request.ReadJsonAsync(); + crudService.Update(key, jsonDocument.RootElement); + + await context.ResponseJsonAsync(crudService.JsonHelper.ConvertEntityToDictionary(crudService.GetByKey(key))); + }); + + app.MapDelete(path + "/{key}", async (context) => + { + var crudService = context.RequestServices.GetRequiredService<CrudService<TEntity>>(); + var key = context.Request.RouteValues["key"]?.ToString(); + if (key == null) + { + await context.ResponseMessageAsync("Please specify a key in path."); + return; + } + + crudService.DeleteByKey(key); + await context.ResponseMessageAsync("Deleted.", StatusCodes.Status200OK); + }); + return app; } } |