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 7a3a394a..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,12 +59,7 @@ public async ValueTask> PostConsumerAdoptionAsync } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [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 41381d77..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,12 +59,7 @@ public async ValueTask> PostConsumerAsync([FromBody] Cons } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 20)] -#endif + [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 4035cd01..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,12 +59,7 @@ public async ValueTask> PostDecisionTypeAsync([FromBo } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [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 6f5a5686..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,12 +59,7 @@ public async ValueTask> PostDecisionAsync([FromBody] Deci } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [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 dadae814..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,12 +59,7 @@ public async ValueTask> PostPatientAsync([FromBody] Patien } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [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 ad96433d..f1f0f894 100644 --- a/LondonDataServices.IDecide.Manage.Server/Program.cs +++ b/LondonDataServices.IDecide.Manage.Server/Program.cs @@ -33,6 +33,7 @@ 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; @@ -186,10 +187,11 @@ private static IEdmModel GetEdmModel() new ODataConventionModelBuilder(); builder.EntitySet("Audits"); - builder.EntitySet("Patients"); - builder.EntitySet("Decisions"); 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 0083e7a9..3cb8f9d1 100644 --- a/LondonDataServices.IDecide.Manage.Server/appsettings.json +++ b/LondonDataServices.IDecide.Manage.Server/appsettings.json @@ -5,6 +5,10 @@ "Microsoft.AspNetCore": "Warning" } }, + "OData": { + "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 3997c7ac..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,12 +60,7 @@ public async ValueTask> PostDecisionTypeAsync([FromBo } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [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 453062bf..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,12 +60,7 @@ public async ValueTask> PostDecisionAsync([FromBody] Deci } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [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 c75080b6..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,12 +60,7 @@ public async ValueTask> PostPatientAsync([FromBody] Patien } [HttpGet] -#if !DEBUG - [EnableQuery(PageSize = 50)] -#endif -#if DEBUG - [EnableQuery(PageSize = 5000)] -#endif + [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 092cf75c..61ecf4bf 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; @@ -197,12 +195,11 @@ private static IEdmModel GetEdmModel() ODataConventionModelBuilder builder = new ODataConventionModelBuilder(); - builder.EntitySet("Consumers"); - builder.EntitySet("ConsumerAdoptions"); - builder.EntitySet("DecisionTypes"); + builder.EntitySet("Audits"); builder.EntitySet("Decisions"); builder.EntitySet("Patients"); - builder.EntitySet("Audits"); + builder.EntitySet("DecisionTypes"); + builder.EnableLowerCamelCase(); return builder.GetEdmModel(); diff --git a/LondonDataServices.IDecide.Portal.Server/appsettings.json b/LondonDataServices.IDecide.Portal.Server/appsettings.json index 1fb8b543..4516dc29 100644 --- a/LondonDataServices.IDecide.Portal.Server/appsettings.json +++ b/LondonDataServices.IDecide.Portal.Server/appsettings.json @@ -5,6 +5,10 @@ "Microsoft.AspNetCore": "Warning" } }, + "OData": { + "PageSize_Debug": 5000, + "PageSize_Release": 50 + }, "ConnectionStrings": { "IDecideConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=IDecide;Trusted_Connection=True;MultipleActiveResultSets=true" },