From 22e9856a448ff0928aa1c1f327967cd399dec422 Mon Sep 17 00:00:00 2001 From: Craig Edmunds Date: Tue, 28 Jan 2025 10:31:23 +0000 Subject: [PATCH] Fixing sonarqube --- .../ImportNotificationsAggregationService.cs | 2 +- Btms.Backend/Config/AnalyticsDashboards.cs | 81 +++---------------- Btms.Backend/Program.cs | 12 --- 3 files changed, 10 insertions(+), 85 deletions(-) diff --git a/Btms.Analytics/ImportNotificationsAggregationService.cs b/Btms.Analytics/ImportNotificationsAggregationService.cs index 76a503de..b279b739 100644 --- a/Btms.Analytics/ImportNotificationsAggregationService.cs +++ b/Btms.Analytics/ImportNotificationsAggregationService.cs @@ -163,7 +163,7 @@ public Task> ByCommodityCount(DateT public Task ByMaxVersion(DateTime from, DateTime to, bool finalisedOnly, ImportNotificationTypeEnum[]? chedTypes = null, string? country = null) { - // TODO : At the moment this doesn't filter on finalisedOnly as thats not stored anywhere on the notification + // NB : At the moment this doesn't filter on finalisedOnly as thats not stored anywhere on the notification // we'd need to denormalise the field, perhaps onto the relationship, to allow this filtering. var data = context diff --git a/Btms.Backend/Config/AnalyticsDashboards.cs b/Btms.Backend/Config/AnalyticsDashboards.cs index f1973a41..8f83385b 100644 --- a/Btms.Backend/Config/AnalyticsDashboards.cs +++ b/Btms.Backend/Config/AnalyticsDashboards.cs @@ -10,84 +10,21 @@ namespace Btms.Backend.Config; - -[ModelBinder(BinderType = typeof(DateRangeBinder))] public class DateRange { [FromQuery(Name = "dateFrom")] public DateTime? From { get; set; } [FromQuery(Name = "dateTo")] public DateTime? To { get; set; } - public static DateRange Default() - { - return new DateRange() { From = DateTime.Now, To = DateTime.Now }; - } - public static bool TryParse(string query, out DateRange dateRange) - { - dateRange = new DateRange() { From = DateTime.Now, To = DateTime.Now }; - return true; - } -} - -public class DateRangeBinderProvider : IModelBinderProvider -{ - public DateRangeBinderProvider() - { - Console.WriteLine("Testing12"); - } - public IModelBinder GetBinder(ModelBinderProviderContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - if (context.Metadata.ModelType == typeof(DateRange)) - { - return new BinderTypeModelBinder(typeof(DateRangeBinder)); - } - - return new BinderTypeModelBinder(context.Metadata.ModelType); - // ; - // return null!; //new BinderTypeModelBinder(); - } -} - -public class DateRangeBinder: IModelBinder -{ - public DateRangeBinder() - { - Console.WriteLine("Testing12"); - } - public Task BindModelAsync(ModelBindingContext bindingContext) - { - if (bindingContext == null) - { - throw new ArgumentNullException(nameof(bindingContext)); - } - - var dateFrom = bindingContext.ValueProvider.GetValue("dateFrom").FirstValue; - var dateTo = bindingContext.ValueProvider.GetValue("dateTo").FirstValue; - - var dateRange = new DateRange() - { - From = DateTime.Now, To = DateTime.Now - }; - // var name = bindingContext.ValueProvider.GetValue("name").FirstValue; - // var beginName = bindingContext.ValueProvider.GetValue("name:contains").FirstValue; - // var exactName = bindingContext.ValueProvider.GetValue("name:exact").FirstValue; - // if (name.ToLower().Contains("tom")) { - // model1.name = name; - // } - // if (beginName.ToLower().StartsWith("tom")) { - // model1.beginName = beginName; - // } - // if (exactName.Contains("Tom")) { - // model1.exactName = exactName; - // } - bindingContext.Result = ModelBindingResult.Success(dateRange); - return Task.CompletedTask; - } + // public static DateRange Default() + // { + // return new DateRange() { From = DateTime.Now, To = DateTime.Now }; + // } + // public static bool TryParse(string query, out DateRange dateRange) + // { + // dateRange = new DateRange() { From = DateTime.Now, To = DateTime.Now }; + // return true; + // } } public static class AnalyticsDashboards diff --git a/Btms.Backend/Program.cs b/Btms.Backend/Program.cs index 76ce1eda..d76950eb 100644 --- a/Btms.Backend/Program.cs +++ b/Btms.Backend/Program.cs @@ -26,7 +26,6 @@ using JsonApiDotNetCore.Serialization.Response; using Microsoft.AspNetCore.Diagnostics.HealthChecks; using Microsoft.Extensions.Options; -// using Microsoft.AspNetCore.Mvc.ModelBinding.Binders; using OpenTelemetry; using OpenTelemetry.Metrics; using OpenTelemetry.Trace; @@ -75,8 +74,6 @@ static void ConfigureWebApplication(WebApplicationBuilder builder) builder.Configuration.AddEnvironmentVariables(); builder.Services.AddOutputCache(options => { - // options.AddBasePolicy(builder => - // builder.Expire(TimeSpan.FromMinutes(10))); options.AddPolicy("Expire10Min", builder => builder.Expire(TimeSpan.FromMinutes(10))); } @@ -102,15 +99,6 @@ static void ConfigureWebApplication(WebApplicationBuilder builder) builder.Services.AddBusinessServices(builder.Configuration); builder.Services.AddConsumers(builder.Configuration); - - // var provider = new SimpleTypeModelBinderProvider( - // typeof(DateRange), new AnalyticsEndpoints.DateRangeBinder()); - // - // builder.Services.Insert(typeof(ModelBinderProvider), 0, provider); - builder.Services.AddControllers(options => - { - options.ModelBinderProviders.Insert(0, new DateRangeBinderProvider()); - }); ConfigureEndpoints(builder);