Skip to content

Commit

Permalink
Fixing sonarqube
Browse files Browse the repository at this point in the history
  • Loading branch information
craigedmunds committed Jan 28, 2025
1 parent c25b858 commit 22e9856
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 85 deletions.
2 changes: 1 addition & 1 deletion Btms.Analytics/ImportNotificationsAggregationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public Task<MultiSeriesDataset<ByNumericDimensionResult>> ByCommodityCount(DateT

public Task<SingleSeriesDataset> 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
Expand Down
81 changes: 9 additions & 72 deletions Btms.Backend/Config/AnalyticsDashboards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions Btms.Backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
Expand All @@ -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);

Expand Down

0 comments on commit 22e9856

Please sign in to comment.