From eb7a67a2e1847e0b61a78ba940c80d36994c0c05 Mon Sep 17 00:00:00 2001 From: Louis-Axel Ambroise Date: Thu, 9 Feb 2023 14:52:48 +0100 Subject: [PATCH 1/2] Fix subscription storage --- .../Database/EpcisModelConfiguration.cs | 7 +++---- src/FasTnT.Application/Handlers/QueriesHandler.cs | 1 - src/FasTnT.Application/Handlers/SubscriptionsHandler.cs | 1 - src/FasTnT.Domain/FasTnT.Domain.csproj | 3 +++ .../Model/CustomQueries/StoredQueryParameter.cs | 8 -------- .../QueryDefinition.cs => Queries/StoredQuery.cs} | 4 ++-- .../v2_0/Communication/Json/Parsers/JsonRequestParser.cs | 6 +++--- .../v2_0/Endpoints/Interfaces/CreateCustomQueryRequest.cs | 2 +- .../Features/v2_0/Endpoints/SubscriptionEndpoints.cs | 1 + .../Queries/WhenHandlingGetQueryNamesQuery.cs | 1 - 10 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 src/FasTnT.Domain/Model/CustomQueries/StoredQueryParameter.cs rename src/FasTnT.Domain/Model/{CustomQueries/QueryDefinition.cs => Queries/StoredQuery.cs} (53%) diff --git a/src/FasTnT.Application/Database/EpcisModelConfiguration.cs b/src/FasTnT.Application/Database/EpcisModelConfiguration.cs index 380c5e36..2826b3f7 100644 --- a/src/FasTnT.Application/Database/EpcisModelConfiguration.cs +++ b/src/FasTnT.Application/Database/EpcisModelConfiguration.cs @@ -1,6 +1,5 @@ using FasTnT.Application.Database; using FasTnT.Domain.Model; -using FasTnT.Domain.Model.CustomQueries; using FasTnT.Domain.Model.Events; using FasTnT.Domain.Model.Masterdata; using FasTnT.Domain.Model.Queries; @@ -279,7 +278,7 @@ public static void Apply(ModelBuilder modelBuilder) subscription.OwnsMany(x => x.Parameters, c => { c.ToTable("SubscriptionParameter", Subscriptions); - c.Property("SubscriptionId").IsRequired(true); + c.WithOwner().HasForeignKey("SubscriptionId"); c.HasKey("SubscriptionId", nameof(QueryParameter.Name)); c.Property(x => x.Values).IsRequired(false).HasJsonArrayConversion(); c.Property(x => x.Name).HasMaxLength(256).IsRequired(true); @@ -310,8 +309,8 @@ public static void Apply(ModelBuilder modelBuilder) storedQuery.OwnsMany(x => x.Parameters, c => { c.ToTable("StoredQueryParameter", Queries); - c.Property("QueryId"); - c.HasKey("QueryId", nameof(StoredQueryParameter.Name)); + c.WithOwner().HasForeignKey("QueryId"); + c.HasKey("QueryId", nameof(QueryParameter.Name)); c.Property(x => x.Values).IsRequired(false).HasJsonArrayConversion(); c.Property(x => x.Name).HasMaxLength(256).IsRequired(true); }); diff --git a/src/FasTnT.Application/Handlers/QueriesHandler.cs b/src/FasTnT.Application/Handlers/QueriesHandler.cs index 0a578ece..6cf6841e 100644 --- a/src/FasTnT.Application/Handlers/QueriesHandler.cs +++ b/src/FasTnT.Application/Handlers/QueriesHandler.cs @@ -1,7 +1,6 @@ using FasTnT.Application.Database; using FasTnT.Application.Services.Users; using FasTnT.Domain.Exceptions; -using FasTnT.Domain.Model.CustomQueries; using FasTnT.Domain.Model.Queries; using FasTnT.Domain.Model.Subscriptions; using Microsoft.EntityFrameworkCore; diff --git a/src/FasTnT.Application/Handlers/SubscriptionsHandler.cs b/src/FasTnT.Application/Handlers/SubscriptionsHandler.cs index 9901cef5..29f68a8d 100644 --- a/src/FasTnT.Application/Handlers/SubscriptionsHandler.cs +++ b/src/FasTnT.Application/Handlers/SubscriptionsHandler.cs @@ -52,7 +52,6 @@ public async Task GetSubscriptionDetailsAsync(string name, Cancell var subscription = await _context.Set() .AsNoTracking() .Where(x => x.Name == name) - .Include(x => x.Parameters) .FirstOrDefaultAsync(x => x.Name == name, cancellationToken); if (subscription is null) diff --git a/src/FasTnT.Domain/FasTnT.Domain.csproj b/src/FasTnT.Domain/FasTnT.Domain.csproj index 115143ce..d9ebe6a2 100644 --- a/src/FasTnT.Domain/FasTnT.Domain.csproj +++ b/src/FasTnT.Domain/FasTnT.Domain.csproj @@ -4,4 +4,7 @@ 10 disable + + + diff --git a/src/FasTnT.Domain/Model/CustomQueries/StoredQueryParameter.cs b/src/FasTnT.Domain/Model/CustomQueries/StoredQueryParameter.cs deleted file mode 100644 index ee73b787..00000000 --- a/src/FasTnT.Domain/Model/CustomQueries/StoredQueryParameter.cs +++ /dev/null @@ -1,8 +0,0 @@ -using FasTnT.Domain.Model.Queries; - -namespace FasTnT.Domain.Model.CustomQueries; - -public class StoredQueryParameter : QueryParameter -{ - public StoredQuery Query { get; set; } -} \ No newline at end of file diff --git a/src/FasTnT.Domain/Model/CustomQueries/QueryDefinition.cs b/src/FasTnT.Domain/Model/Queries/StoredQuery.cs similarity index 53% rename from src/FasTnT.Domain/Model/CustomQueries/QueryDefinition.cs rename to src/FasTnT.Domain/Model/Queries/StoredQuery.cs index 383f3ca4..07743b18 100644 --- a/src/FasTnT.Domain/Model/CustomQueries/QueryDefinition.cs +++ b/src/FasTnT.Domain/Model/Queries/StoredQuery.cs @@ -1,9 +1,9 @@ -namespace FasTnT.Domain.Model.CustomQueries; +namespace FasTnT.Domain.Model.Queries; public class StoredQuery { public int Id { get; set; } public string Name { get; set; } public string UserId { get; set; } - public List Parameters { get; set; } = new(); + public List Parameters { get; set; } = new(); } diff --git a/src/FasTnT.Host/Features/v2_0/Communication/Json/Parsers/JsonRequestParser.cs b/src/FasTnT.Host/Features/v2_0/Communication/Json/Parsers/JsonRequestParser.cs index 14fa045e..228b8ef8 100644 --- a/src/FasTnT.Host/Features/v2_0/Communication/Json/Parsers/JsonRequestParser.cs +++ b/src/FasTnT.Host/Features/v2_0/Communication/Json/Parsers/JsonRequestParser.cs @@ -1,4 +1,4 @@ -using FasTnT.Domain.Model.CustomQueries; +using FasTnT.Domain.Model.Queries; using FasTnT.Domain.Model.Subscriptions; using FasTnT.Host.Features.v2_0.Subscriptions; using System.Text.Json; @@ -51,9 +51,9 @@ private static SubscriptionSchedule ParseSubscriptionSchedule(JsonElement jsonEl }; } - private static List ParseQueryParameters(JsonElement jsonElement) + private static List ParseQueryParameters(JsonElement jsonElement) { - var parameters = new List(); + var parameters = new List(); if (jsonElement.ValueKind == JsonValueKind.Object) { diff --git a/src/FasTnT.Host/Features/v2_0/Endpoints/Interfaces/CreateCustomQueryRequest.cs b/src/FasTnT.Host/Features/v2_0/Endpoints/Interfaces/CreateCustomQueryRequest.cs index a99c4e5c..217a44a3 100644 --- a/src/FasTnT.Host/Features/v2_0/Endpoints/Interfaces/CreateCustomQueryRequest.cs +++ b/src/FasTnT.Host/Features/v2_0/Endpoints/Interfaces/CreateCustomQueryRequest.cs @@ -1,4 +1,4 @@ -using FasTnT.Domain.Model.CustomQueries; +using FasTnT.Domain.Model.Queries; using FasTnT.Host.Features.v2_0.Communication.Json.Parsers; namespace FasTnT.Host.Features.v2_0.Endpoints.Interfaces; diff --git a/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs b/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs index 3ba572bb..cec455b1 100644 --- a/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs +++ b/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs @@ -1,4 +1,5 @@ using FasTnT.Application.Handlers; +using FasTnT.Domain.Model.CustomQueries; using FasTnT.Host.Features.v2_0.Endpoints.Interfaces; using FasTnT.Host.Features.v2_0.Endpoints.Interfaces.Utils; using FasTnT.Host.Features.v2_0.Subscriptions; diff --git a/tests/FasTnT.Application.Tests/Queries/WhenHandlingGetQueryNamesQuery.cs b/tests/FasTnT.Application.Tests/Queries/WhenHandlingGetQueryNamesQuery.cs index 55876600..004b20d2 100644 --- a/tests/FasTnT.Application.Tests/Queries/WhenHandlingGetQueryNamesQuery.cs +++ b/tests/FasTnT.Application.Tests/Queries/WhenHandlingGetQueryNamesQuery.cs @@ -2,7 +2,6 @@ using FasTnT.Application.Handlers; using FasTnT.Application.Services.Users; using FasTnT.Application.Tests.Context; -using FasTnT.Domain.Model.CustomQueries; using FasTnT.Domain.Model.Queries; namespace FasTnT.Application.Tests.Queries; From e1fb221f357317c6b0796df55604a375a9fc6dee Mon Sep 17 00:00:00 2001 From: Louis-Axel Ambroise Date: Thu, 9 Feb 2023 14:54:54 +0100 Subject: [PATCH 2/2] Fix using --- src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs b/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs index cec455b1..3ba572bb 100644 --- a/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs +++ b/src/FasTnT.Host/Features/v2_0/Endpoints/SubscriptionEndpoints.cs @@ -1,5 +1,4 @@ using FasTnT.Application.Handlers; -using FasTnT.Domain.Model.CustomQueries; using FasTnT.Host.Features.v2_0.Endpoints.Interfaces; using FasTnT.Host.Features.v2_0.Endpoints.Interfaces.Utils; using FasTnT.Host.Features.v2_0.Subscriptions;