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 | 7407875fb75bcd90f6f7ef54573483fe2f3cfb84 (patch) | |
tree | ed55de998706e6805f71614d20d2602d1b3b599f /docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs | |
parent | 4595650f6e36ff413bcb65f5419daf8f9bfee9de (diff) | |
download | crupest-7407875fb75bcd90f6f7ef54573483fe2f3cfb84.tar.gz crupest-7407875fb75bcd90f6f7ef54573483fe2f3cfb84.tar.bz2 crupest-7407875fb75bcd90f6f7ef54573483fe2f3cfb84.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; } } |