Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.x'
dotnet-version: '9.x'

- name: Restore dependencies
run: dotnet restore
Expand Down
14 changes: 10 additions & 4 deletions NorthwindCRUD.Tests/NorthwindCRUD.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -16,14 +16,20 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.9.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.9.3" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />

</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions NorthwindCRUD.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32526.322
# Visual Studio Version 18
VisualStudioVersion = 18.0.11104.47 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NorthwindCRUD", "NorthwindCRUD\NorthwindCRUD.csproj", "{43E42C18-0E59-4754-ADF1-25D90114F7E8}"
EndProject
Expand Down
83 changes: 0 additions & 83 deletions NorthwindCRUD/Controllers/QueryBuilderController.cs

This file was deleted.

8 changes: 6 additions & 2 deletions NorthwindCRUD/Filters/EnumSchemaFilter.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
using Microsoft.OpenApi.Any;
using System.Reflection;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;

namespace NorthwindCRUD.Filters
{
public class EnumSchemaFilter : ISchemaFilter
{
private static readonly Assembly CurrentAssembly = typeof(EnumSchemaFilter).Assembly;

public void Apply(OpenApiSchema schema, SchemaFilterContext context)
{
if (context.Type.IsEnum)
if (context.Type.IsEnum && context.Type.Assembly == CurrentAssembly)
{
schema.Type = "string";
schema.Enum = context.Type
.GetEnumNames()
.Select(name => new OpenApiString(name))
.ToList<IOpenApiAny>();
schema.Format = null;
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions NorthwindCRUD/Models/Results/QueryBuilderResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Newtonsoft.Json;
using NorthwindCRUD.Models.Dtos;

namespace NorthwindCRUD.Models
{
public class QueryBuilderResult
{
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public AddressDto[] Addresses { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public CategoryDto[] Categories { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public ProductDto[] Products { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public RegionDto[] Regions { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public TerritoryDto[] Territories { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public EmployeeDto[] Employees { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public CustomerDto[] Customers { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public OrderDto[] Orders { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public OrderDetailDto[] OrderDetails { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public ShipperDto[] Shippers { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public SupplierDto[] Suppliers { get; set; }
}
}
31 changes: 16 additions & 15 deletions NorthwindCRUD/NorthwindCRUD.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>

Expand All @@ -20,31 +20,32 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="AutoMapper" Version="14.0.0" />
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="GraphQL.AspNet" Version="0.12.2-beta" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.8">
<PackageReference Include="Infragistics.QueryBuilder.Executor" Version="0.1.1-prerelease.5" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.22" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.8">
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="9.0.1" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
14 changes: 9 additions & 5 deletions NorthwindCRUD/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text;
using AutoMapper;
using GraphQL.AspNet.Configuration.Mvc;
using Infragistics.QueryBuilder.Executor;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
Expand All @@ -9,6 +10,7 @@
using NorthwindCRUD.Filters;
using NorthwindCRUD.Helpers;
using NorthwindCRUD.Middlewares;
using NorthwindCRUD.Models;
using NorthwindCRUD.Providers;
using NorthwindCRUD.Services;

Expand Down Expand Up @@ -80,13 +82,13 @@ public static void Main(string[] args)
configurationProvider.ConfigureOptions(options);
});

var config = new MapperConfiguration(cfg =>
builder.Services.AddQueryBuilder<DataContext, QueryBuilderResult>();

var mapperConfig = new MapperConfiguration(static cfg =>
{
cfg.AddProfile(new MappingProfiles());
});

var mapper = config.CreateMapper();

var mapper = mapperConfig.CreateMapper();
builder.Services.AddSingleton(mapper);

builder.Services.AddAuthentication(options =>
Expand All @@ -100,7 +102,7 @@ public static void Main(string[] args)
{
ValidIssuer = builder.Configuration["Jwt:Issuer"],
ValidAudience = builder.Configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])),
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"] !)),
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = false,
Expand Down Expand Up @@ -159,6 +161,8 @@ public static void Main(string[] args)

app.MapControllers();

app.UseQueryBuilder<DataContext, QueryBuilderResult>("/QueryBuilder/ExecuteQuery");

app.Run();
}
}
Expand Down
7 changes: 4 additions & 3 deletions NorthwindCRUD/Providers/DbContextConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void ConfigureOptions(DbContextOptionsBuilder options)

var cacheKey = string.Format(CultureInfo.InvariantCulture, DatabaseConnectionCacheKey, tenantId);

if (!memoryCache.TryGetValue(cacheKey, out SqliteConnection connection))
if (!memoryCache.TryGetValue(cacheKey, out SqliteConnection? connection))
{
// Create a cached connection to seed the database and keep the data alive
connection = new SqliteConnection(connectionString);
Expand Down Expand Up @@ -78,7 +78,7 @@ private static void SeedDb(DbContextOptionsBuilder optionsBuilder)
DBSeeder.Seed(dataContext);
}

private static void CloseConnection(object key, object value, EvictionReason reason, object state)
private static void CloseConnection(object key, object? value, EvictionReason reason, object? state)
{
//Used to clear datasource from memory.
(value as SqliteConnection)?.Close();
Expand All @@ -99,7 +99,8 @@ private MemoryCacheEntryOptions GetCacheConnectionEntryOptions()

private string GetSqlLiteConnectionString(string tenantId)
{
var connectionStringTemplate = configuration.GetConnectionString("SQLiteConnectionString");
var connectionStringTemplate = configuration.GetConnectionString("SQLiteConnectionString")
?? throw new InvalidOperationException("SQLiteConnectionString not found");
var unsanitizedConntectionString = string.Format(CultureInfo.InvariantCulture, connectionStringTemplate, tenantId);
var connectionStringBuilder = new SqliteConnectionStringBuilder(unsanitizedConntectionString);
var sanitizedConntectionString = connectionStringBuilder.ToString();
Expand Down
7 changes: 0 additions & 7 deletions NorthwindCRUD/QueryBuilder/Model/FilterType.cs

This file was deleted.

12 changes: 0 additions & 12 deletions NorthwindCRUD/QueryBuilder/Model/Query.cs

This file was deleted.

20 changes: 0 additions & 20 deletions NorthwindCRUD/QueryBuilder/Model/QueryFilter.cs

This file was deleted.

10 changes: 0 additions & 10 deletions NorthwindCRUD/QueryBuilder/Model/QueryFilterCondition.cs

This file was deleted.

Loading