From 791f5dcdf4bb6a6ab156ece80d8d4d42b18e56c6 Mon Sep 17 00:00:00 2001 From: Joe Owens Date: Tue, 21 Oct 2025 16:58:17 +0100 Subject: [PATCH 1/3] CODE RUB: Manage CRUD controllers remove debug comment on GetAll --- .../ConsumerAdoptionsController.cs | 7 +----- .../Consumers/ConsumersController.cs | 7 +----- .../Controllers/DecisionTypesController.cs | 7 +----- .../Controllers/DecisionsController.cs | 7 +----- .../Controllers/PatientsController.cs | 7 +----- .../Program.cs | 23 +++++++++++++++---- .../appsettings.json | 3 +++ .../appsettings.json | 3 +++ 8 files changed, 29 insertions(+), 35 deletions(-) diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs index 7a3a394a..b0ad2bb3 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs @@ -60,12 +60,7 @@ public async ValueTask> PostConsumerAdoptionAsync } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Consumers")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs index 8a5f1906..f703c6d9 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs @@ -60,12 +60,7 @@ public async ValueTask> PostConsumerAsync([FromBody] Cons } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs index 4035cd01..c11ca85b 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs @@ -60,12 +60,7 @@ public async ValueTask> PostDecisionTypeAsync([FromBo } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Agents")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs index 6f5a5686..808cba6e 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs @@ -60,12 +60,7 @@ public async ValueTask> PostDecisionAsync([FromBody] Deci } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Agents")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs index dadae814..b213f6b0 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs @@ -60,12 +60,7 @@ public async ValueTask> PostPatientAsync([FromBody] Patien } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Agents")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Program.cs b/LondonDataServices.IDecide.Manage.Server/Program.cs index ad4dd2e6..c266e1b1 100644 --- a/LondonDataServices.IDecide.Manage.Server/Program.cs +++ b/LondonDataServices.IDecide.Manage.Server/Program.cs @@ -30,7 +30,10 @@ using LondonDataServices.IDecide.Core.Clients.Audits; using LondonDataServices.IDecide.Core.Models.Brokers.Securities; using LondonDataServices.IDecide.Core.Models.Foundations.Audits; +using LondonDataServices.IDecide.Core.Models.Foundations.ConsumerAdoptions; +using LondonDataServices.IDecide.Core.Models.Foundations.Consumers; using LondonDataServices.IDecide.Core.Models.Foundations.Decisions; +using LondonDataServices.IDecide.Core.Models.Foundations.DecisionTypes; using LondonDataServices.IDecide.Core.Models.Foundations.Notifications; using LondonDataServices.IDecide.Core.Models.Foundations.Patients; using LondonDataServices.IDecide.Core.Models.Orchestrations.Decisions; @@ -134,10 +137,12 @@ public static void ConfigureServices( builder.Services.AddSingleton(builder.Configuration); JsonNamingPolicy jsonNamingPolicy = JsonNamingPolicy.CamelCase; + int defaultPageSize = builder.Configuration.GetValue("OData:PageSize", 50); + builder.Services.AddControllers() .AddOData(options => { - options.AddRouteComponents("odata", GetEdmModel()); + options.AddRouteComponents("odata", GetEdmModel(defaultPageSize)); options.Select().Filter().Expand().OrderBy().Count().SetMaxTop(100); }) .AddJsonOptions(options => @@ -178,14 +183,22 @@ public static void ConfigurePipeline(WebApplication app, InvisibleApiKey invisib app.MapFallbackToFile("/index.html"); } - private static IEdmModel GetEdmModel() + private static IEdmModel GetEdmModel(int pageSize) { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); - builder.EntitySet("Audits"); - builder.EntitySet("Patients"); - builder.EntitySet("Decisions"); + builder.EntitySet("Audits").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EntitySet("Consumers").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EntitySet("Decisions").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EntitySet("Patients").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + + builder.EntitySet("ConsumerAdoptions") + .EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + + builder.EntitySet("DecisionTypes") + .EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EnableLowerCamelCase(); return builder.GetEdmModel(); diff --git a/LondonDataServices.IDecide.Manage.Server/appsettings.json b/LondonDataServices.IDecide.Manage.Server/appsettings.json index 0083e7a9..f809752d 100644 --- a/LondonDataServices.IDecide.Manage.Server/appsettings.json +++ b/LondonDataServices.IDecide.Manage.Server/appsettings.json @@ -5,6 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, + "OData": { + "PageSize": 50 + }, "ConnectionStrings": { "IDecideConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=IDecide;Trusted_Connection=True;MultipleActiveResultSets=true" }, diff --git a/LondonDataServices.IDecide.Portal.Server/appsettings.json b/LondonDataServices.IDecide.Portal.Server/appsettings.json index 1fb8b543..598cbaf5 100644 --- a/LondonDataServices.IDecide.Portal.Server/appsettings.json +++ b/LondonDataServices.IDecide.Portal.Server/appsettings.json @@ -5,6 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, + "OData": { + "PageSize": 50 + }, "ConnectionStrings": { "IDecideConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=IDecide;Trusted_Connection=True;MultipleActiveResultSets=true" }, From 5cb989a3f270fbef66971fc6f1166112632ecaaf Mon Sep 17 00:00:00 2001 From: Joe Owens Date: Tue, 21 Oct 2025 17:06:35 +0100 Subject: [PATCH 2/3] CODE RUB: Portal CRUD controllers remove debug comment on GetAll --- .../Controllers/DecisionTypesController.cs | 7 +------ .../Controllers/DecisionsController.cs | 7 +------ .../Controllers/PatientsController.cs | 7 +------ .../Program.cs | 21 ++++++++++--------- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs index 3997c7ac..16a4bdcd 100644 --- a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs +++ b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs @@ -61,12 +61,7 @@ public async ValueTask> PostDecisionTypeAsync([FromBo } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [InvisibleApi] [Authorize(Roles = "LondonDataServices.IDecide.Portal.Server.Administrators")] public async ValueTask>> Get() diff --git a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs index 453062bf..351dbab1 100644 --- a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs +++ b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs @@ -61,12 +61,7 @@ public async ValueTask> PostDecisionAsync([FromBody] Deci } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [InvisibleApi] [Authorize(Roles = "LondonDataServices.IDecide.Portal.Server.Administrators")] public async ValueTask>> Get() diff --git a/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs b/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs index c75080b6..4e4bd93b 100644 --- a/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs +++ b/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs @@ -61,12 +61,7 @@ public async ValueTask> PostPatientAsync([FromBody] Patien } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [EnableQuery] [InvisibleApi] [Authorize(Roles = "LondonDataServices.IDecide.Portal.Server.Administrators")] public async ValueTask>> Get() diff --git a/LondonDataServices.IDecide.Portal.Server/Program.cs b/LondonDataServices.IDecide.Portal.Server/Program.cs index 092cf75c..ff5c8050 100644 --- a/LondonDataServices.IDecide.Portal.Server/Program.cs +++ b/LondonDataServices.IDecide.Portal.Server/Program.cs @@ -32,8 +32,6 @@ using LondonDataServices.IDecide.Core.Clients.Audits; using LondonDataServices.IDecide.Core.Models.Brokers.Securities; using LondonDataServices.IDecide.Core.Models.Foundations.Audits; -using LondonDataServices.IDecide.Core.Models.Foundations.ConsumerAdoptions; -using LondonDataServices.IDecide.Core.Models.Foundations.Consumers; using LondonDataServices.IDecide.Core.Models.Foundations.Decisions; using LondonDataServices.IDecide.Core.Models.Foundations.DecisionTypes; using LondonDataServices.IDecide.Core.Models.Foundations.Notifications; @@ -148,10 +146,12 @@ public static void ConfigureServices( builder.Services.AddSingleton(builder.Configuration); JsonNamingPolicy jsonNamingPolicy = JsonNamingPolicy.CamelCase; + int defaultPageSize = builder.Configuration.GetValue("OData:PageSize", 50); + builder.Services.AddControllers() .AddOData(options => { - options.AddRouteComponents("odata", GetEdmModel()); + options.AddRouteComponents("odata", GetEdmModel(defaultPageSize)); options.Select().Filter().Expand().OrderBy().Count().SetMaxTop(100); }) .AddJsonOptions(options => @@ -192,17 +192,18 @@ public static void ConfigurePipeline(WebApplication app, InvisibleApiKey invisib app.MapFallbackToFile("/index.html"); } - private static IEdmModel GetEdmModel() + private static IEdmModel GetEdmModel(int pageSize) { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); - builder.EntitySet("Consumers"); - builder.EntitySet("ConsumerAdoptions"); - builder.EntitySet("DecisionTypes"); - builder.EntitySet("Decisions"); - builder.EntitySet("Patients"); - builder.EntitySet("Audits"); + builder.EntitySet("Audits").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EntitySet("Decisions").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EntitySet("Patients").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + + builder.EntitySet("DecisionTypes") + .EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EnableLowerCamelCase(); return builder.GetEdmModel(); From 2fc04dc4e62aaf8aec3d03ed2d6c59cc035c0caa Mon Sep 17 00:00:00 2001 From: Joe Owens Date: Wed, 22 Oct 2025 11:05:01 +0100 Subject: [PATCH 3/3] CODE RUB: Moving to custom attribute to enforce page size on query --- .../ConfigurableEnableQueryAttribute.cs | 38 +++++++++++++++++++ .../ConsumerAdoptionsController.cs | 3 +- .../Consumers/ConsumersController.cs | 3 +- .../Controllers/DecisionTypesController.cs | 3 +- .../Controllers/DecisionsController.cs | 3 +- .../Controllers/PatientsController.cs | 3 +- .../Program.cs | 23 ++++------- .../appsettings.json | 3 +- .../ConfigurableEnableQueryAttribute.cs | 38 +++++++++++++++++++ .../Controllers/DecisionTypesController.cs | 3 +- .../Controllers/DecisionsController.cs | 3 +- .../Controllers/PatientsController.cs | 3 +- .../Program.cs | 16 +++----- .../appsettings.json | 3 +- 14 files changed, 102 insertions(+), 43 deletions(-) create mode 100644 LondonDataServices.IDecide.Manage.Server/ConfigurableEnableQueryAttribute.cs create mode 100644 LondonDataServices.IDecide.Portal.Server/ConfigurableEnableQueryAttribute.cs diff --git a/LondonDataServices.IDecide.Manage.Server/ConfigurableEnableQueryAttribute.cs b/LondonDataServices.IDecide.Manage.Server/ConfigurableEnableQueryAttribute.cs new file mode 100644 index 00000000..8ed0d460 --- /dev/null +++ b/LondonDataServices.IDecide.Manage.Server/ConfigurableEnableQueryAttribute.cs @@ -0,0 +1,38 @@ +// --------------------------------------------------------- +// Copyright (c) North East London ICB. All rights reserved. +// --------------------------------------------------------- + +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace LondonDataServices.IDecide.Manage.Server +{ + public class ConfigurableEnableQueryAttribute : EnableQueryAttribute + { + public override void OnActionExecuting(ActionExecutingContext actionContext) + { + int pageSize; + + var configuration = actionContext.HttpContext.RequestServices + .GetRequiredService(); + + var environment = actionContext.HttpContext.RequestServices + .GetRequiredService(); + + if (environment.IsDevelopment()) + { + pageSize = configuration.GetValue("OData:PageSize_Debug", 5000); + } + else + { + pageSize = configuration.GetValue("OData:PageSize_Release", 50); + } + + this.PageSize = pageSize; + base.OnActionExecuting(actionContext); + } + } +} diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs index b0ad2bb3..96354dfb 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/ConsumerAdoptions/ConsumerAdoptionsController.cs @@ -10,7 +10,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.ConsumerAdoptions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Manage.Server.Controllers @@ -60,7 +59,7 @@ public async ValueTask> PostConsumerAdoptionAsync } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Consumers")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs index f703c6d9..53f67a03 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/Consumers/ConsumersController.cs @@ -10,7 +10,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.Consumers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Manage.Server.Controllers @@ -60,7 +59,7 @@ public async ValueTask> PostConsumerAsync([FromBody] Cons } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs index c11ca85b..3cac3f7a 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionTypesController.cs @@ -10,7 +10,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.DecisionTypes; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Manage.Server.Controllers @@ -60,7 +59,7 @@ public async ValueTask> PostDecisionTypeAsync([FromBo } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Agents")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs index 808cba6e..b4a8e378 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/DecisionsController.cs @@ -10,7 +10,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.Decisions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Manage.Server.Controllers @@ -60,7 +59,7 @@ public async ValueTask> PostDecisionAsync([FromBody] Deci } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Agents")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs b/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs index b213f6b0..7f08ced8 100644 --- a/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs +++ b/LondonDataServices.IDecide.Manage.Server/Controllers/PatientsController.cs @@ -10,7 +10,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.Patients; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Manage.Server.Controllers @@ -60,7 +59,7 @@ public async ValueTask> PostPatientAsync([FromBody] Patien } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [Authorize(Roles = "LondonDataServices.IDecide.Manage.Server.Administrators,LondonDataServices.IDecide.Manage.Server.Agents")] public async ValueTask>> Get() { diff --git a/LondonDataServices.IDecide.Manage.Server/Program.cs b/LondonDataServices.IDecide.Manage.Server/Program.cs index c266e1b1..f1f0f894 100644 --- a/LondonDataServices.IDecide.Manage.Server/Program.cs +++ b/LondonDataServices.IDecide.Manage.Server/Program.cs @@ -137,12 +137,10 @@ public static void ConfigureServices( builder.Services.AddSingleton(builder.Configuration); JsonNamingPolicy jsonNamingPolicy = JsonNamingPolicy.CamelCase; - int defaultPageSize = builder.Configuration.GetValue("OData:PageSize", 50); - builder.Services.AddControllers() .AddOData(options => { - options.AddRouteComponents("odata", GetEdmModel(defaultPageSize)); + options.AddRouteComponents("odata", GetEdmModel()); options.Select().Filter().Expand().OrderBy().Count().SetMaxTop(100); }) .AddJsonOptions(options => @@ -183,22 +181,17 @@ public static void ConfigurePipeline(WebApplication app, InvisibleApiKey invisib app.MapFallbackToFile("/index.html"); } - private static IEdmModel GetEdmModel(int pageSize) + private static IEdmModel GetEdmModel() { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); - builder.EntitySet("Audits").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - builder.EntitySet("Consumers").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - builder.EntitySet("Decisions").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - builder.EntitySet("Patients").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - - builder.EntitySet("ConsumerAdoptions") - .EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - - builder.EntitySet("DecisionTypes") - .EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - + builder.EntitySet("Audits"); + builder.EntitySet("Consumers"); + builder.EntitySet("Decisions"); + builder.EntitySet("Patients"); + builder.EntitySet("ConsumerAdoptions"); + builder.EntitySet("DecisionTypes"); builder.EnableLowerCamelCase(); return builder.GetEdmModel(); diff --git a/LondonDataServices.IDecide.Manage.Server/appsettings.json b/LondonDataServices.IDecide.Manage.Server/appsettings.json index f809752d..3cb8f9d1 100644 --- a/LondonDataServices.IDecide.Manage.Server/appsettings.json +++ b/LondonDataServices.IDecide.Manage.Server/appsettings.json @@ -6,7 +6,8 @@ } }, "OData": { - "PageSize": 50 + "PageSize_Debug": 5000, + "PageSize_Release": 50 }, "ConnectionStrings": { "IDecideConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=IDecide;Trusted_Connection=True;MultipleActiveResultSets=true" diff --git a/LondonDataServices.IDecide.Portal.Server/ConfigurableEnableQueryAttribute.cs b/LondonDataServices.IDecide.Portal.Server/ConfigurableEnableQueryAttribute.cs new file mode 100644 index 00000000..84ab0fdb --- /dev/null +++ b/LondonDataServices.IDecide.Portal.Server/ConfigurableEnableQueryAttribute.cs @@ -0,0 +1,38 @@ +// --------------------------------------------------------- +// Copyright (c) North East London ICB. All rights reserved. +// --------------------------------------------------------- + +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace LondonDataServices.IDecide.Portal.Server +{ + public class ConfigurableEnableQueryAttribute : EnableQueryAttribute + { + public override void OnActionExecuting(ActionExecutingContext actionContext) + { + int pageSize; + + var configuration = actionContext.HttpContext.RequestServices + .GetRequiredService(); + + var environment = actionContext.HttpContext.RequestServices + .GetRequiredService(); + + if (environment.IsDevelopment()) + { + pageSize = configuration.GetValue("OData:PageSize_Debug", 5000); + } + else + { + pageSize = configuration.GetValue("OData:PageSize_Release", 50); + } + + this.PageSize = pageSize; + base.OnActionExecuting(actionContext); + } + } +} diff --git a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs index 16a4bdcd..608c61bf 100644 --- a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs +++ b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionTypesController.cs @@ -11,7 +11,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.DecisionTypes; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Portal.Server.Controllers @@ -61,7 +60,7 @@ public async ValueTask> PostDecisionTypeAsync([FromBo } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [InvisibleApi] [Authorize(Roles = "LondonDataServices.IDecide.Portal.Server.Administrators")] public async ValueTask>> Get() diff --git a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs index 351dbab1..65f6e2db 100644 --- a/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs +++ b/LondonDataServices.IDecide.Portal.Server/Controllers/DecisionsController.cs @@ -11,7 +11,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.Decisions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Portal.Server.Controllers @@ -61,7 +60,7 @@ public async ValueTask> PostDecisionAsync([FromBody] Deci } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [InvisibleApi] [Authorize(Roles = "LondonDataServices.IDecide.Portal.Server.Administrators")] public async ValueTask>> Get() diff --git a/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs b/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs index 4e4bd93b..5bad6e3c 100644 --- a/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs +++ b/LondonDataServices.IDecide.Portal.Server/Controllers/PatientsController.cs @@ -11,7 +11,6 @@ using LondonDataServices.IDecide.Core.Services.Foundations.Patients; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.OData.Query; using RESTFulSense.Controllers; namespace LondonDataServices.IDecide.Portal.Server.Controllers @@ -61,7 +60,7 @@ public async ValueTask> PostPatientAsync([FromBody] Patien } [HttpGet] - [EnableQuery] + [ConfigurableEnableQuery] [InvisibleApi] [Authorize(Roles = "LondonDataServices.IDecide.Portal.Server.Administrators")] public async ValueTask>> Get() diff --git a/LondonDataServices.IDecide.Portal.Server/Program.cs b/LondonDataServices.IDecide.Portal.Server/Program.cs index ff5c8050..61ecf4bf 100644 --- a/LondonDataServices.IDecide.Portal.Server/Program.cs +++ b/LondonDataServices.IDecide.Portal.Server/Program.cs @@ -146,12 +146,10 @@ public static void ConfigureServices( builder.Services.AddSingleton(builder.Configuration); JsonNamingPolicy jsonNamingPolicy = JsonNamingPolicy.CamelCase; - int defaultPageSize = builder.Configuration.GetValue("OData:PageSize", 50); - builder.Services.AddControllers() .AddOData(options => { - options.AddRouteComponents("odata", GetEdmModel(defaultPageSize)); + options.AddRouteComponents("odata", GetEdmModel()); options.Select().Filter().Expand().OrderBy().Count().SetMaxTop(100); }) .AddJsonOptions(options => @@ -192,17 +190,15 @@ public static void ConfigurePipeline(WebApplication app, InvisibleApiKey invisib app.MapFallbackToFile("/index.html"); } - private static IEdmModel GetEdmModel(int pageSize) + private static IEdmModel GetEdmModel() { ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); - builder.EntitySet("Audits").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - builder.EntitySet("Decisions").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - builder.EntitySet("Patients").EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); - - builder.EntitySet("DecisionTypes") - .EntityType.Page(maxTopValue: pageSize, pageSizeValue: pageSize); + builder.EntitySet("Audits"); + builder.EntitySet("Decisions"); + builder.EntitySet("Patients"); + builder.EntitySet("DecisionTypes"); builder.EnableLowerCamelCase(); diff --git a/LondonDataServices.IDecide.Portal.Server/appsettings.json b/LondonDataServices.IDecide.Portal.Server/appsettings.json index 598cbaf5..4516dc29 100644 --- a/LondonDataServices.IDecide.Portal.Server/appsettings.json +++ b/LondonDataServices.IDecide.Portal.Server/appsettings.json @@ -6,7 +6,8 @@ } }, "OData": { - "PageSize": 50 + "PageSize_Debug": 5000, + "PageSize_Release": 50 }, "ConnectionStrings": { "IDecideConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=IDecide;Trusted_Connection=True;MultipleActiveResultSets=true"