diff options
| author | crupest <crupest@outlook.com> | 2022-12-23 16:31:47 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2022-12-23 16:31:47 +0800 | 
| commit | 4d8c1ed02fbe706d42f2364c34509216f71b8266 (patch) | |
| tree | b54d036a41739cb8d2dce97fac8b304e4c19a9b3 /docker/crupest-api/CrupestApi/CrupestApi.Commons | |
| parent | e19d5550d88c114acaab77799345135d63117fcc (diff) | |
| download | crupest-4d8c1ed02fbe706d42f2364c34509216f71b8266.tar.gz crupest-4d8c1ed02fbe706d42f2364c34509216f71b8266.tar.bz2 crupest-4d8c1ed02fbe706d42f2364c34509216f71b8266.zip  | |
Develop secret api. v61
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Commons')
| -rw-r--r-- | docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs | 21 | 
1 files changed, 21 insertions, 0 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs index c9e43f2..8942979 100644 --- a/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs +++ b/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/CrudWebApplicationExtensions.cs @@ -2,6 +2,27 @@ namespace CrupestApi.Commons.Crud;  public static class CrudWebApplicationExtensions  { +    public static WebApplication UseCrudCore(this WebApplication app) +    { +        app.Use(async (context, next) => +        { +            try +            { +                await next(); +            } +            catch (EntityNotExistException) +            { +                await context.ResponseMessageAsync("Requested entity does not exist.", StatusCodes.Status404NotFound); +            } +            catch (UserException e) +            { +                await context.ResponseMessageAsync(e.Message); +            } +        }); + +        return app; +    } +      public static WebApplication MapCrud<TEntity>(this WebApplication app, string path, string? permission) where TEntity : class      {          app.MapGet(path, async (context) =>  | 
