diff --git a/.azure/main.parameters.json b/.azure/main.parameters.json index 9f187f433..d810916f1 100644 --- a/.azure/main.parameters.json +++ b/.azure/main.parameters.json @@ -16,4 +16,4 @@ "value": "norwayeast" } } -} \ No newline at end of file +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..dd450888a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,64 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# See also Directory.Build.Props for additional analyzer settings + +root = true + +[*] +# Enforce line endings to be LF +end_of_line = lf +# Enforce indentation to be 4 spaces +indent_style = spaces +indent_size = 4 +# Insert a final new line at the end of the file +insert_final_newline = true + +[*.cs] + +# CA1848: Use the LoggerMessage delegates +# TODO: Possible performance improvement +dotnet_diagnostic.CA1848.severity = none + +# Identifiers should not match keywords +dotnet_diagnostic.CA1716.severity = none + +# Style faults should be warnings +dotnet_analyzer_diagnostic.category-Style.severity = warning + +# +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity + +# Enforce file scoped namespaces +csharp_style_namespace_declarations = file_scoped:suggestion +# Place 'using' directives outside of namespaces +csharp_using_directive_placement = outside_namespace:true + +# Disabling this because of https://github.com/dotnet/roslyn/issues/41640 +dotnet_diagnostic.IDE0005.severity = none +# +# # Disabling this because of https://github.com/dotnet/roslyn/issues/70826 +# dotnet_diagnostic.IDE0028.severity = none +# +# # Primary constructors +# dotnet_diagnostic.IDE0290.severity = none + +# Order 'using' directives with System.* appearing first +dotnet_sort_system_directives_first = true +# Suggest the use of var when the type is apparent +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true:suggestion +# Suggest using expression bodies +csharp_style_expression_bodied_methods = when_on_single_line +dotnet_diagnostic.IDE0022.severity = suggestion +# Don't mix non-braces and braces for ifs +csharp_prefer_braces = when_multiline + +# "Expression body is never used" +dotnet_diagnostic.IDE0058.severity = none +# "'if' statement can be simplified" +dotnet_diagnostic.IDE0046.severity = suggestion +# "Do not declare static members on generic types" +dotnet_diagnostic.CA1000.severity = none +# "Instantiate argument exceptions correctly" +dotnet_diagnostic.CA2208.severity = suggestion diff --git a/.gitattributes b/.gitattributes index d974b9866..b72c2c601 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,7 @@ ############################################################################### # Set default behavior to automatically normalize line endings. ############################################################################### -* text=auto -*.sh text eol=lf -**/all-tests.js eol=lf +* text eol=lf ############################################################################### # Set default behavior for command prompt diff. diff --git a/.github/workflows/main_latidafunction.yml b/.github/workflows/main_latidafunction.yml index fca3eb099..b25b25d59 100644 --- a/.github/workflows/main_latidafunction.yml +++ b/.github/workflows/main_latidafunction.yml @@ -1,42 +1,42 @@ -# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action -# More GitHub Actions for Azure: https://github.com/Azure/actions - -name: Build and deploy dotnet core app to Azure Function App - LatidaFunction - -on: - push: - branches: - - main - workflow_dispatch: - -env: - AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root - DOTNET_VERSION: '7.0.x' # set this to the dotnet version to use - -jobs: - build-and-deploy: - runs-on: windows-latest - steps: - - name: 'Checkout GitHub Action' - uses: actions/checkout@v4 - - - name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment - uses: actions/setup-dotnet@v1 - with: - dotnet-version: ${{ env.DOTNET_VERSION }} - - - name: 'Resolve Project Dependencies Using Dotnet' - shell: pwsh - run: | - pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}' - dotnet build --configuration Release --output ./output - popd - - - name: 'Run Azure Functions Action' - uses: Azure/functions-action@v1 - id: fa - with: - app-name: 'LatidaFunction' - slot-name: 'Production' - package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output' - publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_5B804973F87844089C37A81BF22B1261 }} +# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy dotnet core app to Azure Function App - LatidaFunction + +on: + push: + branches: + - main + workflow_dispatch: + +env: + AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root + DOTNET_VERSION: '7.0.x' # set this to the dotnet version to use + +jobs: + build-and-deploy: + runs-on: windows-latest + steps: + - name: 'Checkout GitHub Action' + uses: actions/checkout@v4 + + - name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: 'Resolve Project Dependencies Using Dotnet' + shell: pwsh + run: | + pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}' + dotnet build --configuration Release --output ./output + popd + + - name: 'Run Azure Functions Action' + uses: Azure/functions-action@v1 + id: fa + with: + app-name: 'LatidaFunction' + slot-name: 'Production' + package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output' + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_5B804973F87844089C37A81BF22B1261 }} diff --git a/Digdir.Domain.Dialogporten.sln b/Digdir.Domain.Dialogporten.sln index eacd30978..63c6e28d1 100644 --- a/Digdir.Domain.Dialogporten.sln +++ b/Digdir.Domain.Dialogporten.sln @@ -27,6 +27,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Digdir.Domain.Dialogporten. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{33E486B1-3279-4645-B536-AB640D560C45}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + Directory.Build.props = Directory.Build.props docker-compose.yml = docker-compose.yml README.md = README.md EndProjectSection diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 000000000..67b1f1d3c --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,14 @@ + + + + true + + + + true + Recommended + true + latest + + + diff --git a/src/Digdir.Domain.Dialogporten.Application/ApplicationExtensions.cs b/src/Digdir.Domain.Dialogporten.Application/ApplicationExtensions.cs index 0bc7bda36..d0f668929 100644 --- a/src/Digdir.Domain.Dialogporten.Application/ApplicationExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/ApplicationExtensions.cs @@ -42,14 +42,13 @@ public static IServiceCollection AddApplication(this IServiceCollection services .AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>)) .AddTransient(typeof(IPipelineBehavior<,>), typeof(DomainContextBehaviour<,>)); - if (environment.IsDevelopment()) - { - var localDeveloperSettings = configuration.GetLocalDevelopmentSettings(); - services.Decorate( - predicate: - localDeveloperSettings.UseLocalDevelopmentUser || - localDeveloperSettings.UseLocalDevelopmentResourceRegister); - } + if (!environment.IsDevelopment()) return services; + + var localDeveloperSettings = configuration.GetLocalDevelopmentSettings(); + services.Decorate( + predicate: + localDeveloperSettings.UseLocalDevelopmentUser || + localDeveloperSettings.UseLocalDevelopmentResourceRegister); return services; } diff --git a/src/Digdir.Domain.Dialogporten.Application/ApplicationSettings.cs b/src/Digdir.Domain.Dialogporten.Application/ApplicationSettings.cs index a919531c6..938707dd9 100644 --- a/src/Digdir.Domain.Dialogporten.Application/ApplicationSettings.cs +++ b/src/Digdir.Domain.Dialogporten.Application/ApplicationSettings.cs @@ -6,7 +6,7 @@ namespace Digdir.Domain.Dialogporten.Application; public sealed class ApplicationSettings { public const string ConfigurationSectionName = "Application"; - + public required DialogportenSettings Dialogporten { get; init; } } @@ -31,4 +31,4 @@ public DialogportenSettingsValidator() { RuleFor(x => x.BaseUri).NotEmpty().IsValidUri(); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/DomainContextBehaviour.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/DomainContextBehaviour.cs index e00135eda..6abb9527f 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/DomainContextBehaviour.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Behaviours/DomainContextBehaviour.cs @@ -26,7 +26,7 @@ internal sealed class DomainContextBehaviour : IPipelineBeh public DomainContextBehaviour(IDomainContext domainContext) { - + _domainContext = domainContext ?? throw new ArgumentNullException(nameof(domainContext)); } @@ -38,7 +38,7 @@ public async Task Handle(TRequest request, RequestHandlerDelegate Handle(TRequest request, RequestHandlerDelegate Handle(TRequest request, RequestHandlerDelegate x is not null) .ToList(); - if (!failures.Any()) + if (failures.Count == 0) { return await next(); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Expressions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Expressions.cs index 6cfe6d800..0c15b2a35 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Expressions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Expressions.cs @@ -8,8 +8,8 @@ internal static class Expressions { internal static Expression> LocalizedSearchExpression(string? search, string? cultureCode) { - return localization => - (cultureCode == null || localization.CultureCode == cultureCode) && + return localization => + (cultureCode == null || localization.CultureCode == cultureCode) && EF.Functions.ILike(localization.Value, $"%{search}%"); - } -} \ No newline at end of file + } +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/AutoMapperExtensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/AutoMapperExtensions.cs index 3f50731c4..d591de2de 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/AutoMapperExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/AutoMapperExtensions.cs @@ -29,10 +29,7 @@ public static IMappingExpression IgnoreComplexDestinationPropert private static bool IsSimple(this Type type) { - if (type is null) - { - throw new ArgumentNullException(nameof(type)); - } + ArgumentNullException.ThrowIfNull(type); if (type.IsGenericType && type.GetGenericTypeDefinition() == GenericNullableType) { diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ClaimsPrincipalExtensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ClaimsPrincipalExtensions.cs index 22d8b23fb..3909a446c 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ClaimsPrincipalExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ClaimsPrincipalExtensions.cs @@ -33,7 +33,7 @@ public static bool TryGetOrgNumber(this ClaimsPrincipal claimsPrincipal, [NotNul } if (!consumerClaimJson.TryGetValue(AuthorityClaim, out var authority) || - !string.Equals(authority, AuthorityValue, StringComparison.InvariantCultureIgnoreCase)) + !string.Equals(authority, AuthorityValue, StringComparison.OrdinalIgnoreCase)) { return false; } @@ -54,4 +54,4 @@ public static bool TryGetOrgNumber(this ClaimsPrincipal claimsPrincipal, [NotNul internal static bool TryGetOrgNumber(this IUser user, [NotNullWhen(true)] out string? orgNumber) => user.GetPrincipal().TryGetOrgNumber(out orgNumber); -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/MergeExtensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/MergeExtensions.cs index de959572a..f3518b704 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/MergeExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/MergeExtensions.cs @@ -12,8 +12,12 @@ namespace Digdir.Domain.Dialogporten.Application.Common.Extensions.Enumerable; internal static class DeleteDelegate { +#pragma warning disable IDE0060 + // ReSharper disable once MethodOverloadWithOptionalParameter public static Task NoOp(IEnumerable deletables, CancellationToken cancellationToken = default) => Task.CompletedTask; public static void NoOp(IEnumerable deletables) { /* No operation by design */ } +#pragma warning restore IDE0060 + } internal static class MergeExtensions @@ -130,17 +134,17 @@ private static async Task DeleteAsync( return; } - var deleates = destinations + var delegates = destinations .Except(updateSets.Select(x => x.Destination)) .ToList(); - if (deleates.Count == 0) + if (delegates.Count == 0) { return; } - await delete(deleates, cancellationToken); - foreach (var item in deleates) + await delete(delegates, cancellationToken); + foreach (var item in delegates) { destinations.Remove(item); } @@ -190,17 +194,17 @@ private static void Delete( return; } - var deleates = destinations + var delegates = destinations .Except(updateSets.Select(x => x.Destination)) .ToList(); - if (deleates.Count == 0) + if (delegates.Count == 0) { return; } - delete(deleates); - foreach (var item in deleates) + delete(delegates); + foreach (var item in delegates) { destinations.Remove(item); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/UpdateSet.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/UpdateSet.cs index e1ea9e727..2c9d02324 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/UpdateSet.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/Enumerable/UpdateSet.cs @@ -1,6 +1,6 @@ namespace Digdir.Domain.Dialogporten.Application.Common.Extensions.Enumerable; -internal readonly struct UpdateSet +internal readonly struct UpdateSet { public TDestination Destination { get; init; } public TSource Source { get; init; } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Enumerable_Extensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Enumerable_Extensions.cs index 40c9ad176..f459459f8 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Enumerable_Extensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Enumerable_Extensions.cs @@ -23,7 +23,7 @@ public static IRuleBuilderOptions> UniqueBy x.Key) .ToArray(); ctx.MessageFormatter.AppendArgument("DuplicateKeys", string.Join(",", duplicateKeys)); - return !duplicateKeys.Any(); + return duplicateKeys.Length == 0; }).WithMessage("Can not contain duplicate items: [{DuplicateKeys}]."); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_LocalizationDto_Extensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_LocalizationDto_Extensions.cs index ff27a4d99..66cb67188 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_LocalizationDto_Extensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_LocalizationDto_Extensions.cs @@ -4,12 +4,12 @@ namespace Digdir.Domain.Dialogporten.Application.Common.Extensions.FluentValidation; -internal static class FluentValidation_LocalizationDto_Extensions +internal static class FluentValidationLocalizationDtoExtensions { - private static readonly string[] AllowedTags = new[] { "p", "a", "br", "em", "strong", "ul", "ol", "li" }; - private static readonly string ContainsValidHttpError = + private static readonly string[] AllowedTags = { "p", "a", "br", "em", "strong", "ul", "ol", "li" }; + private static readonly string ContainsValidHttpError = $"{{PropertyName}} contains unsupported html. The following tags are supported: " + - $"[{string.Join(",", AllowedTags.Select(x => '<' + x + '>'))}]. Tag atributes " + + $"[{string.Join(",", AllowedTags.Select(x => '<' + x + '>'))}]. Tag attributes " + $"are not supported except for on '' which must contain a 'href' starting " + $"with 'https://'."; @@ -55,16 +55,16 @@ private static bool HtmlAgilityPackCheck(this string html) private static bool IsAnchorTag(this HtmlNode node) { - const string AnchorTag = "a"; - return node.Name == AnchorTag; + const string anchorTag = "a"; + return node.Name == anchorTag; } private static bool IsValidAnchorTag(this HtmlNode node) { - const string Https = "https://"; - const string Href = "href"; + const string https = "https://"; + const string href = "href"; return node.Attributes.Count == 1 && - node.Attributes[Href] is not null && - node.Attributes[Href].Value.StartsWith(Https); + node.Attributes[href] is not null && + node.Attributes[href].Value.StartsWith(https, StringComparison.InvariantCultureIgnoreCase); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Uri_Extensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Uri_Extensions.cs index c945d306e..ce2a6a729 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Uri_Extensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/FluentValidation/FluentValidation_Uri_Extensions.cs @@ -2,14 +2,14 @@ namespace Digdir.Domain.Dialogporten.Application.Common.Extensions.FluentValidation; -public static class FluentValidation_Uri_Extensions +public static class FluentValidationUriExtensions { public static IRuleBuilderOptions IsValidUri(this IRuleBuilder ruleBuilder) where TUri : Uri? { return ruleBuilder .Must(uri => uri is null || uri.IsWellFormedOriginalString()) - .WithMessage("'{PropertyName}' is not a well formated URI."); + .WithMessage("'{PropertyName}' is not a well formatted URI."); } public static IRuleBuilderOptions MaximumLength(this IRuleBuilder ruleBuilder, int maximumLength) diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ServiceCollectionExtensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ServiceCollectionExtensions.cs index 460ab9a81..c67cb1cc7 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ServiceCollectionExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Extensions/ServiceCollectionExtensions.cs @@ -1,7 +1,5 @@ using Microsoft.Extensions.DependencyInjection; -using FluentValidation; using Microsoft.Extensions.Hosting; -using System.Diagnostics.CodeAnalysis; namespace Digdir.Domain.Dialogporten.Application.Common.Extensions; @@ -57,9 +55,9 @@ private static IServiceCollection Replace( } public static IServiceCollection Decorate(this IServiceCollection services, bool predicate) - where TDecorator : TService => - predicate - ? services.Decorate() + where TDecorator : TService => + predicate + ? services.Decorate() : services; public static IServiceCollection AddHostedService(this IServiceCollection services, bool predicate) diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/IDomainContext.cs b/src/Digdir.Domain.Dialogporten.Application/Common/IDomainContext.cs index 3d9eeaada..ad761ffa8 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/IDomainContext.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/IDomainContext.cs @@ -20,7 +20,7 @@ internal class DomainContext : IDomainContext public IReadOnlyCollection Errors => _errors.ToList(); - public bool IsValid => !_errors.Any(); + public bool IsValid => _errors.Count == 0; public void AddError(string propertyName, string error) => AddError(new DomainFailure(propertyName, error)); @@ -51,4 +51,4 @@ public void EnsureValidState() throw new DomainException(Pop()); } } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/IUserService.cs b/src/Digdir.Domain.Dialogporten.Application/Common/IUserService.cs index 5ac855f9d..e75bbebae 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/IUserService.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/IUserService.cs @@ -30,15 +30,10 @@ public async Task CurrentUserIsOwner(string serviceResource, CancellationT return resourceIds.Contains(serviceResource); } - public Task> GetCurrentUserResourceIds(CancellationToken cancellationToken) - { - if (!_user.TryGetOrgNumber(out var orgNumber)) - { - throw new UnreachableException(); - } - - return _resourceRegistry.GetResourceIds(orgNumber, cancellationToken); - } + public Task> GetCurrentUserResourceIds(CancellationToken cancellationToken) => + !_user.TryGetOrgNumber(out var orgNumber) + ? throw new UnreachableException() + : _resourceRegistry.GetResourceIds(orgNumber, cancellationToken); } internal sealed class LocalDevelopmentUserServiceDecorator : IUserService @@ -50,9 +45,9 @@ public LocalDevelopmentUserServiceDecorator(IUserService userService) _userService = userService ?? throw new ArgumentNullException(nameof(userService)); } - public Task CurrentUserIsOwner(string serviceResource, CancellationToken cancellationToken) => + public Task CurrentUserIsOwner(string serviceResource, CancellationToken cancellationToken) => Task.FromResult(true); - public Task> GetCurrentUserResourceIds(CancellationToken cancellationToken) => + public Task> GetCurrentUserResourceIds(CancellationToken cancellationToken) => _userService.GetCurrentUserResourceIds(cancellationToken); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/Mod11.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/Mod11.cs index 9816e0aec..d3a8f4c78 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/Mod11.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/Mod11.cs @@ -18,11 +18,11 @@ public static bool TryCalculateControlDigit(ReadOnlySpan number, int[] wei } var sum = 0; - for (int i = 0; i < digits.Length; i++) + for (var i = 0; i < digits.Length; i++) { sum += digits[i] * weights[i]; } - controlDigit = Mod11Number - sum % Mod11Number; + controlDigit = Mod11Number - (sum % Mod11Number); return true; } @@ -31,11 +31,11 @@ private static int[] ExtractDigits(this ReadOnlySpan number) var result = new int[number.Length]; var index = 0; - for (int i = 0; i < number.Length; i++) + foreach (var character in number) { - if (char.IsDigit(number[i])) + if (char.IsDigit(character)) { - result[index++] = number[i] - '0'; + result[index++] = character - '0'; } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/OrganizationNumber.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/OrganizationNumber.cs index ba8d5bf19..e4ab83e2c 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/OrganizationNumber.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/OrganizationNumber.cs @@ -1,13 +1,15 @@ -namespace Digdir.Domain.Dialogporten.Application.Common.Numbers; +using System.Globalization; + +namespace Digdir.Domain.Dialogporten.Application.Common.Numbers; internal static class OrganizationNumber { - private static readonly int[] OrgNumberWeights = new[] { 3, 2, 7, 6, 5, 4, 3, 2 }; + private static readonly int[] OrgNumberWeights = { 3, 2, 7, 6, 5, 4, 3, 2 }; public static bool IsValid(ReadOnlySpan orgNumber) { return orgNumber.Length == 9 && Mod11.TryCalculateControlDigit(orgNumber[..8], OrgNumberWeights, out var control) - && control == int.Parse(orgNumber[8..9]); + && control == int.Parse(orgNumber[8..9], CultureInfo.InvariantCulture); } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/SocialSecurityNumber.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/SocialSecurityNumber.cs index bce2370a1..166d111dd 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/SocialSecurityNumber.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/SocialSecurityNumber.cs @@ -1,16 +1,18 @@ -namespace Digdir.Domain.Dialogporten.Application.Common.Numbers; +using System.Globalization; + +namespace Digdir.Domain.Dialogporten.Application.Common.Numbers; internal static class SocialSecurityNumber { - private static readonly int[] SocialSecurityNumberWeights1 = new[] { 3, 7, 6, 1, 8, 9, 4, 5, 2, 1 }; - private static readonly int[] SocialSecurityNumberWeights2 = new[] { 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 }; + private static readonly int[] SocialSecurityNumberWeights1 = { 3, 7, 6, 1, 8, 9, 4, 5, 2, 1 }; + private static readonly int[] SocialSecurityNumberWeights2 = { 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 }; public static bool IsValid(ReadOnlySpan socialSecurityNumber) { return socialSecurityNumber.Length == 11 && Mod11.TryCalculateControlDigit(socialSecurityNumber[..9], SocialSecurityNumberWeights1, out var control1) && Mod11.TryCalculateControlDigit(socialSecurityNumber[..10], SocialSecurityNumberWeights2, out var control2) - && control1 == int.Parse(socialSecurityNumber[9..10]) - && control2 == int.Parse(socialSecurityNumber[10..11]); + && control1 == int.Parse(socialSecurityNumber[9..10], CultureInfo.InvariantCulture) + && control2 == int.Parse(socialSecurityNumber[10..11], CultureInfo.InvariantCulture); } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/UuidV7.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/UuidV7.cs index 169c6063c..e8ba73f3b 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/UuidV7.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Numbers/UuidV7.cs @@ -12,9 +12,9 @@ public static bool IsValid(string uuid) return IsValid(guid); } - public static bool IsValid(Guid guid) + public static bool IsValid(Guid value) { - var bytes = guid.ToByteArray(); + var bytes = value.ToByteArray(); // Version is stored in the 7th byte, but the nibbles are reversed so version is actually in the higher 4 bits var version = bytes[7] >> 4; if (version != 7) // Ensure version is 7 @@ -29,4 +29,4 @@ public static bool IsValid(Guid guid) } return true; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continue/ContinuationToken.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continuation/ContinuationToken.cs similarity index 97% rename from src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continue/ContinuationToken.cs rename to src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continuation/ContinuationToken.cs index b646bc96d..346ec7b45 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continue/ContinuationToken.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continuation/ContinuationToken.cs @@ -1,7 +1,7 @@ using System.Linq.Expressions; using System.Reflection; -namespace Digdir.Domain.Dialogporten.Application.Common.Pagination.Continue; +namespace Digdir.Domain.Dialogporten.Application.Common.Pagination.Continuation; public class ContinuationToken { diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continue/ContinuationTokenSet.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continuation/ContinuationTokenSet.cs similarity index 99% rename from src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continue/ContinuationTokenSet.cs rename to src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continuation/ContinuationTokenSet.cs index f53468ddc..dfd91eac8 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continue/ContinuationTokenSet.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Continuation/ContinuationTokenSet.cs @@ -2,7 +2,7 @@ using Digdir.Domain.Dialogporten.Application.Common.Pagination.Extensions; using Digdir.Domain.Dialogporten.Application.Common.Pagination.OrderOption; -namespace Digdir.Domain.Dialogporten.Application.Common.Pagination.Continue; +namespace Digdir.Domain.Dialogporten.Application.Common.Pagination.Continuation; public interface IContinuationTokenSet { diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Extensions/OrderExtensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Extensions/OrderExtensions.cs index 65c9b9667..795135762 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Extensions/OrderExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Extensions/OrderExtensions.cs @@ -1,5 +1,5 @@ using Digdir.Domain.Dialogporten.Application.Common.Extensions; -using Digdir.Domain.Dialogporten.Application.Common.Pagination.Continue; +using Digdir.Domain.Dialogporten.Application.Common.Pagination.Continuation; using Digdir.Domain.Dialogporten.Application.Common.Pagination.Order; using Digdir.Domain.Dialogporten.Application.Common.Pagination.OrderOption; using System.Linq.Expressions; diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/IPaginationParameter.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/IPaginationParameter.cs index 922a99cef..686fe6c8a 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/IPaginationParameter.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/IPaginationParameter.cs @@ -1,11 +1,11 @@ -using Digdir.Domain.Dialogporten.Application.Common.Pagination.Continue; +using Digdir.Domain.Dialogporten.Application.Common.Pagination.Continuation; using Digdir.Domain.Dialogporten.Application.Common.Pagination.Order; using Digdir.Domain.Dialogporten.Application.Common.Pagination.OrderOption; using FluentValidation; namespace Digdir.Domain.Dialogporten.Application.Common.Pagination; -public class PaginationParameter +public class PaginationParameter where TOrderDefinition : IOrderDefinition { private readonly int _limit = PaginationConstants.DefaultLimit; @@ -30,7 +30,7 @@ internal sealed class PaginationParameterValidator : { public PaginationParameterValidator() { - RuleFor(x => x.Limit).InclusiveBetween(PaginationConstants.MinLimit,PaginationConstants.MaxLimit); + RuleFor(x => x.Limit).InclusiveBetween(PaginationConstants.MinLimit, PaginationConstants.MaxLimit); RuleFor(x => x.ContinuationToken) .Must((paginationParameter, continuationTokenSet, ctx) => { diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Order/OrderSet.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Order/OrderSet.cs index 65046a1c1..ae871dcc6 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Order/OrderSet.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/Order/OrderSet.cs @@ -54,10 +54,7 @@ public static bool TryParse(string? value, [NotNullWhen(true)] out OrderSet x.Key == PaginationConstants.OrderIdKey) ?? OrderOptions.Value.IdOrder; - if (orderList.Contains(idOrder)) - { - orderList.Remove(idOrder); - } + orderList.Remove(idOrder); orderList.Add(idOrder); @@ -87,7 +84,7 @@ public static bool TryParse(string? value, [NotNullWhen(true)] out OrderSet s, DateTimeOffset d => d.UtcDateTime.ToString("o"), DateTime d => d.ToString("o"), - object o => o.ToString(), + var o => o.ToString(), }; return $"{x.Key.ToLowerInvariant()}{PaginationConstants.ContinuationTokenDelimiter}{value}"; }); @@ -117,9 +114,6 @@ public bool Equals(Order? x, Order? y) return x.Key == y.Key; } - public int GetHashCode([DisallowNull] Order obj) - { - return obj.Key.GetHashCode(); - } + public int GetHashCode([DisallowNull] Order obj) => obj.Key.GetHashCode(); } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/PaginationExtensions.cs b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/PaginationExtensions.cs index c0b101909..1d0e98e76 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/PaginationExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Common/Pagination/PaginationExtensions.cs @@ -1,4 +1,4 @@ -using Digdir.Domain.Dialogporten.Application.Common.Pagination.Continue; +using Digdir.Domain.Dialogporten.Application.Common.Pagination.Continuation; using Digdir.Domain.Dialogporten.Application.Common.Pagination.Extensions; using Digdir.Domain.Dialogporten.Application.Common.Pagination.Order; using Digdir.Domain.Dialogporten.Application.Common.Pagination.OrderOption; @@ -39,10 +39,7 @@ private static async Task> CreateAsync( int limit, CancellationToken cancellationToken = default) { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); const int OneMore = 1; diff --git a/src/Digdir.Domain.Dialogporten.Application/Digdir.Domain.Dialogporten.Application.csproj b/src/Digdir.Domain.Dialogporten.Application/Digdir.Domain.Dialogporten.Application.csproj index 97f292985..5e2ecf0d4 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Digdir.Domain.Dialogporten.Application.csproj +++ b/src/Digdir.Domain.Dialogporten.Application/Digdir.Domain.Dialogporten.Application.csproj @@ -1,31 +1,31 @@  - - net7.0 - enable - enable - + + net7.0 + enable + enable + - - - - - - - - - - - - + + + + + + + + + + + + - - - - + + + + - - - + + + diff --git a/src/Digdir.Domain.Dialogporten.Application/Externals/IDialogDbContext.cs b/src/Digdir.Domain.Dialogporten.Application/Externals/IDialogDbContext.cs index 1cce11fac..6b0888abb 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Externals/IDialogDbContext.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Externals/IDialogDbContext.cs @@ -40,13 +40,13 @@ public interface IDialogDbContext /// True if the property is unmodified or the predicate returns true. /// bool MustWhenModified( - TEntity entity, - Expression> propertyExpression, - Func predicate) + TEntity entity, + Expression> propertyExpression, + Func predicate) where TEntity : class; Task> GetExistingIds( - IEnumerable entities, - CancellationToken cancellationToken) + IEnumerable entities, + CancellationToken cancellationToken) where TEntity : class, IIdentifiableEntity; bool TrySetOriginalETag(TEntity entity, Guid? etag) where TEntity : class, IVersionableEntity; } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/CloudEventTypes.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/CloudEventTypes.cs index 2795cb02d..adb782103 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/CloudEventTypes.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/CloudEventTypes.cs @@ -13,21 +13,21 @@ internal static class CloudEventTypes DialogUpdatedDomainEvent => "dialogporten.dialog.updated.v1", DialogDeletedDomainEvent => "dialogporten.dialog.deleted.v1", DialogReadDomainEvent => "dialogporten.dialog.read.v1", - + // DialogElement DialogElementDeletedDomainEvent => "dialogporten.dialog.element.deleted.v1", DialogElementCreatedDomainEvent => "dialogporten.dialog.element.created.v1", - DialogElementUpdatedDomainEvent => "dialogporten.dialog.element.updated.v1", - + DialogElementUpdatedDomainEvent => "dialogporten.dialog.element.updated.v1", + // Dialog activity - DialogActivityType.Enum.Submission => "dialogporten.dialog.activity.submission.v1", - DialogActivityType.Enum.Feedback => "dialogporten.dialog.activity.feedback.v1", - DialogActivityType.Enum.Information => "dialogporten.dialog.activity.information.v1", - DialogActivityType.Enum.Error => "dialogporten.dialog.activity.error.v1", - DialogActivityType.Enum.Closed => "dialogporten.dialog.activity.closed.v1", - DialogActivityType.Enum.Seen => "dialogporten.dialog.activity.seen.v1", - DialogActivityType.Enum.Forwarded => "dialogporten.dialog.activity.forwarded.v1", - + DialogActivityType.Values.Submission => "dialogporten.dialog.activity.submission.v1", + DialogActivityType.Values.Feedback => "dialogporten.dialog.activity.feedback.v1", + DialogActivityType.Values.Information => "dialogporten.dialog.activity.information.v1", + DialogActivityType.Values.Error => "dialogporten.dialog.activity.error.v1", + DialogActivityType.Values.Closed => "dialogporten.dialog.activity.closed.v1", + DialogActivityType.Values.Seen => "dialogporten.dialog.activity.seen.v1", + DialogActivityType.Values.Forwarded => "dialogporten.dialog.activity.forwarded.v1", + _ => throw new ArgumentOutOfRangeException(nameof(obj), obj, null) }; -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs index b6c93c128..e48d98761 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs @@ -10,7 +10,7 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events; internal sealed class DialogActivityEventToAltinnForwarder : DomainEventToAltinnForwarderBase, INotificationHandler { - public DialogActivityEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions settings) + public DialogActivityEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions settings) : base(cloudEventBus, db, settings) { } public async Task Handle(DialogActivityCreatedDomainEvent domainEvent, CancellationToken cancellationToken) @@ -20,12 +20,8 @@ public async Task Handle(DialogActivityCreatedDomainEvent domainEvent, Cancellat .Include(e => e.DialogElement) .Include(e => e.RelatedActivity) .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == domainEvent.DialogActivityId, cancellationToken); - - if (dialogActivity is null) - { - throw new ApplicationException($"DialogActivity with id {domainEvent.DialogActivityId} not found"); - } + .FirstOrDefaultAsync(x => x.Id == domainEvent.DialogActivityId, cancellationToken) + ?? throw new KeyNotFoundException($"DialogActivity with id {domainEvent.DialogActivityId} not found"); var cloudEvent = new CloudEvent { @@ -39,9 +35,9 @@ public async Task Handle(DialogActivityCreatedDomainEvent domainEvent, Cancellat Data = GetCloudEventData(dialogActivity) }; - await CloudEventBus.Publish(cloudEvent, cancellationToken); + await CloudEventBus.Publish(cloudEvent, cancellationToken); } - + private static Dictionary GetCloudEventData(DialogActivity dialogActivity) { var data = new Dictionary @@ -74,4 +70,4 @@ private static Dictionary GetCloudEventData(DialogActivity dialo return data; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs index 66ac99dc2..91d61a46c 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs @@ -40,17 +40,17 @@ public async Task Handle(DialogElementDeletedDomainEvent domainEvent, Cancellati { ["dialogElementId"] = domainEvent.DialogElementId.ToString() }; - + if (domainEvent.RelatedDialogElementId is not null) { data["relatedDialogElementId"] = domainEvent.RelatedDialogElementId.Value.ToString(); } - + if (domainEvent.Type is not null) { data["dialogElementType"] = domainEvent.Type.ToString(); } - + var cloudEvent = new CloudEvent { Id = domainEvent.EventId, @@ -104,13 +104,9 @@ private async Task GetDialogElement(Guid dialogElementId, Cancell .Include(e => e.Dialog) .Include(e => e.RelatedDialogElement) .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == dialogElementId, cancellationToken); - - if (dialogElement is null) - { - throw new ApplicationException($"DialogElement with id {dialogElementId} not found"); - } + .FirstOrDefaultAsync(x => x.Id == dialogElementId, cancellationToken) + ?? throw new KeyNotFoundException($"DialogElement with id {dialogElementId} not found"); return dialogElement; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs index d38e8da9f..180136642 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs @@ -53,9 +53,8 @@ public async Task Handle(DialogDeletedDomainEvent domainEvent, CancellationToken await CloudEventBus.Publish(cloudEvent, cancellationToken); } - - private CloudEvent CreateCloudEvent(IDomainEvent domainEvent, DialogEntity dialog, - Dictionary? data = null) => new() + + private CloudEvent CreateCloudEvent(IDomainEvent domainEvent, DialogEntity dialog, Dictionary? data = null) => new() { Id = domainEvent.EventId, Type = CloudEventTypes.Get(domainEvent), @@ -66,4 +65,4 @@ private CloudEvent CreateCloudEvent(IDomainEvent domainEvent, DialogEntity dialo Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{dialog.Id}", Data = data }; -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs index cd582553e..29cc0ea40 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs @@ -19,19 +19,15 @@ protected DomainEventToAltinnForwarderBase(ICloudEventBus cloudEventBus, IDialog } protected string DialogportenBaseUrl() => _dialogportenSettings.BaseUri.ToString(); - + protected async Task GetDialog(Guid dialogId, CancellationToken cancellationToken) { var dialog = await Db.Dialogs .IgnoreQueryFilters() .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == dialogId, cancellationToken); - - if (dialog is null) - { - throw new ApplicationException($"Dialog with id {dialogId} not found"); - } + .FirstOrDefaultAsync(x => x.Id == dialogId, cancellationToken) + ?? throw new KeyNotFoundException($"Dialog with id {dialogId} not found"); return dialog; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Localizations/LocalizationDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Localizations/LocalizationDto.cs index 5197f7514..de594fe7f 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Localizations/LocalizationDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Localizations/LocalizationDto.cs @@ -4,12 +4,12 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localization public sealed class LocalizationDto { - private string _cultureCode = null!; + private readonly string _cultureCode = null!; public required string Value { get; init; } - public required string CultureCode - { - get => _cultureCode; - init => _cultureCode = Localization.NormalizeCultureCode(value)!; + public required string CultureCode + { + get => _cultureCode; + init => _cultureCode = Localization.NormalizeCultureCode(value)!; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/GetDialogActivityDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/GetDialogActivityDto.cs index 3953ecd93..dd108bc07 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/GetDialogActivityDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/GetDialogActivityDto.cs @@ -9,7 +9,7 @@ public sealed class GetDialogActivityDto public DateTimeOffset? CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - public DialogActivityType.Enum Type { get; set; } + public DialogActivityType.Values Type { get; set; } public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/MappingProfile.cs index 800fb1ec5..0e30f1f35 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Get/MappingProfile.cs @@ -3,11 +3,11 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Get; -public class MappingProfile : Profile +public class MappingProfile : Profile { public MappingProfile() { CreateMap() .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/MappingProfile.cs similarity index 77% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/MappingProfile.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/MappingProfile.cs index 8243bc8c5..d5346c394 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/MappingProfile.cs @@ -1,13 +1,13 @@ using AutoMapper; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Search; internal sealed class MappingProfile : Profile { public MappingProfile() { - CreateMap() + CreateMap() .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId)); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/ListDialogActivityDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/SearchDialogActivityDto.cs similarity index 72% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/ListDialogActivityDto.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/SearchDialogActivityDto.cs index 00c804c00..adce19ec6 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/ListDialogActivityDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/SearchDialogActivityDto.cs @@ -1,15 +1,15 @@ using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Search; -public sealed class ListDialogActivityDto +public sealed class SearchDialogActivityDto { public Guid Id { get; set; } public DateTimeOffset CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - public DialogActivityType.Enum Type { get; set; } + public DialogActivityType.Values Type { get; set; } public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/ListDialogActivityQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/SearchDialogActivityQuery.cs similarity index 58% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/ListDialogActivityQuery.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/SearchDialogActivityQuery.cs index 9c8a89df0..e676edb19 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/List/ListDialogActivityQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogActivities/Queries/Search/SearchDialogActivityQuery.cs @@ -6,33 +6,33 @@ using Microsoft.EntityFrameworkCore; using OneOf; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Search; -public sealed class ListDialogActivityQuery : IRequest +public sealed class SearchDialogActivityQuery : IRequest { public Guid DialogId { get; set; } } [GenerateOneOf] -public partial class ListDialogActivityResult : OneOfBase, EntityNotFound, EntityDeleted> { } +public partial class SearchDialogActivityResult : OneOfBase, EntityNotFound, EntityDeleted> { } -internal sealed class ListDialogActivityQueryHandler : IRequestHandler +internal sealed class SearchDialogActivityQueryHandler : IRequestHandler { private readonly IDialogDbContext _db; private readonly IMapper _mapper; - public ListDialogActivityQueryHandler(IDialogDbContext db, IMapper mapper) + public SearchDialogActivityQueryHandler(IDialogDbContext db, IMapper mapper) { _db = db ?? throw new ArgumentNullException(nameof(db)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); } - public async Task Handle(ListDialogActivityQuery request, CancellationToken cancellationToken) + public async Task Handle(SearchDialogActivityQuery request, CancellationToken cancellationToken) { var dialog = await _db.Dialogs .Include(x => x.Activities) .IgnoreQueryFilters() - .FirstOrDefaultAsync(x => x.Id == request.DialogId, + .FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken: cancellationToken); if (dialog is null) @@ -44,7 +44,7 @@ public async Task Handle(ListDialogActivityQuery reque { return new EntityDeleted(request.DialogId); } - - return _mapper.Map>(dialog.Activities); + + return _mapper.Map>(dialog.Activities); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementDto.cs index 15c593437..f17b11f66 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementDto.cs @@ -21,5 +21,5 @@ public sealed class GetDialogElementUrlDto public Uri Url { get; set; } = null!; public string? MimeType { get; set; } - public DialogElementUrlConsumerType.Enum ConsumerType { get; set; } + public DialogElementUrlConsumerType.Values ConsumerType { get; set; } } \ No newline at end of file diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementQuery.cs index 89df972e2..8792017e9 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/GetDialogElementQuery.cs @@ -17,9 +17,7 @@ public sealed class GetDialogElementQuery : IRequest } [GenerateOneOf] -public partial class GetDialogElementResult : OneOfBase -{ -} +public partial class GetDialogElementResult : OneOfBase { } internal sealed class GetDialogElementQueryHandler : IRequestHandler { @@ -37,16 +35,16 @@ public async Task Handle(GetDialogElementQuery request, { Expression>> elementFilter = dialog => dialog.Elements.Where(x => x.Id == request.ElementId); - + var dialog = await _dbContext.Dialogs .Include(elementFilter) .ThenInclude(x => x.DisplayName!.Localizations) .Include(elementFilter) .ThenInclude(x => x.Urls) .IgnoreQueryFilters() - .FirstOrDefaultAsync(x => x.Id == request.DialogId, + .FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken: cancellationToken); - + if (dialog is null) { return new EntityNotFound(request.DialogId); @@ -56,15 +54,15 @@ public async Task Handle(GetDialogElementQuery request, { return new EntityDeleted(request.DialogId); } - + var element = dialog.Elements.FirstOrDefault(); if (element is null) { return new EntityNotFound(request.ElementId); } - + var dto = _mapper.Map(element); return dto; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/MappingProfile.cs index 57176fa68..fd343f029 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Get/MappingProfile.cs @@ -8,9 +8,9 @@ public class MappingProfile : Profile public MappingProfile() { CreateMap(); - + CreateMap() .ForMember(dest => dest.ConsumerType, opt => opt .MapFrom(src => src.ConsumerTypeId)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/MappingProfile.cs similarity index 71% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/MappingProfile.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/MappingProfile.cs index b112e6372..16119d379 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/MappingProfile.cs @@ -1,12 +1,12 @@ using AutoMapper; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.DialogElements; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.Search; public class MappingProfile : Profile { public MappingProfile() { - CreateMap(); + CreateMap(); } } \ No newline at end of file diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/ListDialogElementDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/SearchDialogElementDto.cs similarity index 88% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/ListDialogElementDto.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/SearchDialogElementDto.cs index b90b04937..d813dfb14 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/ListDialogElementDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/SearchDialogElementDto.cs @@ -1,13 +1,13 @@ using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.Search; -public class ListDialogElementDto +public class SearchDialogElementDto { public Guid Id { get; set; } public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset UpdatedAt { get; set; } - + public string? AuthorizationAttribute { get; set; } public Uri? Type { get; set; } @@ -17,4 +17,4 @@ public class ListDialogElementDto public List DisplayName { get; set; } = new(); public Guid? RelatedDialogElementId { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/ListDialogElementQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/SearchDialogElementQuery.cs similarity index 60% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/ListDialogElementQuery.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/SearchDialogElementQuery.cs index 4cd47e5a6..58e338f5c 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/List/ListDialogElementQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/DialogElements/Queries/Search/SearchDialogElementQuery.cs @@ -6,34 +6,34 @@ using Microsoft.EntityFrameworkCore; using OneOf; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.Search; -public sealed class ListDialogElementQuery : IRequest +public sealed class SearchDialogElementQuery : IRequest { public Guid DialogId { get; set; } } [GenerateOneOf] -public partial class ListDialogElementResult : OneOfBase, EntityNotFound, EntityDeleted> { } +public partial class SearchDialogElementResult : OneOfBase, EntityNotFound, EntityDeleted> { } -internal sealed class ListDialogElementQueryHandler : IRequestHandler +internal sealed class SearchDialogElementQueryHandler : IRequestHandler { private readonly IDialogDbContext _db; private readonly IMapper _mapper; - public ListDialogElementQueryHandler(IDialogDbContext db, IMapper mapper) + public SearchDialogElementQueryHandler(IDialogDbContext db, IMapper mapper) { _db = db ?? throw new ArgumentNullException(nameof(db)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); } - public async Task Handle(ListDialogElementQuery request, CancellationToken cancellationToken) + public async Task Handle(SearchDialogElementQuery request, CancellationToken cancellationToken) { var dialog = await _db.Dialogs .Include(x => x.Elements) .ThenInclude(x => x.DisplayName!.Localizations) .IgnoreQueryFilters() - .FirstOrDefaultAsync(x => x.Id == request.DialogId, + .FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken: cancellationToken); if (dialog is null) @@ -45,7 +45,7 @@ public async Task Handle(ListDialogElementQuery request { return new EntityDeleted(request.DialogId); } - - return _mapper.Map>(dialog.Elements); + + return _mapper.Map>(dialog.Elements); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogDto.cs index 96523df98..274b293a1 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogDto.cs @@ -21,7 +21,7 @@ public sealed class GetDialogDto public DateTimeOffset UpdatedAt { get; set; } public DateTimeOffset? ReadAt { get; set; } - public DialogStatus.Enum Status { get; set; } + public DialogStatus.Values Status { get; set; } public List? Body { get; set; } public List Title { get; set; } = new(); @@ -39,7 +39,7 @@ public sealed class GetDialogDialogActivityDto public DateTimeOffset? CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - public DialogActivityType.Enum Type { get; set; } + public DialogActivityType.Values Type { get; set; } public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } @@ -64,7 +64,7 @@ public sealed class GetDialogDialogApiActionEndpointDto public Guid Id { get; set; } public string? Version { get; set; } public Uri Url { get; set; } = null!; - public HttpVerb.Enum HttpMethod { get; set; } + public HttpVerb.Values HttpMethod { get; set; } public Uri? DocumentationUrl { get; set; } public Uri? RequestSchema { get; set; } public Uri? ResponseSchema { get; set; } @@ -81,7 +81,7 @@ public sealed class GetDialogDialogGuiActionDto public bool IsBackChannel { get; set; } public bool IsDeleteAction { get; set; } - public DialogGuiActionPriority.Enum Priority { get; set; } + public DialogGuiActionPriority.Values Priority { get; set; } public List Title { get; set; } = new(); } @@ -104,5 +104,5 @@ public sealed class GetDialogDialogElementUrlDto public Uri Url { get; set; } = null!; public string? MimeType { get; set; } - public DialogElementUrlConsumerType.Enum ConsumerType { get; set; } + public DialogElementUrlConsumerType.Values ConsumerType { get; set; } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs index 778d5ba6b..7676171b1 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/GetDialogQuery.cs @@ -73,17 +73,17 @@ public async Task Handle(GetDialogQuery request, CancellationTo } dialog.UpdateReadAt(_transactionTime.Value); - + var saveResult = await _unitOfWork .WithoutAuditableSideEffects() .SaveChangesAsync(cancellationToken); - + saveResult.Switch( success => { }, domainError => throw new UnreachableException("Should not get domain error when updating ReadAt."), concurrencyError => throw new UnreachableException("Should not get concurrencyError when updating ReadAt.")); - + var dto = _mapper.Map(dialog); return dto; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/MappingProfile.cs index ec81f8bea..454d3eefd 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Get/MappingProfile.cs @@ -12,20 +12,20 @@ public MappingProfile() { CreateMap() .ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId)); - + CreateMap() .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId)); - + CreateMap(); - + CreateMap() .ForMember(dest => dest.HttpMethod, opt => opt.MapFrom(src => src.HttpMethodId)); - + CreateMap() .ForMember(dest => dest.Priority, opt => opt.MapFrom(src => src.PriorityId)); - + CreateMap(); - + CreateMap() .ForMember(dest => dest.ConsumerType, opt => opt.MapFrom(src => src.ConsumerTypeId)); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/MappingProfile.cs similarity index 58% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/MappingProfile.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/MappingProfile.cs index 8f8be85b2..140998412 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/MappingProfile.cs @@ -1,13 +1,13 @@ using AutoMapper; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Search; internal sealed class MappingProfile : Profile { public MappingProfile() { - CreateMap() - .ForMember(dest => dest.Status,opt => opt.MapFrom(src => src.StatusId)); + CreateMap() + .ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogDto.cs similarity index 78% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogDto.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogDto.cs index 9defccfbd..97f70d089 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogDto.cs @@ -1,9 +1,9 @@ using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Search; -public sealed class ListDialogDto +public sealed class SearchDialogDto { public Guid Id { get; set; } public string Org { get; set; } = null!; @@ -14,8 +14,8 @@ public sealed class ListDialogDto public DateTimeOffset UpdatedAt { get; set; } public DateTimeOffset? DueAt { get; set; } - public DialogStatus.Enum Status { get; set; } + public DialogStatus.Values Status { get; set; } public List Title { get; set; } = new(); - public List? SenderName { get; set; } -} \ No newline at end of file + public List? SenderName { get; set; } +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogQuery.cs similarity index 72% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogQuery.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogQuery.cs index 43940bf89..d394102d9 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogQuery.cs @@ -1,4 +1,5 @@ -using AutoMapper; +using System.Globalization; +using AutoMapper; using AutoMapper.QueryableExtensions; using Digdir.Domain.Dialogporten.Application.Common; using Digdir.Domain.Dialogporten.Application.Common.Extensions; @@ -11,19 +12,18 @@ using Digdir.Domain.Dialogporten.Domain.Localizations; using MediatR; using OneOf; -using static Digdir.Domain.Dialogporten.Application.Common.Expressions; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Search; -public sealed class ListDialogQuery : SortablePaginationParameter, IRequest +public sealed class SearchDialogQuery : SortablePaginationParameter, IRequest { - private string? _searchCultureCode; + private readonly string? _searchCultureCode; public List? Org { get; init; } public List? ServiceResource { get; init; } public List? Party { get; init; } public List? ExtendedStatus { get; init; } - public List? Status { get; init; } + public List? Status { get; init; } public DateTimeOffset? CreatedAfter { get; init; } public DateTimeOffset? CreatedBefore { get; init; } @@ -35,16 +35,16 @@ public sealed class ListDialogQuery : SortablePaginationParameter _searchCultureCode; - init => _searchCultureCode = Localization.NormalizeCultureCode(value); + public string? SearchCultureCode + { + get => _searchCultureCode; + init => _searchCultureCode = Localization.NormalizeCultureCode(value); } } -public sealed class ListDialogQueryOrderDefinition : IOrderDefinition +public sealed class SearchDialogQueryOrderDefinition : IOrderDefinition { - public static IOrderOptions Configure(IOrderOptionsBuilder options) => + public static IOrderOptions Configure(IOrderOptionsBuilder options) => options.AddId(x => x.Id) .AddDefault("createdAt", x => x.CreatedAt) .AddOption("updatedAt", x => x.UpdatedAt) @@ -53,24 +53,24 @@ public static IOrderOptions Configure(IOrderOptionsBuilder, ValidationError> { } +public partial class SearchDialogResult : OneOfBase, ValidationError> { } -internal sealed class ListDialogQueryHandler : IRequestHandler +internal sealed class SearchDialogQueryHandler : IRequestHandler { private readonly IDialogDbContext _db; private readonly IMapper _mapper; private readonly IClock _clock; - public ListDialogQueryHandler(IDialogDbContext db, IMapper mapper, IClock clock) + public SearchDialogQueryHandler(IDialogDbContext db, IMapper mapper, IClock clock) { _db = db ?? throw new ArgumentNullException(nameof(db)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); _clock = clock ?? throw new ArgumentNullException(nameof(clock)); } - public async Task Handle(ListDialogQuery request, CancellationToken cancellationToken) + public async Task Handle(SearchDialogQuery request, CancellationToken cancellationToken) { - var searchExpression = LocalizedSearchExpression(request.Search, request.SearchCultureCode); + var searchExpression = Expressions.LocalizedSearchExpression(request.Search, request.SearchCultureCode); return await _db.Dialogs .WhereIf(!request.Org.IsNullOrEmpty(), x => request.Org!.Contains(x.Org)) @@ -86,12 +86,12 @@ public async Task Handle(ListDialogQuery request, Cancellation .WhereIf(request.DueBefore.HasValue, x => x.DueAt <= request.DueBefore) .WhereIf(request.Search is not null, x => x.Title!.Localizations.AsQueryable().Any(searchExpression) || - x.SearchTags.Any(x => x.Value == request.Search!.ToLower()) || + x.SearchTags.Any(x => x.Value.Equals(request.Search, StringComparison.OrdinalIgnoreCase)) || x.SenderName!.Localizations.AsQueryable().Any(searchExpression) ) .Where(x => !x.VisibleFrom.HasValue || _clock.UtcNowOffset > x.VisibleFrom) .Where(x => !x.ExpiresAt.HasValue || x.ExpiresAt > _clock.UtcNowOffset) - .ProjectTo(_mapper.ConfigurationProvider) + .ProjectTo(_mapper.ConfigurationProvider) .ToPaginatedListAsync(request, cancellationToken: cancellationToken); } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogQueryValidator.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogQueryValidator.cs similarity index 76% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogQueryValidator.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogQueryValidator.cs index 84c1fb11d..5abc51762 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/List/ListDialogQueryValidator.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/EndUser/Dialogs/Queries/Search/SearchDialogQueryValidator.cs @@ -3,13 +3,13 @@ using Digdir.Domain.Dialogporten.Domain.Localizations; using FluentValidation; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Search; -internal sealed class ListDialogQueryValidator : AbstractValidator +internal sealed class SearchDialogQueryValidator : AbstractValidator { - public ListDialogQueryValidator() + public SearchDialogQueryValidator() { - Include(new PaginationParameterValidator()); + Include(new PaginationParameterValidator()); RuleFor(x => x.Search) .MinimumLength(3) .When(x => x.Search is not null); @@ -20,7 +20,7 @@ public ListDialogQueryValidator() RuleFor(x => x) .Must(x => !x.ServiceResource.IsNullOrEmpty() || !x.Party.IsNullOrEmpty()) - .WithMessage($"Either {nameof(ListDialogQuery.ServiceResource)} or {nameof(ListDialogQuery.Party)} must be specified."); + .WithMessage($"Either {nameof(SearchDialogQuery.ServiceResource)} or {nameof(SearchDialogQuery.Party)} must be specified."); RuleFor(x => x.Org!.Count) .LessThanOrEqualTo(20) diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Outboxes/Commands/Delete/DeleteOutboxMessagesCommand.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Outboxes/Commands/Delete/DeleteOutboxMessagesCommand.cs index 2ea28dc57..3c9141e84 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Outboxes/Commands/Delete/DeleteOutboxMessagesCommand.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Outboxes/Commands/Delete/DeleteOutboxMessagesCommand.cs @@ -29,7 +29,7 @@ public DeleteOutboxMessagesCommandHandler(IUnitOfWork unitOfWork, IDialogDbConte public async Task Handle(DeleteOutboxMessagesCommand request, CancellationToken cancellationToken) { - var outboxMessage = await _db.OutboxMessages.FindAsync(request.EventId, cancellationToken); + var outboxMessage = await _db.OutboxMessages.FindAsync(new object?[] { request.EventId }, cancellationToken: cancellationToken); if (outboxMessage is null) { diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/GetDialogActivityDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/GetDialogActivityDto.cs index 9f7be863d..e30790a57 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/GetDialogActivityDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/GetDialogActivityDto.cs @@ -8,14 +8,14 @@ public sealed class GetDialogActivityDto public Guid Id { get; set; } public DateTimeOffset? CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - - public DialogActivityType.Enum Type { get; set; } - + + public DialogActivityType.Values Type { get; set; } + public DateTimeOffset? DeletedAt { get; set; } - + public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } public List? PerformedBy { get; set; } = new(); public List Description { get; set; } = new(); -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/MappingProfile.cs index b7e685387..affc6eac0 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Get/MappingProfile.cs @@ -3,7 +3,7 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.Get; -public class MappingProfile : Profile +public class MappingProfile : Profile { public MappingProfile() { @@ -11,4 +11,4 @@ public MappingProfile() .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId)) .ForMember(dest => dest.DeletedAt, opt => opt.MapFrom(src => src.Dialog.DeletedAt)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/MappingProfile.cs similarity index 79% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/MappingProfile.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/MappingProfile.cs index 7941102b7..969b4856c 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/MappingProfile.cs @@ -1,13 +1,13 @@ using AutoMapper; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.Search; public class MappingProfile : Profile { public MappingProfile() { - CreateMap() + CreateMap() .ForMember(dest => dest.Type, opt => opt.MapFrom(src => src.TypeId)) .ForMember(dest => dest.DeletedAt, opt => opt.MapFrom(src => src.Dialog.DeletedAt)); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/ListDialogActivityDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/SearchDialogActivityDto.cs similarity index 74% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/ListDialogActivityDto.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/SearchDialogActivityDto.cs index 5fb634f19..1c0d75ff3 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/ListDialogActivityDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/SearchDialogActivityDto.cs @@ -1,17 +1,17 @@ using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.Search; -public sealed class ListDialogActivityDto +public sealed class SearchDialogActivityDto { public Guid Id { get; set; } public DateTimeOffset CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - public DialogActivityType.Enum Type { get; set; } + public DialogActivityType.Values Type { get; set; } public DateTimeOffset? DeletedAt { get; set; } public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/ListDialogActivityQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/SearchDialogActivityQuery.cs similarity index 56% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/ListDialogActivityQuery.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/SearchDialogActivityQuery.cs index 61e065891..855cb6110 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/List/ListDialogActivityQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogActivities/Queries/Search/SearchDialogActivityQuery.cs @@ -6,33 +6,33 @@ using Microsoft.EntityFrameworkCore; using OneOf; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.Search; -public sealed class ListDialogActivityQuery : IRequest +public sealed class SearchDialogActivityQuery : IRequest { public Guid DialogId { get; set; } } [GenerateOneOf] -public partial class ListDialogActivityResult : OneOfBase, EntityNotFound> { } +public partial class SearchDialogActivityResult : OneOfBase, EntityNotFound> { } -internal sealed class ListDialogActivityQueryHandler : IRequestHandler +internal sealed class SearchDialogActivityQueryHandler : IRequestHandler { private readonly IDialogDbContext _db; private readonly IMapper _mapper; - public ListDialogActivityQueryHandler(IDialogDbContext db, IMapper mapper) + public SearchDialogActivityQueryHandler(IDialogDbContext db, IMapper mapper) { _db = db ?? throw new ArgumentNullException(nameof(db)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); } - public async Task Handle(ListDialogActivityQuery request, CancellationToken cancellationToken) + public async Task Handle(SearchDialogActivityQuery request, CancellationToken cancellationToken) { var dialog = await _db.Dialogs .Include(x => x.Activities) .IgnoreQueryFilters() - .FirstOrDefaultAsync(x => x.Id == request.DialogId, + .FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken: cancellationToken); if (dialog is null) @@ -40,6 +40,6 @@ public async Task Handle(ListDialogActivityQuery reque return new EntityNotFound(request.DialogId); } - return _mapper.Map>(dialog.Activities); + return _mapper.Map>(dialog.Activities); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementDto.cs index 0b05777b1..f03338136 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementDto.cs @@ -12,7 +12,7 @@ public sealed class GetDialogElementDto public Guid? RelatedDialogElementId { get; set; } public DateTimeOffset? DeletedAt { get; set; } - + public List DisplayName { get; set; } = new(); public List Urls { get; set; } = new(); } @@ -23,5 +23,5 @@ public sealed class GetDialogElementUrlDto public Uri Url { get; set; } = null!; public string? MimeType { get; set; } - public DialogElementUrlConsumerType.Enum ConsumerType { get; set; } -} \ No newline at end of file + public DialogElementUrlConsumerType.Values ConsumerType { get; set; } +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementQuery.cs index 115c90c0f..403ae5870 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Get/GetDialogElementQuery.cs @@ -17,9 +17,7 @@ public sealed class GetDialogElementQuery : IRequest } [GenerateOneOf] -public partial class GetDialogElementResult : OneOfBase -{ -} +public partial class GetDialogElementResult : OneOfBase { } internal sealed class GetDialogElementQueryHandler : IRequestHandler { @@ -37,16 +35,16 @@ public async Task Handle(GetDialogElementQuery request, { Expression>> elementFilter = dialog => dialog.Elements.Where(x => x.Id == request.ElementId); - + var dialog = await _dbContext.Dialogs .Include(elementFilter) .ThenInclude(x => x.DisplayName!.Localizations) .Include(elementFilter) .ThenInclude(x => x.Urls) .IgnoreQueryFilters() - .FirstOrDefaultAsync(x => x.Id == request.DialogId, + .FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken: cancellationToken); - + if (dialog is null) { return new EntityNotFound(request.DialogId); @@ -58,7 +56,7 @@ public async Task Handle(GetDialogElementQuery request, { return new EntityNotFound(request.ElementId); } - + return _mapper.Map(element); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/MappingProfile.cs similarity index 77% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/MappingProfile.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/MappingProfile.cs index ab1cec908..b02f454cc 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/MappingProfile.cs @@ -1,13 +1,13 @@ using AutoMapper; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.DialogElements; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.Search; public class MappingProfile : Profile { public MappingProfile() { - CreateMap() + CreateMap() .ForMember(dest => dest.DeletedAt, opt => opt.MapFrom(src => src.Dialog.DeletedAt)); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/ListDialogElementDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/SearchDialogElementDto.cs similarity index 88% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/ListDialogElementDto.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/SearchDialogElementDto.cs index 363dd1b2d..0ac2e70c4 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/ListDialogElementDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/SearchDialogElementDto.cs @@ -1,13 +1,13 @@ using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.Search; -public class ListDialogElementDto +public class SearchDialogElementDto { public Guid Id { get; set; } public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset UpdatedAt { get; set; } - + public string? AuthorizationAttribute { get; set; } public Uri? Type { get; set; } @@ -18,4 +18,4 @@ public class ListDialogElementDto public List DisplayName { get; set; } = new(); public Guid? RelatedDialogElementId { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/ListDialogElementQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/SearchDialogElementQuery.cs similarity index 58% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/ListDialogElementQuery.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/SearchDialogElementQuery.cs index 5feb103df..10ff05462 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/List/ListDialogElementQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/DialogElements/Queries/Search/SearchDialogElementQuery.cs @@ -6,34 +6,34 @@ using Microsoft.EntityFrameworkCore; using OneOf; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.Search; -public sealed class ListDialogElementQuery : IRequest +public sealed class SearchDialogElementQuery : IRequest { public Guid DialogId { get; set; } } [GenerateOneOf] -public partial class ListDialogElementResult : OneOfBase, EntityNotFound> { } +public partial class SearchDialogElementResult : OneOfBase, EntityNotFound> { } -internal sealed class ListDialogElementQueryHandler : IRequestHandler +internal sealed class SearchDialogElementQueryHandler : IRequestHandler { private readonly IDialogDbContext _db; private readonly IMapper _mapper; - public ListDialogElementQueryHandler(IDialogDbContext db, IMapper mapper) + public SearchDialogElementQueryHandler(IDialogDbContext db, IMapper mapper) { _db = db ?? throw new ArgumentNullException(nameof(db)); _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper)); } - public async Task Handle(ListDialogElementQuery request, CancellationToken cancellationToken) + public async Task Handle(SearchDialogElementQuery request, CancellationToken cancellationToken) { var dialog = await _db.Dialogs .Include(x => x.Elements) .ThenInclude(x => x.DisplayName!.Localizations) .IgnoreQueryFilters() - .FirstOrDefaultAsync(x => x.Id == request.DialogId, + .FirstOrDefaultAsync(x => x.Id == request.DialogId, cancellationToken: cancellationToken); if (dialog is null) @@ -41,6 +41,6 @@ public async Task Handle(ListDialogElementQuery request return new EntityNotFound(request.DialogId); } - return _mapper.Map>(dialog.Elements); + return _mapper.Map>(dialog.Elements); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs index f39116042..605063e8a 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs @@ -50,19 +50,19 @@ public async Task Handle(CreateDialogCommand request, Cancel var dialog = _mapper.Map(request); var existingDialogIds = await _db.GetExistingIds(new[] { dialog }, cancellationToken); - if (existingDialogIds.Any()) + if (existingDialogIds.Count != 0) { _domainContext.AddError(DomainFailure.EntityExists(existingDialogIds)); } var existingActivityIds = await _db.GetExistingIds(dialog.Activities, cancellationToken); - if (existingActivityIds.Any()) + if (existingActivityIds.Count != 0) { _domainContext.AddError(DomainFailure.EntityExists(existingActivityIds)); } var existingElementIds = await _db.GetExistingIds(dialog.Elements, cancellationToken); - if (existingElementIds.Any()) + if (existingElementIds.Count != 0) { _domainContext.AddError(DomainFailure.EntityExists(existingElementIds)); } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs index add3eecf2..f604e22cc 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs @@ -24,7 +24,7 @@ public CreateDialogCommandValidator( .NotNull() .IsValidUri() .MaximumLength(Constants.DefaultMaxUriLength) - .Must(x => x?.StartsWith(Constants.ServiceResourcePrefix) ?? false) + .Must(x => x?.StartsWith(Constants.ServiceResourcePrefix, StringComparison.InvariantCulture) ?? false) .WithMessage($"'{{PropertyName}}' must start with '{Constants.ServiceResourcePrefix}'."); RuleFor(x => x.Party) @@ -35,7 +35,7 @@ public CreateDialogCommandValidator( _ => false }).WithMessage( "'{PropertyName}' must be on format '/org/[orgNumber]' or " + - "'/person/[socialSecurityNumber]' with valid numbers respectivly.") + "'/person/[socialSecurityNumber]' with valid numbers respectively.") .NotEmpty() .MaximumLength(Constants.DefaultMaxStringLength); @@ -77,13 +77,13 @@ public CreateDialogCommandValidator( RuleFor(x => x.GuiActions) .Must(x => x - .Where(x => x.Priority == DialogGuiActionPriority.Enum.Primary) + .Where(x => x.Priority == DialogGuiActionPriority.Values.Primary) .Count() <= 1).WithMessage("Only one primary GUI action is allowed.") .Must(x => x - .Where(x => x.Priority == DialogGuiActionPriority.Enum.Secondary) + .Where(x => x.Priority == DialogGuiActionPriority.Values.Secondary) .Count() <= 1).WithMessage("Only one secondary GUI action is allowed.") .Must(x => x - .Where(x => x.Priority == DialogGuiActionPriority.Enum.Tertiary) + .Where(x => x.Priority == DialogGuiActionPriority.Values.Tertiary) .Count() <= 5).WithMessage("Only five tertiary GUI actions are allowed.") .ForEach(x => x.SetValidator(guiActionValidator)); diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs index ac2cf46d5..9755ba1f7 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs @@ -17,7 +17,7 @@ public class CreateDialogDto public DateTimeOffset? DueAt { get; set; } public DateTimeOffset? ExpiresAt { get; set; } - public DialogStatus.Enum Status { get; set; } + public DialogStatus.Values Status { get; set; } public List Body { get; set; } = new(); public List Title { get; set; } = new(); @@ -41,7 +41,7 @@ public sealed class CreateDialogDialogActivityDto public DateTimeOffset? CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - public DialogActivityType.Enum Type { get; set; } + public DialogActivityType.Values Type { get; set; } public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } @@ -64,7 +64,7 @@ public sealed class CreateDialogDialogApiActionEndpointDto { public string? Version { get; set; } public Uri Url { get; set; } = null!; - public HttpVerb.Enum HttpMethod { get; set; } + public HttpVerb.Values HttpMethod { get; set; } public Uri? DocumentationUrl { get; set; } public Uri? RequestSchema { get; set; } public Uri? ResponseSchema { get; set; } @@ -80,7 +80,7 @@ public sealed class CreateDialogDialogGuiActionDto public bool IsBackChannel { get; set; } public bool IsDeleteAction { get; set; } - public DialogGuiActionPriority.Enum Priority { get; set; } + public DialogGuiActionPriority.Values Priority { get; set; } public List Title { get; set; } = new(); } @@ -102,5 +102,5 @@ public sealed class CreateDialogDialogElementUrlDto public Uri Url { get; set; } = null!; public string? MimeType { get; set; } - public DialogElementUrlConsumerType.Enum ConsumerType { get; set; } + public DialogElementUrlConsumerType.Values ConsumerType { get; set; } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/MappingProfile.cs index 91d7aecaf..91f5ec29a 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/MappingProfile.cs @@ -13,27 +13,27 @@ public MappingProfile() CreateMap() .ForMember(dest => dest.Status, opt => opt.Ignore()) .ForMember(dest => dest.StatusId, opt => opt.MapFrom(src => src.Status)); - + CreateMap(); - + CreateMap(); - + CreateMap() .ForMember(dest => dest.ConsumerType, opt => opt.Ignore()) .ForMember(dest => dest.ConsumerTypeId, opt => opt.MapFrom(src => src.ConsumerType)); - + CreateMap() .ForMember(dest => dest.Priority, opt => opt.Ignore()) .ForMember(dest => dest.PriorityId, opt => opt.MapFrom(src => src.Priority)); - + CreateMap(); - + CreateMap() .ForMember(dest => dest.HttpMethod, opt => opt.Ignore()) .ForMember(dest => dest.HttpMethodId, opt => opt.MapFrom(src => src.HttpMethod)); - + CreateMap() .ForMember(dest => dest.Type, opt => opt.Ignore()) .ForMember(dest => dest.TypeId, opt => opt.MapFrom(src => src.Type)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommand.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommand.cs index 36336dba5..f12a7f85d 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommand.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommand.cs @@ -53,7 +53,7 @@ public UpdateDialogCommandHandler( public async Task Handle(UpdateDialogCommand request, CancellationToken cancellationToken) { var resourceIds = await _userService.GetCurrentUserResourceIds(cancellationToken); - + var dialog = await _db.Dialogs .Include(x => x.Body!.Localizations) .Include(x => x.Title!.Localizations) @@ -85,7 +85,7 @@ public async Task Handle(UpdateDialogCommand request, Cancel dialog.Body = _localizationService.Merge(dialog.Body, request.Dto.Body); dialog.Title = _localizationService.Merge(dialog.Title, request.Dto.Title); dialog.SenderName = _localizationService.Merge(dialog.SenderName, request.Dto.SenderName); - + dialog.SearchTags .Merge(request.Dto.SearchTags, destinationKeySelector: x => x.Value, @@ -93,7 +93,7 @@ public async Task Handle(UpdateDialogCommand request, Cancel create: _mapper.Map>, delete: DeleteDelegate.NoOp, comparer: StringComparer.InvariantCultureIgnoreCase); - + await dialog.Elements .MergeAsync(request.Dto.Elements, destinationKeySelector: x => x.Id, @@ -158,10 +158,10 @@ private async Task AppendActivity(DialogEntity dialog, UpdateDialogDto dto, Canc var newDialogActivities = _mapper.Map>(dto.Activities); var existingIds = await _db.GetExistingIds(newDialogActivities, cancellationToken); - if (existingIds.Any()) + if (existingIds.Count != 0) { _domainContext.AddError( - nameof(UpdateDialogDto.Activities), + nameof(UpdateDialogDto.Activities), $"Entity '{nameof(DialogActivity)}' with the following key(s) already exists: ({string.Join(", ", existingIds)})."); } @@ -228,7 +228,7 @@ private async Task> CreateElements(IEnumerable x.GuiActions) .Must(x => x - .Where(x => x.Priority == DialogGuiActionPriority.Enum.Primary) + .Where(x => x.Priority == DialogGuiActionPriority.Values.Primary) .Count() <= 1).WithMessage("Only one primary GUI action is allowed.") .Must(x => x - .Where(x => x.Priority == DialogGuiActionPriority.Enum.Secondary) + .Where(x => x.Priority == DialogGuiActionPriority.Values.Secondary) .Count() <= 1).WithMessage("Only one secondary GUI action is allowed.") .Must(x => x - .Where(x => x.Priority == DialogGuiActionPriority.Enum.Tertiary) + .Where(x => x.Priority == DialogGuiActionPriority.Values.Tertiary) .Count() <= 5).WithMessage("Only five tertiary GUI actions are allowed.") .UniqueBy(x => x.Id) .ForEach(x => x.SetValidator(guiActionValidator)); diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs index e6a28205e..3d3b1500d 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs @@ -14,7 +14,7 @@ public sealed class UpdateDialogDto public DateTimeOffset? DueAt { get; set; } public DateTimeOffset? ExpiresAt { get; set; } - public DialogStatus.Enum Status { get; set; } + public DialogStatus.Values Status { get; set; } public List Body { get; set; } = new(); public List Title { get; set; } = new(); @@ -38,7 +38,7 @@ public class UpdateDialogDialogActivityDto public DateTimeOffset? CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - public DialogActivityType.Enum Type { get; set; } + public DialogActivityType.Values Type { get; set; } public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } @@ -63,7 +63,7 @@ public sealed class UpdateDialogDialogApiActionEndpointDto public Guid? Id { get; set; } public string? Version { get; set; } public Uri Url { get; set; } = null!; - public HttpVerb.Enum HttpMethod { get; set; } + public HttpVerb.Values HttpMethod { get; set; } public Uri? DocumentationUrl { get; set; } public Uri? RequestSchema { get; set; } public Uri? ResponseSchema { get; set; } @@ -80,7 +80,7 @@ public sealed class UpdateDialogDialogGuiActionDto public bool IsBackChannel { get; set; } public bool IsDeleteAction { get; set; } - public DialogGuiActionPriority.Enum Priority { get; set; } + public DialogGuiActionPriority.Values Priority { get; set; } public List Title { get; set; } = new(); } @@ -103,5 +103,5 @@ public sealed class UpdateDialogDialogElementUrlDto public Uri Url { get; set; } = null!; public string? MimeType { get; set; } - public DialogElementUrlConsumerType.Enum ConsumerType { get; set; } + public DialogElementUrlConsumerType.Values ConsumerType { get; set; } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Get/GetDialogDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Get/GetDialogDto.cs index ff8f5eebc..a8edd5de3 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Get/GetDialogDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Get/GetDialogDto.cs @@ -23,11 +23,11 @@ public sealed class GetDialogDto public DateTimeOffset UpdatedAt { get; set; } public DateTimeOffset? ReadAt { get; set; } - public DialogStatus.Enum Status { get; set; } + public DialogStatus.Values Status { get; set; } - public List? Body { get; set; } + public List? Body { get; set; } public List Title { get; set; } = new(); - public List? SenderName { get; set; } + public List? SenderName { get; set; } public List? SearchTags { get; set; } public List Elements { get; set; } = new(); @@ -47,7 +47,7 @@ public sealed class GetDialogDialogActivityDto public DateTimeOffset? CreatedAt { get; set; } public Uri? ExtendedType { get; set; } - public DialogActivityType.Enum Type { get; set; } + public DialogActivityType.Values Type { get; set; } public Guid? RelatedActivityId { get; set; } public Guid? DialogElementId { get; set; } @@ -72,7 +72,7 @@ public sealed class GetDialogDialogApiActionEndpointDto public Guid Id { get; set; } public string? Version { get; set; } public Uri Url { get; set; } = null!; - public HttpVerb.Enum HttpMethod { get; set; } + public HttpVerb.Values HttpMethod { get; set; } public Uri? DocumentationUrl { get; set; } public Uri? RequestSchema { get; set; } public Uri? ResponseSchema { get; set; } @@ -89,7 +89,7 @@ public sealed class GetDialogDialogGuiActionDto public bool IsBackChannel { get; set; } public bool IsDeleteAction { get; set; } - public DialogGuiActionPriority.Enum Priority { get; set; } + public DialogGuiActionPriority.Values Priority { get; set; } public List Title { get; set; } = new(); } @@ -112,5 +112,5 @@ public sealed class GetDialogDialogElementUrlDto public Uri Url { get; set; } = null!; public string? MimeType { get; set; } - public DialogElementUrlConsumerType.Enum ConsumerType { get; set; } + public DialogElementUrlConsumerType.Values ConsumerType { get; set; } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/MappingProfile.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/MappingProfile.cs similarity index 68% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/MappingProfile.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/MappingProfile.cs index 0f8b82786..cf19d53ff 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/MappingProfile.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/MappingProfile.cs @@ -1,15 +1,15 @@ using AutoMapper; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search; internal sealed class MappingProfile : Profile { public MappingProfile() { - CreateMap() + CreateMap() .ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId)); - CreateMap(); + CreateMap(); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogDto.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogDto.cs similarity index 76% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogDto.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogDto.cs index c3f27f0b4..8a7ef16b4 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogDto.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogDto.cs @@ -1,9 +1,9 @@ using Digdir.Domain.Dialogporten.Application.Features.V1.Common.Localizations; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search; -public sealed class ListDialogDto +public sealed class SearchDialogDto { public Guid Id { get; set; } public string Org { get; set; } = null!; @@ -15,14 +15,14 @@ public sealed class ListDialogDto public DateTimeOffset? DueAt { get; set; } public DateTimeOffset? VisibleFrom { get; set; } - public DialogStatus.Enum Status { get; set; } - + public DialogStatus.Values Status { get; set; } + public List Title { get; set; } = new(); public List? SenderName { get; set; } - public List SearchTags { get; set; } = new(); + public List SearchTags { get; set; } = new(); } -public sealed class ListDialogSearchTagDto +public sealed class SearchDialogSearchTagDto { public string Value { get; set; } = null!; } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogQuery.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogQuery.cs similarity index 76% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogQuery.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogQuery.cs index d67b65df0..7041c7213 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogQuery.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogQuery.cs @@ -1,5 +1,7 @@ -using AutoMapper; +using System.Globalization; +using AutoMapper; using AutoMapper.QueryableExtensions; +using Digdir.Domain.Dialogporten.Application.Common; using Digdir.Domain.Dialogporten.Application.Common.Extensions; using Digdir.Domain.Dialogporten.Application.Common.Extensions.Enumerable; using Digdir.Domain.Dialogporten.Application.Common.Pagination; @@ -10,19 +12,17 @@ using Digdir.Domain.Dialogporten.Domain.Localizations; using MediatR; using OneOf; -using static Digdir.Domain.Dialogporten.Application.Common.Expressions; -using Digdir.Domain.Dialogporten.Application.Common; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search; -public sealed class ListDialogQuery : SortablePaginationParameter, IRequest +public sealed class SearchDialogQuery : SortablePaginationParameter, IRequest { private string? _searchCultureCode; public List? ServiceResource { get; init; } public List? Party { get; init; } public List? ExtendedStatus { get; init; } - public List? Status { get; init; } + public List? Status { get; init; } public DateTimeOffset? CreatedAfter { get; init; } public DateTimeOffset? CreatedBefore { get; init; } @@ -35,17 +35,17 @@ public sealed class ListDialogQuery : SortablePaginationParameter _searchCultureCode; - init => _searchCultureCode = Localization.NormalizeCultureCode(value); + public string? SearchCultureCode + { + get => _searchCultureCode; + init => _searchCultureCode = Localization.NormalizeCultureCode(value); } } -public sealed class ListDialogQueryOrderDefinition : IOrderDefinition +public sealed class SearchDialogQueryOrderDefinition : IOrderDefinition { - public static IOrderOptions Configure(IOrderOptionsBuilder options) => + public static IOrderOptions Configure(IOrderOptionsBuilder options) => options.AddId(x => x.Id) .AddDefault("createdAt", x => x.CreatedAt) .AddOption("updatedAt", x => x.UpdatedAt) @@ -54,15 +54,15 @@ public static IOrderOptions Configure(IOrderOptionsBuilder, ValidationError> { } +public partial class SearchDialogResult : OneOfBase, ValidationError> { } -internal sealed class ListDialogQueryHandler : IRequestHandler +internal sealed class SearchDialogQueryHandler : IRequestHandler { private readonly IDialogDbContext _db; private readonly IMapper _mapper; private readonly IUserService _userService; - public ListDialogQueryHandler( + public SearchDialogQueryHandler( IDialogDbContext db, IMapper mapper, IUserService userService) @@ -72,10 +72,10 @@ public ListDialogQueryHandler( _userService = userService ?? throw new ArgumentNullException(nameof(userService)); } - public async Task Handle(ListDialogQuery request, CancellationToken cancellationToken) + public async Task Handle(SearchDialogQuery request, CancellationToken cancellationToken) { var resourceIds = await _userService.GetCurrentUserResourceIds(cancellationToken); - var searchExpression = LocalizedSearchExpression(request.Search, request.SearchCultureCode); + var searchExpression = Expressions.LocalizedSearchExpression(request.Search, request.SearchCultureCode); return await _db.Dialogs .WhereIf(!request.ServiceResource.IsNullOrEmpty(), x => request.ServiceResource!.Contains(x.ServiceResource)) .WhereIf(!request.Party.IsNullOrEmpty(), x => request.Party!.Contains(x.Party)) @@ -92,11 +92,11 @@ public async Task Handle(ListDialogQuery request, Cancellation .WhereIf(request.Search is not null, x => x.Title!.Localizations.AsQueryable().Any(searchExpression) || x.Body!.Localizations.AsQueryable().Any(searchExpression) || - x.SearchTags.Any(x => x.Value == request.Search!.ToLower()) || + x.SearchTags.Any(x => x.Value.Equals(request.Search, StringComparison.OrdinalIgnoreCase)) || x.SenderName!.Localizations.AsQueryable().Any(searchExpression) ) .Where(x => resourceIds.Contains(x.ServiceResource)) - .ProjectTo(_mapper.ConfigurationProvider) + .ProjectTo(_mapper.ConfigurationProvider) .ToPaginatedListAsync(request, cancellationToken: cancellationToken); } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogQueryValidator.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogQueryValidator.cs similarity index 77% rename from src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogQueryValidator.cs rename to src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogQueryValidator.cs index 77411a301..287e0b4fb 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/List/ListDialogQueryValidator.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Queries/Search/SearchDialogQueryValidator.cs @@ -2,13 +2,13 @@ using Digdir.Domain.Dialogporten.Domain.Localizations; using FluentValidation; -namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.List; +namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search; -internal sealed class ListDialogQueryValidator : AbstractValidator +internal sealed class SearchDialogQueryValidator : AbstractValidator { - public ListDialogQueryValidator() + public SearchDialogQueryValidator() { - Include(new PaginationParameterValidator()); + Include(new PaginationParameterValidator()); RuleFor(x => x.Search) .MinimumLength(3) .When(x => x.Search is not null); @@ -16,19 +16,19 @@ public ListDialogQueryValidator() RuleFor(x => x.SearchCultureCode) .Must(x => x is null || Localization.IsValidCultureCode(x)) .WithMessage("'{PropertyName}' must be a valid culture code."); - + RuleFor(x => x.ServiceResource!.Count) .LessThanOrEqualTo(20) .When(x => x.ServiceResource is not null); - + RuleFor(x => x.Party!.Count) .LessThanOrEqualTo(20) .When(x => x.Party is not null); - + RuleFor(x => x.ExtendedStatus!.Count) .LessThanOrEqualTo(20) .When(x => x.ExtendedStatus is not null); RuleForEach(x => x.Status).IsInEnum(); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/ICdcSubscription.cs b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/ICdcSubscription.cs index b38109b21..75e65530a 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/ICdcSubscription.cs +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/ICdcSubscription.cs @@ -20,8 +20,8 @@ public record PostgresCdcSSubscriptionOptions( IReplicationDataMapper DataMapper ) { - internal string ReplicationSlotName { get; init; } = ReplicationSlotName.ToLower(); - internal string PublicationName { get; init; } = PublicationName.ToLower(); + internal string ReplicationSlotName { get; init; } = ReplicationSlotName.ToLowerInvariant(); + internal string PublicationName { get; init; } = PublicationName.ToLowerInvariant(); } internal sealed class PostgresCdcSubscription : ICdcSubscription diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/IReplicationDataMapper.cs b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/IReplicationDataMapper.cs index 00d257d3e..78c6b4b81 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/IReplicationDataMapper.cs +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/IReplicationDataMapper.cs @@ -1,4 +1,5 @@ -using Digdir.Domain.Dialogporten.Domain.Outboxes; +using System.Collections.ObjectModel; +using Digdir.Domain.Dialogporten.Domain.Outboxes; using Npgsql; using Npgsql.Replication.PgOutput.Messages; @@ -38,15 +39,15 @@ private static async Task> ToDictionary(InsertMessag return result; } - private static IDictionary ToDictionary(NpgsqlDataReader reader) + private static ReadOnlyDictionary ToDictionary(NpgsqlDataReader reader) { var result = new Dictionary(); - for (int i = 0; i < reader.FieldCount; i++) + for (var i = 0; i < reader.FieldCount; i++) { var columnName = reader.GetName(i); result[columnName] = reader.GetValue(i).ToString()!; } - return result; + return result.AsReadOnly(); } private static OutboxMessage ToOutboxMessage(IDictionary dic) @@ -58,4 +59,4 @@ private static OutboxMessage ToOutboxMessage(IDictionary dic) EventPayload = dic[nameof(OutboxMessage.EventPayload)], }; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/NpgsqlDataSourceExtensions.cs b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/NpgsqlDataSourceExtensions.cs index 1498acd94..d00a97c9d 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/NpgsqlDataSourceExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ChangeDataCapture/NpgsqlDataSourceExtensions.cs @@ -28,7 +28,7 @@ public static async Task Exists( command.Parameters.AddWithValue(parameter); } - return await command.ExecuteScalarAsync(ct) as bool? == true; + return (await command.ExecuteScalarAsync(ct) as bool?) == true; } public static async IAsyncEnumerable ReadExistingRowsFromSnapshot( diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj index 740ba241e..a9c1b25b0 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Digdir.Domain.Dialogporten.ChangeDataCapture.csproj @@ -1,27 +1,27 @@ - - Exe - net7.0 - enable - enable - 750256a4-f332-4783-8802-8a7d9566f9ca - Linux - + + Exe + net7.0 + enable + enable + 750256a4-f332-4783-8802-8a7d9566f9ca + Linux + - - - - - - - - - - + + + + + + + + + + - - - + + + diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs index e8a34e563..18272eb25 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/ICdcSink.cs @@ -23,7 +23,15 @@ public async Task Send(OutboxMessage outboxMessage, CancellationToken cancellati var endpoint = await _sender.GetSendEndpoint(new Uri("exchange:Digdir.Domain.Dialogporten.Service")); await endpoint.Send( outboxMessage, - context => (context as RabbitMqSendContext).Mandatory = true, + context => + { + if (context is not RabbitMqSendContext rabbitMqSendContext) + { + throw new ArgumentException("The context is not a RabbitMQ send context.", nameof(context)); + } + + rabbitMqSendContext.Mandatory = true; + }, cancellationToken); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs index 268fdc122..43d78fae3 100644 --- a/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs +++ b/src/Digdir.Domain.Dialogporten.ChangeDataCapture/Program.cs @@ -1,4 +1,5 @@ -using Digdir.Domain.Dialogporten.ChangeDataCapture; +using System.Globalization; +using Digdir.Domain.Dialogporten.ChangeDataCapture; using Digdir.Domain.Dialogporten.ChangeDataCapture.ChangeDataCapture; using Digdir.Domain.Dialogporten.ChangeDataCapture.Common; using Digdir.Domain.Dialogporten.Domain.Outboxes; @@ -14,7 +15,7 @@ Log.Logger = new LoggerConfiguration() .MinimumLevel.Warning() .Enrich.FromLogContext() - .WriteTo.Console() + .WriteTo.Console(formatProvider: CultureInfo.InvariantCulture) .WriteTo.ApplicationInsights( TelemetryConfiguration.CreateDefault(), TelemetryConverter.Traces) @@ -43,8 +44,8 @@ static void BuildAndRun(string[] args) .ReadFrom.Services(services) .Enrich.FromLogContext() .WriteTo.Conditional( - condition: x => builder.Environment.IsDevelopment(), - configureSink: x => x.Console()) + condition: x => builder.Environment.IsDevelopment(), + configureSink: x => x.Console(formatProvider: CultureInfo.InvariantCulture)) .WriteTo.ApplicationInsights( services.GetRequiredService(), TelemetryConverter.Traces)); diff --git a/src/Digdir.Domain.Dialogporten.Domain/Common/Constants.cs b/src/Digdir.Domain.Dialogporten.Domain/Common/Constants.cs index f4e70887d..aba8b99b1 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Common/Constants.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Common/Constants.cs @@ -7,4 +7,4 @@ public static class Constants public const int DefaultMaxUriLength = 1023; public const string ServiceResourcePrefix = "urn:altinn:resource:"; -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Domain/Common/DomainFailure.cs b/src/Digdir.Domain.Dialogporten.Domain/Common/DomainFailure.cs index 9e0c4ffac..c8d5a6056 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Common/DomainFailure.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Common/DomainFailure.cs @@ -1,6 +1,6 @@ namespace Digdir.Domain.Dialogporten.Domain.Common; -public class DomainFailure +public class DomainFailure { public string PropertyName { get; init; } public string ErrorMessage { get; init; } diff --git a/src/Digdir.Domain.Dialogporten.Domain/Common/Exceptions/DomainException.cs b/src/Digdir.Domain.Dialogporten.Domain/Common/Exceptions/DomainException.cs index 7bb4d4abf..e0c6cfa46 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Common/Exceptions/DomainException.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Common/Exceptions/DomainException.cs @@ -4,7 +4,7 @@ public class DomainException : ApplicationException { private readonly IEnumerable _errors; - public IReadOnlyCollection Errors => _errors.ToList().AsReadOnly(); + public IReadOnlyCollection Errors => _errors.ToList().AsReadOnly(); public DomainException(string message) : this(message, Enumerable.Empty()) { diff --git a/src/Digdir.Domain.Dialogporten.Domain/Common/Extensions/AggregateNodeExtensions.cs b/src/Digdir.Domain.Dialogporten.Domain/Common/Extensions/AggregateNodeExtensions.cs index 6284ff215..42ebe97bf 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Common/Extensions/AggregateNodeExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Common/Extensions/AggregateNodeExtensions.cs @@ -1,4 +1,5 @@ -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; +using System.Collections.ObjectModel; +using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actions; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.DialogElements; @@ -13,7 +14,7 @@ public static class AggregateNodeExtensions public static IReadOnlyCollection ToPaths(this IEnumerable aggregateNodes) => ToPaths(aggregateNodes, string.Empty); - private static IReadOnlyCollection ToPaths(this IEnumerable aggregateNodes, string parentPath) + private static ReadOnlyCollection ToPaths(this IEnumerable aggregateNodes, string parentPath) { var paths = new List(); @@ -42,7 +43,7 @@ private static IReadOnlyCollection ToPaths(this IEnumerable ToLocalizationPathStrings(this LocalizationSet localizationSet, string parentPath) => @@ -74,4 +75,4 @@ private static IEnumerable ToLocalizationPathStrings(this LocalizationSe string name when name.EndsWith("Id", StringComparison.InvariantCultureIgnoreCase) => name[..^2], _ => propertyName }; -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogApiActionEndpoint.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogApiActionEndpoint.cs index edec0e95a..d414d550e 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogApiActionEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogApiActionEndpoint.cs @@ -12,13 +12,13 @@ public class DialogApiActionEndpoint : IEntity public string? Version { get; set; } public Uri Url { get; set; } = null!; public Uri? DocumentationUrl { get; set; } - public Uri? RequestSchema { get; set;} - public Uri? ResponseSchema { get; set;} + public Uri? RequestSchema { get; set; } + public Uri? ResponseSchema { get; set; } public bool Deprecated { get; set; } public DateTimeOffset? SunsetAt { get; set; } // === Dependent relationships === - public HttpVerb.Enum HttpMethodId { get; set; } + public HttpVerb.Values HttpMethodId { get; set; } public HttpVerb HttpMethod { get; set; } = null!; public Guid ActionId { get; set; } diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiAction.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiAction.cs index 121bc4ddd..47310f4aa 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiAction.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiAction.cs @@ -17,7 +17,7 @@ public class DialogGuiAction : IEntity public bool IsDeleteAction { get; set; } // === Dependent relationships === - public DialogGuiActionPriority.Enum PriorityId { get; set; } + public DialogGuiActionPriority.Values PriorityId { get; set; } public DialogGuiActionPriority Priority { get; set; } = null!; public Guid DialogId { get; set; } diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiActionPriority.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiActionPriority.cs index 54ae3259c..0e2893c7d 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiActionPriority.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Actions/DialogGuiActionPriority.cs @@ -2,12 +2,12 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Actions; -public class DialogGuiActionPriority : AbstractLookupEntity +public class DialogGuiActionPriority : AbstractLookupEntity { - public DialogGuiActionPriority(Enum id) : base(id) { } - public override DialogGuiActionPriority MapValue(Enum id) => new(id); + public DialogGuiActionPriority(Values id) : base(id) { } + public override DialogGuiActionPriority MapValue(Values id) => new(id); - public enum Enum + public enum Values { Primary = 1, Secondary = 2, diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs index 3d106b088..b2191d097 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs @@ -15,7 +15,7 @@ public class DialogActivity : IImmutableEntity, IAggregateCreatedHandler, IEvent public Uri? ExtendedType { get; set; } // === Dependent relationships === - public DialogActivityType.Enum TypeId { get; set; } + public DialogActivityType.Values TypeId { get; set; } public DialogActivityType Type { get; set; } = null!; public Guid DialogId { get; set; } @@ -35,10 +35,10 @@ public class DialogActivity : IImmutableEntity, IAggregateCreatedHandler, IEvent public DialogActivityPerformedBy? PerformedBy { get; set; } public List RelatedActivities { get; set; } = new(); - + public void OnCreate(AggregateNode self, DateTimeOffset utcNow) { - _domainEvents.Add(new DialogActivityCreatedDomainEvent(DialogId, Id)); + _domainEvents.Add(new DialogActivityCreatedDomainEvent(DialogId, Id)); } private readonly List _domainEvents = new(); @@ -55,4 +55,4 @@ public class DialogActivityPerformedBy : LocalizationSet { public DialogActivity Activity { get; set; } = null!; public Guid ActivityId { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivityType.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivityType.cs index bafa74fed..62a2a4c35 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivityType.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivityType.cs @@ -2,12 +2,12 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; -public class DialogActivityType : AbstractLookupEntity +public class DialogActivityType : AbstractLookupEntity { - public DialogActivityType(Enum id) : base(id) { } - public override DialogActivityType MapValue(Enum id) => new(id); + public DialogActivityType(Values id) : base(id) { } + public override DialogActivityType MapValue(Values id) => new(id); - public enum Enum + public enum Values { /// /// Refererer en innsending utført av party som er mottatt hos tjenestetilbyder. diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElement.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElement.cs index 40d484e85..552e48a31 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElement.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElement.cs @@ -13,7 +13,7 @@ public class DialogElement : IEntity, IAggregateChangedHandler, IEventPublisher public Guid Id { get; set; } public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset UpdatedAt { get; set; } - + public string? AuthorizationAttribute { get; set; } public Uri? Type { get; set; } @@ -33,7 +33,7 @@ public class DialogElement : IEntity, IAggregateChangedHandler, IEventPublisher public List ApiActions { get; set; } = new(); public List Activities { get; set; } = new(); public List RelatedDialogElements { get; set; } = new(); - + public void OnCreate(AggregateNode self, DateTimeOffset utcNow) { _domainEvents.Add(new DialogElementCreatedDomainEvent(DialogId, Id)); @@ -62,4 +62,4 @@ public class DialogElementDisplayName : LocalizationSet { public Guid ElementId { get; set; } public DialogElement Element { get; set; } = null!; -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrl.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrl.cs index aa4877ac3..dc717fb83 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrl.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrl.cs @@ -12,7 +12,7 @@ public class DialogElementUrl : IEntity public string? MimeType { get; set; } // === Dependent relationships === - public DialogElementUrlConsumerType.Enum ConsumerTypeId { get; set; } + public DialogElementUrlConsumerType.Values ConsumerTypeId { get; set; } public DialogElementUrlConsumerType ConsumerType { get; set; } = null!; public Guid DialogElementId { get; set; } diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrlConsumerType.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrlConsumerType.cs index 2cf7ad260..fba6d55b9 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrlConsumerType.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogElements/DialogElementUrlConsumerType.cs @@ -2,12 +2,12 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.DialogElements; -public class DialogElementUrlConsumerType : AbstractLookupEntity +public class DialogElementUrlConsumerType : AbstractLookupEntity { - public DialogElementUrlConsumerType(Enum id) : base(id) { } - public override DialogElementUrlConsumerType MapValue(Enum id) => new(id); + public DialogElementUrlConsumerType(Values id) : base(id) { } + public override DialogElementUrlConsumerType MapValue(Values id) => new(id); - public enum Enum + public enum Values { Gui = 1, Api = 2, diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs index df00142d7..d40224ec8 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs @@ -11,11 +11,11 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -public class DialogEntity : - IEntity, - ISoftDeletableEntity, - IVersionableEntity, - IAggregateChangedHandler, +public class DialogEntity : + IEntity, + ISoftDeletableEntity, + IVersionableEntity, + IAggregateChangedHandler, IEventPublisher { public Guid Id { get; set; } @@ -36,7 +36,7 @@ public class DialogEntity : public DateTimeOffset? ReadAt { get; set; } // === Dependent relationships === - public DialogStatus.Enum StatusId { get; set; } + public DialogStatus.Values StatusId { get; set; } public DialogStatus Status { get; set; } = null!; @@ -45,14 +45,14 @@ public class DialogEntity : public DialogBody? Body { get; set; } [AggregateChild] - public DialogTitle? Title { get; set; } + public DialogTitle? Title { get; set; } [AggregateChild] public DialogSenderName? SenderName { get; set; } [AggregateChild] public List SearchTags { get; set; } = new(); - + [AggregateChild] public List Elements { get; set; } = new(); @@ -96,14 +96,14 @@ public void OnDelete(AggregateNode self, DateTimeOffset utcNow) { _domainEvents.Add(new DialogDeletedDomainEvent(Id, ServiceResource, Party)); } - + public void UpdateReadAt(DateTimeOffset timestamp) { if ((ReadAt ?? DateTimeOffset.MinValue) >= UpdatedAt) { return; } - + ReadAt = timestamp; _domainEvents.Add(new DialogReadDomainEvent(Id)); } diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogSearchTag.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogSearchTag.cs index b05186364..45afd8c1b 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogSearchTag.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogSearchTag.cs @@ -10,11 +10,11 @@ public class DialogSearchTag : IImmutableEntity public string Value { get => _value; - set => _value = value.Trim().ToLower(); + set => _value = value.Trim().ToLowerInvariant(); } public DateTimeOffset CreatedAt { get; set; } - + public Guid DialogId { get; set; } public DialogEntity Dialog { get; set; } = null!; -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogStatus.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogStatus.cs index 2988fb51e..5c8808da6 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogStatus.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogStatus.cs @@ -2,12 +2,12 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -public class DialogStatus : AbstractLookupEntity +public class DialogStatus : AbstractLookupEntity { - public DialogStatus(Enum id) : base(id) { } - public override DialogStatus MapValue(Enum id) => new(id); + public DialogStatus(Values id) : base(id) { } + public override DialogStatus MapValue(Values id) => new(id); - public enum Enum + public enum Values { /// /// Dialogen har ingen spesiell status. Brukes typisk for enkle meldinger som ikke krever noe diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogDeletedDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogDeletedDomainEvent.cs index 99e65a1e0..da891fb40 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogDeletedDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogDeletedDomainEvent.cs @@ -3,7 +3,7 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events; public sealed record DialogDeletedDomainEvent( - Guid DialogId, - string ServiceResource, - string Party) : + Guid DialogId, + string ServiceResource, + string Party) : DomainEvent; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Digdir.Domain.Dialogporten.Domain.csproj b/src/Digdir.Domain.Dialogporten.Domain/Digdir.Domain.Dialogporten.Domain.csproj index 90b508f0a..71f4a17fc 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Digdir.Domain.Dialogporten.Domain.csproj +++ b/src/Digdir.Domain.Dialogporten.Domain/Digdir.Domain.Dialogporten.Domain.csproj @@ -1,15 +1,13 @@  - - - net7.0 - enable - enable - - - - - - - - - \ No newline at end of file + + + net7.0 + enable + enable + + + + + + + diff --git a/src/Digdir.Domain.Dialogporten.Domain/Http/HttpVerb.cs b/src/Digdir.Domain.Dialogporten.Domain/Http/HttpVerb.cs index fca93f51c..41e40e6ee 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Http/HttpVerb.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Http/HttpVerb.cs @@ -1,13 +1,14 @@ using Digdir.Library.Entity.Abstractions.Features.Lookup; +// ReSharper disable InconsistentNaming namespace Digdir.Domain.Dialogporten.Domain.Http; -public class HttpVerb : AbstractLookupEntity +public class HttpVerb : AbstractLookupEntity { - public HttpVerb(Enum id) : base(id) { } - public override HttpVerb MapValue(Enum id) => new(id); + public HttpVerb(Values id) : base(id) { } + public override HttpVerb MapValue(Values id) => new(id); - public enum Enum + public enum Values { GET = 1, POST = 2, diff --git a/src/Digdir.Domain.Dialogporten.Domain/Localizations/Localization.cs b/src/Digdir.Domain.Dialogporten.Domain/Localizations/Localization.cs index f639eb2ea..366c7f86d 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Localizations/Localization.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Localizations/Localization.cs @@ -11,16 +11,16 @@ public class Localization : IJoinEntity .Select(x => x.Name) .ToHashSet(); - private string cultureCode = null!; + private string _cultureCode = null!; public DateTimeOffset CreatedAt { get; set; } public DateTimeOffset UpdatedAt { get; set; } public string Value { get; set; } = null!; - public string CultureCode - { - get => cultureCode; - set => cultureCode = NormalizeCultureCode(value)!; + public string CultureCode + { + get => _cultureCode; + set => _cultureCode = NormalizeCultureCode(value)!; } // === Dependent relationships === @@ -28,9 +28,9 @@ public string CultureCode public LocalizationSet LocalizationSet { get; set; } = null!; public static string? NormalizeCultureCode(string? cultureCode) => - cultureCode?.Trim().Replace('_', '-').ToLower(); + cultureCode?.Trim().Replace('_', '-').ToLowerInvariant(); public static bool IsValidCultureCode(string? cultureCode) => - !string.IsNullOrWhiteSpace(cultureCode) && + !string.IsNullOrWhiteSpace(cultureCode) && ValidCultureNames.Contains(cultureCode, StringComparer.InvariantCultureIgnoreCase); } diff --git a/src/Digdir.Domain.Dialogporten.Domain/Outboxes/OutboxMessage.cs b/src/Digdir.Domain.Dialogporten.Domain/Outboxes/OutboxMessage.cs index ccb9e6296..f9b138275 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Outboxes/OutboxMessage.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Outboxes/OutboxMessage.cs @@ -6,7 +6,7 @@ namespace Digdir.Domain.Dialogporten.Domain.Outboxes; public sealed class OutboxMessage { public required Guid EventId { get; init; } - public required string EventType { get; init; } + public required string EventType { get; init; } public required string EventPayload { get; init; } public List OutboxMessageConsumers { get; set; } = new(); @@ -22,4 +22,4 @@ public static OutboxMessage Create(TDomainEvent domainEvent) EventPayload = JsonSerializer.Serialize(domainEvent, eventType) }; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Registry/ResourceRegistryClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Registry/ResourceRegistryClient.cs index 4582b1736..5244b3b65 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Registry/ResourceRegistryClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Altinn/Registry/ResourceRegistryClient.cs @@ -33,23 +33,20 @@ public async Task> GetResourceIds(string org, Cancel return resourceIds ?? Array.Empty(); } - private static DistributedCacheEntryOptions? CacheOptionsFactory(Dictionary? resourceIdsByOrg) => + private static DistributedCacheEntryOptions? CacheOptionsFactory(Dictionary? resourceIdsByOrg) => resourceIdsByOrg is not null ? _oneDayCacheDuration : _zeroCacheDuration; private async Task> GetResourceIdsByOrg(CancellationToken cancellationToken) { - const string SearchEndpoint = "resourceregistry/api/v1/resource/search"; - var response = await _client.GetFromJsonAsync>(SearchEndpoint, cancellationToken); - - if (response is null) - { - throw new UnreachableException(); - } + const string searchEndpoint = "resourceregistry/api/v1/resource/search"; + var response = await _client + .GetFromJsonAsync>(searchEndpoint, cancellationToken) + ?? throw new UnreachableException(); var resourceIdsByOrg = response .GroupBy(x => x.HasCompetentAuthority.Organization) .ToDictionary( - x => x.Key, + x => x.Key, x => x.Select(x => $"{Constants.ServiceResourcePrefix}{x.Identifier}") .ToArray() ); diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/AltinnEventsClient.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/AltinnEventsClient.cs index 30c13578f..0952887e5 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/AltinnEventsClient.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/AltinnEventsClient.cs @@ -36,7 +36,7 @@ public ConsoleLogEventBus(ILogger logger) { _logger = logger; } - + public Task Publish(CloudEvent cloudEvent, CancellationToken cancellationToken) { _logger.LogInformation("Event published! Time: {CloudEventTime:O}, Type: {CloudEventType}", cloudEvent.Time, cloudEvent.Type); diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Common/Serialization/SerializerOptions.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Common/Serialization/SerializerOptions.cs index b41233ea3..b07ae7b3c 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Common/Serialization/SerializerOptions.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Common/Serialization/SerializerOptions.cs @@ -52,6 +52,6 @@ private static void DomainEventModifier(JsonTypeInfo typeInfo) internal class LowerCaseNamingPolicy : JsonNamingPolicy { public override string ConvertName(string name) => - name.ToLower(); + name.ToLowerInvariant(); } diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj b/src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj index 2e8177de9..4ea2d24ff 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Digdir.Domain.Dialogporten.Infrastructure.csproj @@ -1,34 +1,34 @@  - - net7.0 - enable - enable - 750256a4-f332-4783-8802-8a7d9566f9ca - + + net7.0 + enable + enable + 750256a4-f332-4783-8802-8a7d9566f9ca + - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - true - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + true + + + + - - - - + + + + - - - - + + + + diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs index 439aece40..cd3ab4563 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs @@ -28,11 +28,11 @@ public override ValueTask> SavingChangesAsync( var domainEvents = dbContext.ChangeTracker.Entries() .SelectMany(x => - x.Entity is IEventPublisher publisher - ? publisher.DomainEvents + x.Entity is IEventPublisher publisher + ? publisher.DomainEvents : Enumerable.Empty()) .ToList(); - + foreach (var domainEvent in domainEvents) { domainEvent.OccuredAt = _transactionTime.Value; diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/IdempotentDomainEventHandler.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/IdempotentDomainEventHandler.cs index cfbbe38a1..ab7bf7a95 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/IdempotentDomainEventHandler.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/IdempotentDomainEventHandler.cs @@ -38,7 +38,7 @@ public async Task Handle(TDomainEvent notification, CancellationToken cancellati EventId = notification.EventId, ConsumerName = consumer }); - + await _db.SaveChangesAsync(cancellationToken); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/OutboxDispatcher.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/OutboxDispatcher.cs index 8b66854b0..d5b736c67 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/OutboxDispatcher.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/Dispatcher/OutboxDispatcher.cs @@ -72,7 +72,7 @@ private static bool TryToDomainEvent(OutboxMessage outboxMessage, [NotNullWhen(t var eventType = EventAssembly.GetType(outboxMessage.EventType); if (eventType is null) { - domainEvent= null; + domainEvent = null; return false; } diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs index 1d8f453d4..9617f24b3 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs @@ -76,13 +76,13 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi // HttpClient services. AddMaskinportenHttpClient( - infrastructureConfigurationSection, + infrastructureConfigurationSection, x => x.ClientSettings.ExhangeToAltinnToken = true) .ConfigureHttpClient((services, client) => { client.BaseAddress = services.GetRequiredService>().Value.Altinn.BaseUri; }); - services.AddHttpClient((services, client) => + services.AddHttpClient((services, client) => client.BaseAddress = services.GetRequiredService>().Value.Altinn.BaseUri) .AddPolicyHandlerFromRegistry(PollyPolicy.DefaultHttpRetryPolicy); diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogSearchTagConfiguration.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogSearchTagConfiguration.cs index fa55bf77e..1af4af128 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogSearchTagConfiguration.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Configurations/Dialogs/DialogSearchTagConfiguration.cs @@ -9,9 +9,9 @@ internal sealed class DialogSearchTagConfiguration : IEntityTypeConfiguration builder) { - builder.HasIndex(x => new {x.DialogId, x.Value}) + builder.HasIndex(x => new { x.DialogId, x.Value }) .IsUnique(); builder.Property(x => x.Value) .HasMaxLength(Constants.MaxSearchTagLength); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs index d9a84098c..b4b984f04 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/DialogDbContext.cs @@ -34,14 +34,15 @@ public DialogDbContext(DbContextOptions options) : base(options public DbSet OutboxMessageConsumers => Set(); public bool TrySetOriginalETag( - TEntity entity, + TEntity entity, Guid? etag) where TEntity : class, IVersionableEntity { - if (entity is null || !etag.HasValue) + if (entity is null || !etag.HasValue) // TODO: Ask B&M { return false; } + var prop = Entry(entity).Property(x => x.ETag); prop.OriginalValue = etag.Value; prop.IsModified = false; @@ -50,8 +51,8 @@ public bool TrySetOriginalETag( /// public bool MustWhenModified( - TEntity entity, - Expression> propertyExpression, + TEntity entity, + Expression> propertyExpression, Func predicate) where TEntity : class { diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/.editorconfig b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/.editorconfig new file mode 100644 index 000000000..69a07f39d --- /dev/null +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/.editorconfig @@ -0,0 +1,2 @@ +[*] +generated_code = true \ No newline at end of file diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/DialogDbContextModelSnapshot.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/DialogDbContextModelSnapshot.cs index db44c8175..c4eb01db4 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/DialogDbContextModelSnapshot.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/Persistence/Migrations/DialogDbContextModelSnapshot.cs @@ -17,7 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("ProductVersion", "7.0.11") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); diff --git a/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumer.cs b/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumer.cs index 2ba6d21ff..001678d6b 100644 --- a/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumer.cs +++ b/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumer.cs @@ -19,8 +19,8 @@ public async Task Consume(ConsumeContext context) { var eventAssembly = typeof(OutboxMessage).Assembly; var eventType = eventAssembly.GetType(context.Message.EventType); - var @event = JsonSerializer.Deserialize(context.Message.EventPayload, eventType); - await _mediatr.Publish(@event); + var @event = JsonSerializer.Deserialize(context.Message.EventPayload, eventType!); // TODO: Better null handling + await _mediatr.Publish(@event!); // TODO: Better null handling await _mediatr.Send(new DeleteOutboxMessagesCommand { EventId = context.Message.EventId }); } } diff --git a/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumerDefinition.cs b/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumerDefinition.cs index f23998fdf..44f53771d 100644 --- a/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumerDefinition.cs +++ b/src/Digdir.Domain.Dialogporten.Service/Consumers/OutboxMessages/OutboxMessageConsumerDefinition.cs @@ -6,7 +6,8 @@ public sealed class OutboxMessageConsumerDefinition : ConsumerDefinition consumerConfigurator) + IConsumerConfigurator consumerConfigurator, + IRegistrationContext context) { endpointConfigurator.ConfigureConsumeTopology = false; } diff --git a/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj b/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj index 6924a7f7d..980b7635d 100644 --- a/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj +++ b/src/Digdir.Domain.Dialogporten.Service/Digdir.Domain.Dialogporten.Service.csproj @@ -1,25 +1,25 @@ - - Exe - net7.0 - enable - enable - 750256a4-f332-4783-8802-8a7d9566f9ca - Linux - + + Exe + net7.0 + enable + enable + 750256a4-f332-4783-8802-8a7d9566f9ca + Linux + - - - - - - - + + + + + + + - - - - + + + + diff --git a/src/Digdir.Domain.Dialogporten.Service/Program.cs b/src/Digdir.Domain.Dialogporten.Service/Program.cs index 64d3398f8..f02f36fe5 100644 --- a/src/Digdir.Domain.Dialogporten.Service/Program.cs +++ b/src/Digdir.Domain.Dialogporten.Service/Program.cs @@ -1,4 +1,5 @@ -using Digdir.Domain.Dialogporten.Application; +using System.Globalization; +using Digdir.Domain.Dialogporten.Application; using Digdir.Domain.Dialogporten.Infrastructure; using MassTransit; using System.Reflection; @@ -15,7 +16,7 @@ Log.Logger = new LoggerConfiguration() .MinimumLevel.Warning() .Enrich.FromLogContext() - .WriteTo.Console() + .WriteTo.Console(formatProvider: CultureInfo.InvariantCulture) .WriteTo.ApplicationInsights( TelemetryConfiguration.CreateDefault(), TelemetryConverter.Traces) @@ -46,11 +47,13 @@ static void BuildAndRun(string[] args) .ReadFrom.Configuration(context.Configuration) .ReadFrom.Services(services) .Enrich.FromLogContext() - .WriteTo.Console() + .WriteTo.Conditional( + condition: x => builder.Environment.IsDevelopment(), + configureSink: x => x.Console(formatProvider: CultureInfo.InvariantCulture)) .WriteTo.ApplicationInsights( services.GetRequiredService(), TelemetryConverter.Traces)); - + builder.Services .AddApplicationInsightsTelemetry() .AddMassTransit(x => @@ -59,11 +62,12 @@ static void BuildAndRun(string[] args) x.UsingRabbitMq((context, cfg) => { const string rabbitMqSection = "RabbitMq"; - cfg.Host(builder.Configuration[$"{rabbitMqSection}:Host"], "/", h => { + cfg.Host(builder.Configuration[$"{rabbitMqSection}:Host"], "/", h => + { h.Username(builder.Configuration[$"{rabbitMqSection}:Username"]); h.Password(builder.Configuration[$"{rabbitMqSection}:Password"]); }); - cfg.ReceiveEndpoint(thisAssembly.GetName().Name!, x => + cfg.ReceiveEndpoint(thisAssembly.GetName().Name!, x => { x.UseMessageRetry(r => r.Intervals( TimeSpan.FromSeconds(1), @@ -85,5 +89,5 @@ static void BuildAndRun(string[] args) var app = builder.Build(); app.UseHttpsRedirection(); - app.Run(); + app.Run(); } diff --git a/src/Digdir.Domain.Dialogporten.Service/ServiceUser.cs b/src/Digdir.Domain.Dialogporten.Service/ServiceUser.cs index 348169730..c23f03a55 100644 --- a/src/Digdir.Domain.Dialogporten.Service/ServiceUser.cs +++ b/src/Digdir.Domain.Dialogporten.Service/ServiceUser.cs @@ -9,6 +9,6 @@ public ClaimsPrincipal GetPrincipal() { throw new NotSupportedException( "At the time of this writing, Digdir.Domain.Dialogporten.Service should not " + - "be using application commands or queries requiering the need for a user."); + "be using application commands or queries requiring the need for a user."); } } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptions.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptions.cs index 6a451d68a..e6abde0c1 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptions.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptions.cs @@ -1,6 +1,4 @@ -using FluentValidation; - -namespace Digdir.Domain.Dialogporten.WebApi.Common.Options; +namespace Digdir.Domain.Dialogporten.WebApi.Common.Authentication; public sealed class AuthenticationOptions { @@ -11,4 +9,4 @@ public sealed class JwtBearerTokenSchemasOptions { public required string Name { get; init; } public required string WellKnown { get; init; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptionsValidator.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptionsValidator.cs index 005b965fe..7554602ba 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptionsValidator.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authentication/AuthenticationOptionsValidator.cs @@ -1,6 +1,6 @@ using FluentValidation; -namespace Digdir.Domain.Dialogporten.WebApi.Common.Options; +namespace Digdir.Domain.Dialogporten.WebApi.Common.Authentication; internal sealed class AuthenticationOptionsValidator : AbstractValidator { diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AllowAnonymousHandler.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AllowAnonymousHandler.cs index 90e6a95b8..57ab4497f 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AllowAnonymousHandler.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AllowAnonymousHandler.cs @@ -12,9 +12,9 @@ public Task HandleAsync(AuthorizationHandlerContext context) foreach (var requirement in context.PendingRequirements) { //Simply pass all requirements - context.Succeed(requirement); + context.Succeed(requirement); } return Task.CompletedTask; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationOptionsSetup.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationOptionsSetup.cs index 66d542c68..819925afb 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationOptionsSetup.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationOptionsSetup.cs @@ -14,7 +14,7 @@ public AuthorizationOptionsSetup(IOptions options) public void Configure(AuthorizationOptions options) { - var authenticatonSchemas = _options + var authenticationSchemas = _options .Authentication .JwtBearerTokenSchemas .Select(x => x.Name) @@ -22,17 +22,17 @@ public void Configure(AuthorizationOptions options) options.DefaultPolicy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() - .AddAuthenticationSchemes(authenticatonSchemas) + .AddAuthenticationSchemes(authenticationSchemas) .RequireValidConsumerClaim() .Build(); - options.AddPolicy(AuthorizationPolicy.Serviceprovider, builder => builder + options.AddPolicy(AuthorizationPolicy.ServiceProvider, builder => builder .Combine(options.DefaultPolicy) - .RequireScope(AuthorizationScope.Serviceprovider)); + .RequireScope(AuthorizationScope.ServiceProvider)); - options.AddPolicy(AuthorizationPolicy.ServiceproviderSearch, builder => builder + options.AddPolicy(AuthorizationPolicy.ServiceProviderSearch, builder => builder .Combine(options.DefaultPolicy) - .RequireScope(AuthorizationScope.ServiceproviderSearch)); + .RequireScope(AuthorizationScope.ServiceProviderSearch)); options.AddPolicy(AuthorizationPolicy.Testing, builder => builder .Combine(options.DefaultPolicy) diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs index 9a0787268..f6b9e6212 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicy.cs @@ -1,23 +1,27 @@ -namespace Digdir.Domain.Dialogporten.WebApi.Common.Authorization; +using System.Collections.ObjectModel; + +namespace Digdir.Domain.Dialogporten.WebApi.Common.Authorization; internal static class AuthorizationPolicy { - public const string Serviceprovider = "serviceprovider"; - public const string ServiceproviderSearch = "serviceproviderSearch"; + public const string ServiceProvider = "serviceprovider"; + public const string ServiceProviderSearch = "serviceproviderSearch"; public const string Testing = "testing"; } internal static class AuthorizationScope { - public const string Serviceprovider = "digdir:dialogporten.serviceprovider"; - public const string ServiceproviderSearch = "digdir:dialogporten.serviceprovider.search"; + public const string ServiceProvider = "digdir:dialogporten.serviceprovider"; + public const string ServiceProviderSearch = "digdir:dialogporten.serviceprovider.search"; public const string Testing = "digdir:dialogporten.developer.test"; internal static readonly Lazy> AllScopes = new(GetAll); - private static IReadOnlyCollection GetAll() => + + private static ReadOnlyCollection GetAll() => typeof(AuthorizationScope) .GetFields() .Where(x => x.IsLiteral && !x.IsInitOnly && x.DeclaringType == typeof(string)) .Select(x => (string)x.GetRawConstantValue()!) - .ToList(); -} \ No newline at end of file + .ToList() + .AsReadOnly(); +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicyBuilderExtensions.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicyBuilderExtensions.cs index 6843adb9b..8a9e26375 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicyBuilderExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Authorization/AuthorizationPolicyBuilderExtensions.cs @@ -16,6 +16,6 @@ public static AuthorizationPolicyBuilder RequireScope(this AuthorizationPolicyBu .Split(ScopeClaimSeparator, StringSplitOptions.RemoveEmptyEntries) .Contains(scope))); - public static AuthorizationPolicyBuilder RequireValidConsumerClaim(this AuthorizationPolicyBuilder builder) => + public static AuthorizationPolicyBuilder RequireValidConsumerClaim(this AuthorizationPolicyBuilder builder) => builder.RequireAssertion(ctx => ctx.User.TryGetOrgNumber(out _)); -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Extensions/ExceptionHandlerExtensions.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Extensions/ExceptionHandlerExtensions.cs index 28c5258ff..1218dfde1 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Extensions/ExceptionHandlerExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Extensions/ExceptionHandlerExtensions.cs @@ -21,7 +21,7 @@ public static IApplicationBuilder UseProblemDetailsExceptionHandler(this IApplic var type = exHandlerFeature.Error.GetType().Name; var error = exHandlerFeature.Error.Message; var logger = ctx.Resolve>(); - logger.LogError(exHandlerFeature.Error, "{@http}{@type}{@reason}", http, type, error); + logger.LogError(exHandlerFeature.Error, "{@Http}{@Type}{@Reason}", http, type, error); ctx.Response.StatusCode = StatusCodes.Status500InternalServerError; ctx.Response.ContentType = "application/problem+json"; await ctx.Response.WriteAsJsonAsync(ctx.ResponseBuilder(ctx.Response.StatusCode)); @@ -31,5 +31,5 @@ public static IApplicationBuilder UseProblemDetailsExceptionHandler(this IApplic return app; } - private class ExceptionHandler { } -} \ No newline at end of file + private sealed class ExceptionHandler { } +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/Json/UtcDateTimeOffsetConverter.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/Json/UtcDateTimeOffsetConverter.cs index 1cdb18454..495beba52 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/Json/UtcDateTimeOffsetConverter.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/Json/UtcDateTimeOffsetConverter.cs @@ -47,18 +47,18 @@ private static bool HasValidOffset(ReadOnlySpan dateTimeOffsetSpan) return true; } - for (int i = 0; i < offsetSpan.Length; i++) + for (var i = 0; i < offsetSpan.Length; i++) { var value = offsetSpan[i]; var isValid = i switch { - 0 => IsPlussOrMinus(value), + 0 => IsPlusOrMinus(value), 1 => IsNumber(value), 2 => IsNumber(value), 3 => IsSemicolon(value), 4 => IsNumber(value), 5 => IsNumber(value), - _ => throw new IndexOutOfRangeException() + _ => throw new ArgumentOutOfRangeException() }; if (!isValid) @@ -70,8 +70,8 @@ private static bool HasValidOffset(ReadOnlySpan dateTimeOffsetSpan) return true; } - private static bool IsNumber(byte value) => 48 <= value && value <= 57; + private static bool IsNumber(byte value) => value is >= 48 and <= 57; private static bool IsZ(byte value) => value == 90; - private static bool IsPlussOrMinus(byte value) => value == 43 || value == 45; + private static bool IsPlusOrMinus(byte value) => value is 43 or 45; private static bool IsSemicolon(byte value) => value == 58; } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Common/WebApiSettings.cs b/src/Digdir.Domain.Dialogporten.WebApi/Common/WebApiSettings.cs index 41cc33f02..105d490e1 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Common/WebApiSettings.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Common/WebApiSettings.cs @@ -1,4 +1,4 @@ -using Digdir.Domain.Dialogporten.WebApi.Common.Options; +using Digdir.Domain.Dialogporten.WebApi.Common.Authentication; using FluentValidation; namespace Digdir.Domain.Dialogporten.WebApi.Common; diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj b/src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj index 8368b8c79..909545b05 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj +++ b/src/Digdir.Domain.Dialogporten.WebApi/Digdir.Domain.Dialogporten.WebApi.csproj @@ -1,29 +1,29 @@ - - net7.0 - enable - enable - 750256a4-f332-4783-8802-8a7d9566f9ca - Linux - + + net7.0 + enable + enable + 750256a4-f332-4783-8802-8a7d9566f9ca + Linux + - - - - - - - - - - - - + + + + + + + + + + + + - - - - + + + + diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/Dialog/ListDialogEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/Dialog/SearchDialogEndpoint.cs similarity index 75% rename from src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/Dialog/ListDialogEndpoint.cs rename to src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/Dialog/SearchDialogEndpoint.cs index 940efaa48..458303483 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/Dialog/ListDialogEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/Dialog/SearchDialogEndpoint.cs @@ -1,15 +1,15 @@ -using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.List; +using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Queries.Search; using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; using FastEndpoints; using MediatR; namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.EndUser.Dialog; -public class ListDialogEndpoint : Endpoint +public class SearchDialogEndpoint : Endpoint { private readonly ISender _sender; - public ListDialogEndpoint(ISender sender) + public SearchDialogEndpoint(ISender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); } @@ -20,7 +20,7 @@ public override void Configure() Group(); } - public override async Task HandleAsync(ListDialogQuery req, CancellationToken ct) + public override async Task HandleAsync(SearchDialogQuery req, CancellationToken ct) { var result = await _sender.Send(req, ct); await result.Match( diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogActivity/ListDialogActivityEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogActivity/SearchDialogActivityEndpoint.cs similarity index 73% rename from src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogActivity/ListDialogActivityEndpoint.cs rename to src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogActivity/SearchDialogActivityEndpoint.cs index 66a1ad621..8decd2bbc 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogActivity/ListDialogActivityEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogActivity/SearchDialogActivityEndpoint.cs @@ -1,15 +1,15 @@ -using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.List; +using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogActivities.Queries.Search; using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; using FastEndpoints; using MediatR; namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.EndUser.DialogActivity; -public class ListDialogActivityEndpoint : Endpoint +public class SearchDialogActivityEndpoint : Endpoint { private readonly ISender _sender; - public ListDialogActivityEndpoint(ISender sender) + public SearchDialogActivityEndpoint(ISender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); } @@ -20,7 +20,7 @@ public override void Configure() Group(); } - public override async Task HandleAsync(ListDialogActivityQuery req, CancellationToken ct) + public override async Task HandleAsync(SearchDialogActivityQuery req, CancellationToken ct) { var result = await _sender.Send(req, ct); await result.Match( @@ -28,4 +28,4 @@ await result.Match( notFound => this.NotFoundAsync(notFound, ct), deleted => this.GoneAsync(deleted, ct)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogElement/ListDialogElementEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogElement/SearchDialogElementEndpoint.cs similarity index 73% rename from src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogElement/ListDialogElementEndpoint.cs rename to src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogElement/SearchDialogElementEndpoint.cs index 3048cb551..3be0f27c4 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogElement/ListDialogElementEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/EndUser/DialogElement/SearchDialogElementEndpoint.cs @@ -1,15 +1,15 @@ -using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.List; +using Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.DialogElements.Queries.Search; using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; using FastEndpoints; using MediatR; namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.EndUser.DialogElement; -public class ListDialogElementEndpoint : Endpoint +public class SearchDialogElementEndpoint : Endpoint { private readonly ISender _sender; - public ListDialogElementEndpoint(ISender sender) + public SearchDialogElementEndpoint(ISender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); } @@ -20,7 +20,7 @@ public override void Configure() Group(); } - public override async Task HandleAsync(ListDialogElementQuery req, CancellationToken ct) + public override async Task HandleAsync(SearchDialogElementQuery req, CancellationToken ct) { var result = await _sender.Send(req, ct); await result.Match( @@ -28,4 +28,4 @@ await result.Match( notFound => this.NotFoundAsync(notFound, ct), deleted => this.GoneAsync(deleted, ct)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/CreateDialogEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/CreateDialogEndpoint.cs index f4c806063..57f716d9a 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/CreateDialogEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/CreateDialogEndpoint.cs @@ -19,7 +19,7 @@ public CreateDialogEndpoint(ISender sender) public override void Configure() { Post("dialogs"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/DeleteDialogEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/DeleteDialogEndpoint.cs index 963b71d2b..e6eaf0653 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/DeleteDialogEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/DeleteDialogEndpoint.cs @@ -19,7 +19,7 @@ public DeleteDialogEndpoint(ISender sender) public override void Configure() { Delete("dialogs/{dialogId}"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/GetDialogEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/GetDialogEndpoint.cs index aeedab969..1f8825007 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/GetDialogEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/GetDialogEndpoint.cs @@ -18,7 +18,7 @@ public GetDialogEndpoint(ISender sender) public override void Configure() { Get("dialogs/{dialogId}"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/PatchDialogsController.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/PatchDialogsController.cs index 1f50b2554..c82d9bd83 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/PatchDialogsController.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/PatchDialogsController.cs @@ -20,7 +20,7 @@ namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.Dialog; [ApiController] [Route("api/v1/serviceowner/dialogs")] [Tags(ServiceOwnerGroup.RoutePrefix)] -[Authorize(Policy = DialogportenAuthorizationPolizy.Serviceprovider)] +[Authorize(Policy = DialogportenAuthorizationPolizy.ServiceProvider)] public sealed class PatchDialogsController : ControllerBase { private readonly ISender _sender; diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/ListDialogEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/SearchDialogEndpoint.cs similarity index 72% rename from src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/ListDialogEndpoint.cs rename to src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/SearchDialogEndpoint.cs index 7866d94cd..0c57180fd 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/ListDialogEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/SearchDialogEndpoint.cs @@ -1,4 +1,4 @@ -using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.List; +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Queries.Search; using Digdir.Domain.Dialogporten.WebApi.Common.Authorization; using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; using FastEndpoints; @@ -6,11 +6,11 @@ namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.Dialog; -public class ListDialogEndpoint : Endpoint +public class SearchDialogEndpoint : Endpoint { private readonly ISender _sender; - public ListDialogEndpoint(ISender sender) + public SearchDialogEndpoint(ISender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); } @@ -18,11 +18,11 @@ public ListDialogEndpoint(ISender sender) public override void Configure() { Get("dialogs"); - Policies(AuthorizationPolicy.ServiceproviderSearch); + Policies(AuthorizationPolicy.ServiceProviderSearch); Group(); } - public override async Task HandleAsync(ListDialogQuery req, CancellationToken ct) + public override async Task HandleAsync(SearchDialogQuery req, CancellationToken ct) { var result = await _sender.Send(req, ct); await result.Match( diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/UpdateDialogEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/UpdateDialogEndpoint.cs index 3187846a3..8999ee4dc 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/UpdateDialogEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/Dialog/UpdateDialogEndpoint.cs @@ -19,7 +19,7 @@ public UpdateDialogEndpoint(ISender sender) public override void Configure() { Put("dialogs/{dialogId}"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/CreateDialogActivityEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/CreateDialogActivityEndpoint.cs index 01a61b07b..80777a505 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/CreateDialogActivityEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/CreateDialogActivityEndpoint.cs @@ -25,13 +25,13 @@ public CreateDialogActivityEndpoint(ISender sender, IMapper mapper) public override void Configure() { Post("dialogs/{dialogId}/activities"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } - public override async Task HandleAsync(CreateDialogActivityRequest request, CancellationToken ct) + public override async Task HandleAsync(CreateDialogActivityRequest req, CancellationToken ct) { - var dialogQueryResult = await _sender.Send(new GetDialogQuery {DialogId = request.DialogId}, ct); + var dialogQueryResult = await _sender.Send(new GetDialogQuery { DialogId = req.DialogId }, ct); if (dialogQueryResult.TryPickT1(out var entityNotFound, out var dialog)) { await this.NotFoundAsync(entityNotFound, cancellationToken: ct); @@ -44,17 +44,17 @@ public override async Task HandleAsync(CreateDialogActivityRequest request, Canc var updateDialogDto = _mapper.Map(dialog); - request.Id = !request.Id.HasValue || request.Id.Value == default + req.Id = !req.Id.HasValue || req.Id.Value == default ? Uuid7.NewUuid7().ToGuid() - : request.Id; + : req.Id; - updateDialogDto.Activities.Add(request); + updateDialogDto.Activities.Add(req); - var updateDialogCommand = new UpdateDialogCommand {Id = request.DialogId, ETag = request.ETag, Dto = updateDialogDto}; + var updateDialogCommand = new UpdateDialogCommand { Id = req.DialogId, ETag = req.ETag, Dto = updateDialogDto }; var result = await _sender.Send(updateDialogCommand, ct); await result.Match( - success => SendCreatedAtAsync(new GetDialogActivityQuery {DialogId = dialog.Id, ActivityId = request.Id.Value}, request.Id, cancellation: ct), + success => SendCreatedAtAsync(new GetDialogActivityQuery { DialogId = dialog.Id, ActivityId = req.Id.Value }, req.Id, cancellation: ct), notFound => this.NotFoundAsync(notFound, ct), validationError => this.BadRequestAsync(validationError, ct), domainError => this.UnprocessableEntityAsync(domainError, ct), @@ -68,4 +68,4 @@ public sealed class CreateDialogActivityRequest : UpdateDialogDialogActivityDto [FromHeader(headerName: Constants.IfMatch, isRequired: false)] public Guid? ETag { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/GetDialogActivityEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/GetDialogActivityEndpoint.cs index 88c398231..b435d27e4 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/GetDialogActivityEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/GetDialogActivityEndpoint.cs @@ -18,7 +18,7 @@ public GetDialogActivityEndpoint(ISender sender) public override void Configure() { Get("dialogs/{dialogId}/activities/{activityId}"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/ListDialogActivityEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/SearchDialogActivityEndpoint.cs similarity index 69% rename from src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/ListDialogActivityEndpoint.cs rename to src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/SearchDialogActivityEndpoint.cs index 8f71937ba..9f487d323 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/ListDialogActivityEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogActivity/SearchDialogActivityEndpoint.cs @@ -1,4 +1,4 @@ -using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.List; +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogActivities.Queries.Search; using Digdir.Domain.Dialogporten.WebApi.Common.Authorization; using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; using FastEndpoints; @@ -6,11 +6,11 @@ namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.DialogActivity; -public class ListDialogActivityEndpoint : Endpoint +public class SearchDialogActivityEndpoint : Endpoint { private readonly ISender _sender; - public ListDialogActivityEndpoint(ISender sender) + public SearchDialogActivityEndpoint(ISender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); } @@ -18,15 +18,15 @@ public ListDialogActivityEndpoint(ISender sender) public override void Configure() { Get("dialogs/{dialogId}/activities"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } - public override async Task HandleAsync(ListDialogActivityQuery req, CancellationToken ct) + public override async Task HandleAsync(SearchDialogActivityQuery req, CancellationToken ct) { var result = await _sender.Send(req, ct); await result.Match( dto => SendOkAsync(dto, ct), notFound => this.NotFoundAsync(notFound, ct)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/CreateDialogElementEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/CreateDialogElementEndpoint.cs index b8fc00d49..b49a2802e 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/CreateDialogElementEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/CreateDialogElementEndpoint.cs @@ -25,13 +25,13 @@ public CreateDialogActivityEndpoint(ISender sender, IMapper mapper) public override void Configure() { Post("dialogs/{dialogId}/elements"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } - public override async Task HandleAsync(CreateDialogElementRequest request, CancellationToken ct) + public override async Task HandleAsync(CreateDialogElementRequest req, CancellationToken ct) { - var dialogQueryResult = await _sender.Send(new GetDialogQuery {DialogId = request.DialogId}, ct); + var dialogQueryResult = await _sender.Send(new GetDialogQuery { DialogId = req.DialogId }, ct); if (dialogQueryResult.TryPickT1(out var entityNotFound, out var dialog)) { await this.NotFoundAsync(entityNotFound, cancellationToken: ct); @@ -40,17 +40,17 @@ public override async Task HandleAsync(CreateDialogElementRequest request, Cance var updateDialogDto = _mapper.Map(dialog); - request.Id = !request.Id.HasValue || request.Id.Value == default + req.Id = !req.Id.HasValue || req.Id.Value == default ? Uuid7.NewUuid7().ToGuid() - : request.Id; + : req.Id; - updateDialogDto.Elements.Add(request); + updateDialogDto.Elements.Add(req); - var updateDialogCommand = new UpdateDialogCommand {Id = request.DialogId, ETag = request.ETag, Dto = updateDialogDto}; + var updateDialogCommand = new UpdateDialogCommand { Id = req.DialogId, ETag = req.ETag, Dto = updateDialogDto }; var result = await _sender.Send(updateDialogCommand, ct); await result.Match( - success => SendCreatedAtAsync(new GetDialogElementQuery {DialogId = dialog.Id, ElementId = request.Id.Value}, request.Id, cancellation: ct), + success => SendCreatedAtAsync(new GetDialogElementQuery { DialogId = dialog.Id, ElementId = req.Id.Value }, req.Id, cancellation: ct), notFound => this.NotFoundAsync(notFound, ct), validationError => this.BadRequestAsync(validationError, ct), domainError => this.UnprocessableEntityAsync(domainError, ct), @@ -64,4 +64,4 @@ public sealed class CreateDialogElementRequest : UpdateDialogDialogElementDto [FromHeader(headerName: Constants.IfMatch, isRequired: false)] public Guid? ETag { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/DeleteDialogElementEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/DeleteDialogElementEndpoint.cs index 696b07028..ca8e4f508 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/DeleteDialogElementEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/DeleteDialogElementEndpoint.cs @@ -24,13 +24,13 @@ public DeleteDialogActivityEndpoint(ISender sender, IMapper mapper) public override void Configure() { Delete("dialogs/{dialogId}/elements/{elementId}"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } - public override async Task HandleAsync(DeleteDialogElementRequest request, CancellationToken ct) + public override async Task HandleAsync(DeleteDialogElementRequest req, CancellationToken ct) { - var dialogQueryResult = await _sender.Send(new GetDialogQuery {DialogId = request.DialogId}, ct); + var dialogQueryResult = await _sender.Send(new GetDialogQuery { DialogId = req.DialogId }, ct); if (dialogQueryResult.TryPickT1(out var entityNotFound, out var dialog)) { await this.NotFoundAsync(entityNotFound, cancellationToken: ct); @@ -43,17 +43,17 @@ public override async Task HandleAsync(DeleteDialogElementRequest request, Cance var updateDialogDto = _mapper.Map(dialog); - var dialogElement = updateDialogDto.Elements.FirstOrDefault(x => x.Id == request.ElementId); + var dialogElement = updateDialogDto.Elements.FirstOrDefault(x => x.Id == req.ElementId); if (dialogElement is null) { - await this.NotFoundAsync(new EntityNotFound(request.ElementId), cancellationToken: ct); + await this.NotFoundAsync(new EntityNotFound(req.ElementId), cancellationToken: ct); return; } - + updateDialogDto.Elements.Remove(dialogElement); var updateDialogCommand = new UpdateDialogCommand - {Id = request.DialogId, ETag = request.ETag, Dto = updateDialogDto}; + { Id = req.DialogId, ETag = req.ETag, Dto = updateDialogDto }; var result = await _sender.Send(updateDialogCommand, ct); await result.Match( @@ -65,11 +65,11 @@ await result.Match( } } -public sealed class DeleteDialogElementRequest +public sealed class DeleteDialogElementRequest { public Guid DialogId { get; set; } public Guid ElementId { get; set; } [FromHeader(headerName: Constants.IfMatch, isRequired: false)] public Guid? ETag { get; set; } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/GetDialogElementEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/GetDialogElementEndpoint.cs index bc5e94342..c7bb8a3da 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/GetDialogElementEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/GetDialogElementEndpoint.cs @@ -18,7 +18,7 @@ public GetDialogElementEndpoint(ISender sender) public override void Configure() { Get("dialogs/{dialogId}/elements/{elementId}"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/ListDialogElementEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/SearchDialogElementEndpoint.cs similarity index 70% rename from src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/ListDialogElementEndpoint.cs rename to src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/SearchDialogElementEndpoint.cs index db8d2a69c..fd105acee 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/ListDialogElementEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/SearchDialogElementEndpoint.cs @@ -1,4 +1,4 @@ -using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.List; +using Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.DialogElements.Queries.Search; using Digdir.Domain.Dialogporten.WebApi.Common.Authorization; using Digdir.Domain.Dialogporten.WebApi.Common.Extensions; using FastEndpoints; @@ -6,11 +6,11 @@ namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.DialogElement; -public class ListDialogElementEndpoint : Endpoint +public class SearchDialogElementEndpoint : Endpoint { private readonly ISender _sender; - public ListDialogElementEndpoint(ISender sender) + public SearchDialogElementEndpoint(ISender sender) { _sender = sender ?? throw new ArgumentNullException(nameof(sender)); } @@ -18,15 +18,15 @@ public ListDialogElementEndpoint(ISender sender) public override void Configure() { Get("dialogs/{dialogId}/elements"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } - public override async Task HandleAsync(ListDialogElementQuery req, CancellationToken ct) + public override async Task HandleAsync(SearchDialogElementQuery req, CancellationToken ct) { var result = await _sender.Send(req, ct); await result.Match( dto => SendOkAsync(dto, ct), notFound => this.NotFoundAsync(notFound, ct)); } -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/UpdateDialogElementEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/UpdateDialogElementEndpoint.cs index 806dec314..7ce25bda5 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/UpdateDialogElementEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/DialogElement/UpdateDialogElementEndpoint.cs @@ -25,13 +25,13 @@ public UpdateDialogActivityEndpoint(ISender sender, IMapper mapper) public override void Configure() { Put("dialogs/{dialogId}/elements/{elementId}"); - Policies(AuthorizationPolicy.Serviceprovider); + Policies(AuthorizationPolicy.ServiceProvider); Group(); } - public override async Task HandleAsync(UpdateDialogElementRequest request, CancellationToken ct) + public override async Task HandleAsync(UpdateDialogElementRequest req, CancellationToken ct) { - var dialogQueryResult = await _sender.Send(new GetDialogQuery {DialogId = request.DialogId}, ct); + var dialogQueryResult = await _sender.Send(new GetDialogQuery { DialogId = req.DialogId }, ct); if (dialogQueryResult.TryPickT1(out var entityNotFound, out var dialog)) { await this.NotFoundAsync(entityNotFound, cancellationToken: ct); @@ -40,22 +40,22 @@ public override async Task HandleAsync(UpdateDialogElementRequest request, Cance var updateDialogDto = _mapper.Map(dialog); - var dialogElement = updateDialogDto.Elements.FirstOrDefault(x => x.Id == request.ElementId); + var dialogElement = updateDialogDto.Elements.FirstOrDefault(x => x.Id == req.ElementId); if (dialogElement is null) { await this.NotFoundAsync( - new EntityNotFound(request.ElementId), + new EntityNotFound(req.ElementId), cancellationToken: ct); return; } updateDialogDto.Elements.Remove(dialogElement); - var updateDialogElementDto = MapToUpdateDto(request); + var updateDialogElementDto = MapToUpdateDto(req); updateDialogDto.Elements.Add(updateDialogElementDto); var updateDialogCommand = new UpdateDialogCommand - {Id = request.DialogId, ETag = request.ETag, Dto = updateDialogDto}; + { Id = req.DialogId, ETag = req.ETag, Dto = updateDialogDto }; var result = await _sender.Send(updateDialogCommand, ct); await result.Match( @@ -93,4 +93,4 @@ public sealed class UpdateDialogElementRequest public List DisplayName { get; set; } = new(); public List Urls { get; set; } = new(); -} \ No newline at end of file +} diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/ServiceOwnerGroup.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/ServiceOwnerGroup.cs index b532e4bfa..2f1c8c4be 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/ServiceOwnerGroup.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/ServiceOwner/ServiceOwnerGroup.cs @@ -2,12 +2,12 @@ namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner; -public class ServiceOwnerGroup : Group +public sealed class ServiceOwnerGroup : Group { public const string RoutePrefix = "Serviceowner"; public ServiceOwnerGroup() { - Configure(RoutePrefix.ToLower(), ep => + Configure(RoutePrefix.ToLowerInvariant(), ep => { ep.EndpointVersion(1); }); diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Testing/ExceptionEndpoint.cs b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Testing/ExceptionEndpoint.cs index d7f57a5cb..791702f99 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Testing/ExceptionEndpoint.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Endpoints/V1/Testing/ExceptionEndpoint.cs @@ -12,16 +12,16 @@ public override void Configure() Description(x => x.ExcludeFromDescription()); } - public override Task HandleAsync(ExceptionEndpointRequest request, CancellationToken ct) + public override Task HandleAsync(ExceptionEndpointRequest req, CancellationToken ct) { - var exceptionType = Type.GetType(request.ExceptionType); + var exceptionType = Type.GetType(req.ExceptionType); if (exceptionType is null || !exceptionType.IsAssignableTo(typeof(Exception))) { - throw new Exception(request.ExceptionMessage); + throw new ArgumentException(req.ExceptionMessage); } - throw (Exception)Activator.CreateInstance(exceptionType, request.ExceptionMessage)!; + throw (Exception)Activator.CreateInstance(exceptionType, req.ExceptionMessage)!; } } diff --git a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs index 555daf344..09a7e6b47 100644 --- a/src/Digdir.Domain.Dialogporten.WebApi/Program.cs +++ b/src/Digdir.Domain.Dialogporten.WebApi/Program.cs @@ -25,7 +25,7 @@ .MinimumLevel.Warning() .Enrich.FromLogContext() .WriteTo.ApplicationInsights( - TelemetryConfiguration.CreateDefault(), + TelemetryConfiguration.CreateDefault(), TelemetryConverter.Traces) .CreateBootstrapLogger(); @@ -146,9 +146,9 @@ static void BuildAndRun(string[] args) app.Run(); } -static void IgnoreEmptyCollections(JsonTypeInfo type_info) +static void IgnoreEmptyCollections(JsonTypeInfo typeInfo) { - foreach (var property in type_info.Properties) + foreach (var property in typeInfo.Properties) { if (property.PropertyType.IsAssignableTo(typeof(ICollection))) { diff --git a/src/Digdir.Library.Entity.Abstractions/Digdir.Library.Entity.Abstractions.csproj b/src/Digdir.Library.Entity.Abstractions/Digdir.Library.Entity.Abstractions.csproj index 2e3da7a58..ef57fa1c6 100644 --- a/src/Digdir.Library.Entity.Abstractions/Digdir.Library.Entity.Abstractions.csproj +++ b/src/Digdir.Library.Entity.Abstractions/Digdir.Library.Entity.Abstractions.csproj @@ -1,17 +1,17 @@  - - net7.0 - enable - enable - true - - - - - - - + + net7.0 + enable + enable + true + + + + + + + diff --git a/src/Digdir.Library.Entity.Abstractions/Features/Aggregate/AggregateNode.cs b/src/Digdir.Library.Entity.Abstractions/Features/Aggregate/AggregateNode.cs index 50f132a09..a6d037fbf 100644 --- a/src/Digdir.Library.Entity.Abstractions/Features/Aggregate/AggregateNode.cs +++ b/src/Digdir.Library.Entity.Abstractions/Features/Aggregate/AggregateNode.cs @@ -36,7 +36,8 @@ public abstract class AggregateNode /// /// Initializes a new instance of the class. /// - protected AggregateNode(object entity, AggregateNodeState state, IEnumerable modifiedProperties) + protected AggregateNode(object entity, AggregateNodeState state, + IEnumerable modifiedProperties) { Entity = entity; State = state; @@ -45,7 +46,8 @@ protected AggregateNode(object entity, AggregateNodeState state, IEnumerable _children.Add(node); - internal static AggregateNode Create(Type type, object entity, AggregateNodeState state, IEnumerable modifiedProperties) + internal static AggregateNode Create(Type type, object entity, AggregateNodeState state, + IEnumerable modifiedProperties) { if (!entity.GetType().IsAssignableTo(type)) { @@ -55,7 +57,8 @@ internal static AggregateNode Create(Type type, object entity, AggregateNodeStat var nodeArguments = new[] { entity, state, modifiedProperties }; var genericType = _openGenericAggregateNodeType.MakeGenericType(type); - var node = (AggregateNode) Activator.CreateInstance(genericType, BindingFlags.NonPublic | BindingFlags.Instance, null, nodeArguments, null)!; + var node = (AggregateNode)Activator.CreateInstance(genericType, BindingFlags.NonPublic | BindingFlags.Instance, + null, nodeArguments, null)!; return node; } } @@ -70,9 +73,12 @@ public sealed class AggregateNode : AggregateNode /// /// The actual entity in the aggregate tree this node represents. /// - public new T Entity => (T) base.Entity; - private AggregateNode(T entity, AggregateNodeState state, IEnumerable modifiedProperties) - : base(entity, state, modifiedProperties) { } + public new T Entity => (T)base.Entity; + + private AggregateNode(T entity, AggregateNodeState state, IEnumerable modifiedProperties) + : base(entity, state, modifiedProperties) + { + } } /// @@ -96,7 +102,7 @@ public enum AggregateNodeState Deleted = 3, /// - /// The entitys property values have not been changed from the values in the database. + /// The entities property values have not been changed from the values in the database. /// Unchanged = 4 } @@ -144,7 +150,8 @@ internal static AggregateNodeProperty Create( { var nodeArguments = new[] { propertyName, originalValue, currentValue }; var genericType = _openGenericAggregateNodePropertyType.MakeGenericType(propertyType); - var property = (AggregateNodeProperty)Activator.CreateInstance(genericType, BindingFlags.NonPublic | BindingFlags.Instance, null, nodeArguments, null)!; + var property = (AggregateNodeProperty)Activator.CreateInstance(genericType, + BindingFlags.NonPublic | BindingFlags.Instance, null, nodeArguments, null)!; return property; } } @@ -171,5 +178,8 @@ public sealed class AggregateNodeProperty : AggregateNodeProperty /// The name of the property that has been modified. /// The original value of the property before modification. /// The current value of the property after modification. - private AggregateNodeProperty(string propertyName, T originalValue, T currentValue) : base(propertyName, originalValue, currentValue) { } + private AggregateNodeProperty(string propertyName, T originalValue, T currentValue) : base(propertyName, + originalValue, currentValue) + { + } } diff --git a/src/Digdir.Library.Entity.Abstractions/Features/Creatable/CreatableExtensions.cs b/src/Digdir.Library.Entity.Abstractions/Features/Creatable/CreatableExtensions.cs index 9dbe5a6c2..0f5a5c683 100644 --- a/src/Digdir.Library.Entity.Abstractions/Features/Creatable/CreatableExtensions.cs +++ b/src/Digdir.Library.Entity.Abstractions/Features/Creatable/CreatableExtensions.cs @@ -12,8 +12,8 @@ public static class CreatableExtensions /// The creation time in UTC. public static void Create(this ICreatableEntity creatable, DateTimeOffset utcNow) { - creatable.CreatedAt = creatable.CreatedAt == default - ? utcNow + creatable.CreatedAt = creatable.CreatedAt == default + ? utcNow : creatable.CreatedAt; } } diff --git a/src/Digdir.Library.Entity.Abstractions/Features/EventPublisher/IDomainEvent.cs b/src/Digdir.Library.Entity.Abstractions/Features/EventPublisher/IDomainEvent.cs index ef815e7b4..5245ba410 100644 --- a/src/Digdir.Library.Entity.Abstractions/Features/EventPublisher/IDomainEvent.cs +++ b/src/Digdir.Library.Entity.Abstractions/Features/EventPublisher/IDomainEvent.cs @@ -15,5 +15,5 @@ public interface IDomainEvent : INotification /// /// The time in which the event, as well as all the actual changes occured. /// - DateTimeOffset OccuredAt { get; set; } -} \ No newline at end of file + DateTimeOffset OccuredAt { get; set; } +} diff --git a/src/Digdir.Library.Entity.Abstractions/Features/Versionable/VersionableExtensions.cs b/src/Digdir.Library.Entity.Abstractions/Features/Versionable/VersionableExtensions.cs index 4d9973ab1..9aa376233 100644 --- a/src/Digdir.Library.Entity.Abstractions/Features/Versionable/VersionableExtensions.cs +++ b/src/Digdir.Library.Entity.Abstractions/Features/Versionable/VersionableExtensions.cs @@ -9,9 +9,7 @@ public static class VersionableExtensions /// Sets properties related to . /// /// The to update. - /// The entity tag unique to each version of the entity. - public static void NewVersion(this IVersionableEntity concurrentEntity, Guid? guid = null) - { - concurrentEntity.ETag = guid ?? Guid.NewGuid(); - } -} \ No newline at end of file + /// The entity tag unique to each version of the entity. + public static void NewVersion(this IVersionableEntity concurrentEntity, Guid? eTag = null) => + concurrentEntity.ETag = eTag ?? Guid.NewGuid(); +} diff --git a/src/Digdir.Library.Entity.EntityFrameworkCore/Digdir.Library.Entity.EntityFrameworkCore.csproj b/src/Digdir.Library.Entity.EntityFrameworkCore/Digdir.Library.Entity.EntityFrameworkCore.csproj index 3df3d7a2d..e145e811d 100644 --- a/src/Digdir.Library.Entity.EntityFrameworkCore/Digdir.Library.Entity.EntityFrameworkCore.csproj +++ b/src/Digdir.Library.Entity.EntityFrameworkCore/Digdir.Library.Entity.EntityFrameworkCore.csproj @@ -1,18 +1,18 @@  - - net7.0 - enable - enable - true - + + net7.0 + enable + enable + true + - + - + diff --git a/src/Digdir.Library.Entity.EntityFrameworkCore/EntityLibraryEfCoreExtensions.cs b/src/Digdir.Library.Entity.EntityFrameworkCore/EntityLibraryEfCoreExtensions.cs index 1aadd92f9..0f2e33784 100644 --- a/src/Digdir.Library.Entity.EntityFrameworkCore/EntityLibraryEfCoreExtensions.cs +++ b/src/Digdir.Library.Entity.EntityFrameworkCore/EntityLibraryEfCoreExtensions.cs @@ -51,7 +51,7 @@ public static async Task HandleAuditableEntities(this ChangeTrack .HandleImmutableEntities() //.HandleVersionableEntities() .HandleCreatableEntities(utcNow); - //.HandleUpdatableEntities(utcNow); + //.HandleUpdatableEntities(utcNow); await changeTracker.HandleAggregateEntities(utcNow, cancellationToken); return changeTracker.HandleSoftDeletableEntities(utcNow); } diff --git a/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Aggregate/AggregateExtensions.cs b/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Aggregate/AggregateExtensions.cs index bb2c41099..83ba72d8d 100644 --- a/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Aggregate/AggregateExtensions.cs +++ b/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Aggregate/AggregateExtensions.cs @@ -70,9 +70,10 @@ private static async Task AddAggregateParentChain( EntityEntry entry, CancellationToken cancellationToken) { - if (!nodeByEntry.ContainsKey(entry)) + if (!nodeByEntry.TryGetValue(entry, out var value)) { - nodeByEntry[entry] = entry.ToAggregateNode(); + value = entry.ToAggregateNode(); + nodeByEntry[entry] = value; } foreach (var parentForeignKey in entry.Metadata.FindAggregateParents()) @@ -94,14 +95,10 @@ private static async Task AddAggregateParentChain( } var parentEntity = await entry.Context - .FindAsync(parentType, parentPrimaryKey, cancellationToken: cancellationToken); - - if (parentEntity is null) - { - throw new InvalidOperationException( + .FindAsync(parentType, parentPrimaryKey, cancellationToken: cancellationToken) + ?? throw new InvalidOperationException( $"Could not find parent {parentType.Name} on {entry.Metadata.ClrType.Name} " + $"with key [{string.Join(",", parentPrimaryKey)}]."); - } var parentEntry = entry.Context.Entry(parentEntity); @@ -111,7 +108,7 @@ private static async Task AddAggregateParentChain( await nodeByEntry.AddAggregateParentChain(parentEntry, cancellationToken); } - parentNode.AddChild(nodeByEntry[entry]); + parentNode.AddChild(value); } } @@ -137,8 +134,8 @@ private static AggregateNode ToAggregateNode(this EntityEntry entry) // x.CurrentValue)); return AggregateNode.Create( - entry.Entity.GetType(), - entry.Entity, + entry.Entity.GetType(), + entry.Entity, aggregateState, Enumerable.Empty()); } @@ -150,7 +147,7 @@ private static IEnumerable FindAggregateParents(this IEntityType en .Where(x => x .PrincipalToDependent? .PropertyInfo? - .GetCustomAttribute() + .GetCustomAttribute() is not null); } @@ -159,4 +156,4 @@ private sealed class EntityEntryComparer : IEqualityComparer public bool Equals(EntityEntry? x, EntityEntry? y) => ReferenceEquals(x?.Entity, y?.Entity); public int GetHashCode(EntityEntry obj) => obj.Entity.GetHashCode(); } -} \ No newline at end of file +} diff --git a/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Lookup/LookupEntityExtensions.cs b/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Lookup/LookupEntityExtensions.cs index ad54a7446..5c7609c07 100644 --- a/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Lookup/LookupEntityExtensions.cs +++ b/src/Digdir.Library.Entity.EntityFrameworkCore/Features/Lookup/LookupEntityExtensions.cs @@ -25,7 +25,7 @@ public static ModelBuilder AddLookupEntities(this ModelBuilder modelBuilder) lookupEntity.Property(nameof(MockLookupEntity.Id)).ValueGeneratedNever(); lookupEntity.Property(nameof(MockLookupEntity.Name)).IsRequired(); lookupEntity.HasData(values); - + foreach (var reference in lookupType.GetReferencingForeignKeys()) { reference.DeleteBehavior = DeleteBehavior.Restrict; diff --git a/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/AsciiTableFormatter.cs b/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/AsciiTableFormatter.cs index a399db1b6..041c829d7 100644 --- a/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/AsciiTableFormatter.cs +++ b/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/AsciiTableFormatter.cs @@ -1,5 +1,4 @@ -using System.Data; -using System.Text; +using System.Text; namespace Digdir.Tool.Dialogporten.SlackNotifier.Common; @@ -10,19 +9,19 @@ public static string ToAsciiTable(this IEnumerable> rows) => .ToList() .ToAsciiTable(); - public static string ToAsciiTable(this List> rows) + private static string ToAsciiTable(this List> rows) { - var bldr = new StringBuilder(); + var builder = new StringBuilder(); var sizes = MaxLengthInEachColumn(rows); var types = GetColumnTypes(rows); - for (int rowNum = 0; rowNum < rows.Count; rowNum++) + for (var rowNum = 0; rowNum < rows.Count; rowNum++) { if (rowNum == 0) { // Top border - AppendLine(bldr, sizes); + AppendLine(builder, sizes); if (rows[0][0] == null) { continue; @@ -30,65 +29,65 @@ public static string ToAsciiTable(this List> rows) } var row = rows[rowNum]; - for (int i = 0; i < row.Count; i++) + for (var i = 0; i < row.Count; i++) { var item = row[i]!; var size = sizes[i]; - bldr.Append("| "); + builder.Append("| "); if (item == null) { - bldr.Append("".PadLeft(size)); + builder.Append("".PadLeft(size)); } else if (types[i] == ColumnType.Numeric) { - bldr.Append(item.ToString()!.PadLeft(size)); + builder.Append(item.ToString()!.PadLeft(size)); } else if (types[i] == ColumnType.Text) { - bldr.Append(item.ToString()!.PadRight(size)); + builder.Append(item.ToString()!.PadRight(size)); } else { throw new InvalidOperationException("Unexpected state"); } - bldr.Append(" "); + builder.Append(' '); if (i == row.Count - 1) { // Add right border for last column - bldr.Append("|"); + builder.Append('|'); } } - bldr.Append('\n'); + builder.Append('\n'); if (rowNum == 0) { - AppendLine(bldr, sizes); + AppendLine(builder, sizes); } } - AppendLine(bldr, sizes); + AppendLine(builder, sizes); - return bldr.ToString(); + return builder.ToString(); } - private static void AppendLine(StringBuilder bldr, List sizes) + private static void AppendLine(StringBuilder builder, IReadOnlyList sizes) { - bldr.Append('o'); + builder.Append('o'); - for (int i = 0; i < sizes.Count; i++) + foreach (var i in sizes) { - bldr.Append(new string('-', sizes[i] + 2)); - bldr.Append('o'); + builder.Append(new string('-', i + 2)); + builder.Append('o'); } - bldr.Append('\n'); + builder.Append('\n'); } - private static List MaxLengthInEachColumn(List> rows) + private static List MaxLengthInEachColumn(IReadOnlyList> rows) { var sizes = new List(); //Start from second row to skip the header - for (int i = 0; i < rows[1].Count; i++) + for (var i = 0; i < rows[1].Count; i++) { var max = rows.Max(row => row[i]?.ToString()?.Length ?? 0); sizes.Insert(i, max); @@ -99,11 +98,11 @@ private static List MaxLengthInEachColumn(List> rows) private static List GetColumnTypes(List> rows) { var types = new List(); - for (int i = 0; i < rows[1].Count; i++) + for (var i = 0; i < rows[1].Count; i++) { var isNumeric = rows.Skip(1).All(row => row[i]?.GetType()?.IsNumericType() ?? false); - var coltype = isNumeric ? ColumnType.Numeric : ColumnType.Text; - types.Insert(i, coltype); + var columnType = isNumeric ? ColumnType.Numeric : ColumnType.Text; + types.Insert(i, columnType); } return types; } @@ -138,7 +137,17 @@ private static bool IsNumericType(this Type type) return Nullable.GetUnderlyingType(type)!.IsNumericType(); } return false; + case TypeCode.Empty: + case TypeCode.DBNull: + case TypeCode.Boolean: + case TypeCode.Char: + case TypeCode.DateTime: + case TypeCode.String: + break; + default: + throw new ArgumentOutOfRangeException(); } + return false; } diff --git a/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/Extensions.cs b/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/Extensions.cs index 77df076b5..1e963c196 100644 --- a/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/Extensions.cs +++ b/src/Digdir.Tool.Dialogporten.SlackNotifier/Common/Extensions.cs @@ -28,7 +28,7 @@ public static string ToQueryLink(this AzureAlertDto azureAlertRequest) private static string RemoveQuery(string inputUrl) { - int index = inputUrl.IndexOf("q/"); + var index = inputUrl.IndexOf("q/", StringComparison.Ordinal); if (index >= 0) { @@ -37,4 +37,4 @@ private static string RemoveQuery(string inputUrl) return inputUrl; // "q/" not found, return the original URL } -} \ No newline at end of file +} diff --git a/src/Digdir.Tool.Dialogporten.SlackNotifier/Digdir.Tool.Dialogporten.SlackNotifier.csproj b/src/Digdir.Tool.Dialogporten.SlackNotifier/Digdir.Tool.Dialogporten.SlackNotifier.csproj index cdb6fb795..d6dde1ca0 100644 --- a/src/Digdir.Tool.Dialogporten.SlackNotifier/Digdir.Tool.Dialogporten.SlackNotifier.csproj +++ b/src/Digdir.Tool.Dialogporten.SlackNotifier/Digdir.Tool.Dialogporten.SlackNotifier.csproj @@ -1,33 +1,38 @@ - - net7.0 - v4 - Exe - enable - enable - dd6841cd-1cfd-4f1c-a63e-edc687bff657 - - - - - - - - - - - PreserveNewest - - - PreserveNewest - Never - - - PreserveNewest - Never - - - - - - \ No newline at end of file + + + + + + + net7.0 + v4 + Exe + enable + enable + dd6841cd-1cfd-4f1c-a63e-edc687bff657 + + + + + + + + + + + PreserveNewest + + + PreserveNewest + Never + + + PreserveNewest + Never + + + + + + diff --git a/src/Digdir.Tool.Dialogporten.SlackNotifier/Features/AzureAlertToSlackForwarder/ForewardAlertToSlack.cs b/src/Digdir.Tool.Dialogporten.SlackNotifier/Features/AzureAlertToSlackForwarder/ForewardAlertToSlack.cs index 8f2c44114..da084a699 100644 --- a/src/Digdir.Tool.Dialogporten.SlackNotifier/Features/AzureAlertToSlackForwarder/ForewardAlertToSlack.cs +++ b/src/Digdir.Tool.Dialogporten.SlackNotifier/Features/AzureAlertToSlackForwarder/ForewardAlertToSlack.cs @@ -1,4 +1,3 @@ -using System.Net.Http.Json; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using System.Net; diff --git a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/.editorconfig b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/.editorconfig new file mode 100644 index 000000000..ef0ff3386 --- /dev/null +++ b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/.editorconfig @@ -0,0 +1,4 @@ +[*] + +# CA1707: Identifiers should not contain underscores +dotnet_diagnostic.CA1707.severity = none diff --git a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/ApplicationCollectionFixture.cs b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/ApplicationCollectionFixture.cs index 3b2e6aa45..0d4c07be0 100644 --- a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/ApplicationCollectionFixture.cs +++ b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/ApplicationCollectionFixture.cs @@ -2,7 +2,7 @@ public abstract class ApplicationCollectionFixture : IAsyncLifetime { - protected readonly DialogApplication Application; + protected DialogApplication Application { get; } protected ApplicationCollectionFixture(DialogApplication application) { diff --git a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/DialogApplication.cs b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/DialogApplication.cs index bf0045a4f..5f002b266 100644 --- a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/DialogApplication.cs +++ b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Common/DialogApplication.cs @@ -1,4 +1,5 @@ -using Digdir.Domain.Dialogporten.Application.Externals; +using System.Collections.ObjectModel; +using Digdir.Domain.Dialogporten.Application.Externals; using Digdir.Domain.Dialogporten.Infrastructure; using Digdir.Domain.Dialogporten.Infrastructure.Persistence; using Digdir.Library.Entity.Abstractions.Features.Lookup; @@ -11,6 +12,7 @@ using Npgsql; using NSubstitute; using Respawn; +using Respawn.Graph; using Testcontainers.PostgreSql; namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Common; @@ -84,13 +86,14 @@ private async Task BuildRespawnState() }); } - private IEnumerable GetLookupTables() + private ReadOnlyCollection GetLookupTables() { using var scope = _rootProvider.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); return db.Model.GetEntityTypes() .Where(x => typeof(ILookupEntity).IsAssignableFrom(x.ClrType)) .Select(x => new Respawn.Graph.Table(x.GetTableName()!)) - .ToList(); + .ToList() + .AsReadOnly(); } } diff --git a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Digdir.Domain.Dialogporten.Application.Integration.Tests.csproj b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Digdir.Domain.Dialogporten.Application.Integration.Tests.csproj index 72a793823..4739f9e44 100644 --- a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Digdir.Domain.Dialogporten.Application.Integration.Tests.csproj +++ b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Digdir.Domain.Dialogporten.Application.Integration.Tests.csproj @@ -1,34 +1,34 @@ - - net7.0 - enable - enable + + net7.0 + enable + enable - false - + false + - - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + - - - - + + + + diff --git a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Commands/CreateDialogTests.cs b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Commands/CreateDialogTests.cs index 71f4678e2..0238a4197 100644 --- a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Commands/CreateDialogTests.cs +++ b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Commands/CreateDialogTests.cs @@ -47,7 +47,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() Id = expectedDialogId, ServiceResource = new("urn:altinn:resource:example_dialog_service"), Party = "org:991825827", - Status = DialogStatus.Enum.InProgress, + Status = DialogStatus.Values.InProgress, ExtendedStatus = "SKE-ABC", //DueAt = new(2022, 12, 01), //ExpiresAt = new(2023, 12, 01), @@ -66,7 +66,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() { new () { - ConsumerType = DialogElementUrlConsumerType.Enum.Gui, + ConsumerType = DialogElementUrlConsumerType.Values.Gui, MimeType = "application/pdf", Url = new Uri("http://example.com/some/deep/link/to/attachment1.pdf") } @@ -82,7 +82,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() { new () { - ConsumerType = DialogElementUrlConsumerType.Enum.Api, + ConsumerType = DialogElementUrlConsumerType.Values.Api, MimeType = "application/xml", Url = new Uri("http://example.com/some/deep/link/to/attachment1.xml") } @@ -93,19 +93,19 @@ public async Task Create_CreateDialog_WhenDataIsValid() { new() { Action = "open", - Priority = DialogGuiActionPriority.Enum.Primary, + Priority = DialogGuiActionPriority.Values.Primary, Title = new() { new() { CultureCode = "nb_NO", Value = "Åpne i dialogtjeneste" } }, Url = new("https://example.com/some/deep/link/to/dialogs/123456789")}, new() { Action = "confirm", - Priority = DialogGuiActionPriority.Enum.Secondary, + Priority = DialogGuiActionPriority.Values.Secondary, Title = new() { new() { CultureCode = "nb_NO", Value = "Bekreft mottatt" } }, Url = new("https://example.com/some/deep/link/to/dialogs/123456789/confirmReceived"), AuthorizationAttribute = "somesubresource", IsBackChannel = true}, new() { Action = "delete", - Priority = DialogGuiActionPriority.Enum.Tertiary, + Priority = DialogGuiActionPriority.Values.Tertiary, Title = new() { new() { CultureCode = "nb_NO", Value = "Avbryt" } }, Url = new("https://example.com/some/deep/link/to/dialogs/123456789/confirmReceived"), IsDeleteAction = true} @@ -117,7 +117,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789"), - HttpMethod = HttpVerb.Enum.GET, + HttpMethod = HttpVerb.Values.GET, ResponseSchema = new("https://schemas.altinn.no/dialogs/v1/dialogs.json"), DocumentationUrl = new("https://api-docs.example.com/dialogservice/open-action") }, @@ -128,7 +128,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789/confirmReceived"), - HttpMethod = HttpVerb.Enum.POST, + HttpMethod = HttpVerb.Values.POST, DocumentationUrl = new("https://api-docs.example.com/dialogservice/confirm-action") }, } @@ -138,7 +138,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789"), - HttpMethod = HttpVerb.Enum.POST, + HttpMethod = HttpVerb.Values.POST, RequestSchema = new("https://schemas.example.com/dialogservice/v1/dialogservice.json"), ResponseSchema = new("https://schemas.altinn.no/dialogs/v1/dialogs.json") }, @@ -149,7 +149,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789"), - HttpMethod = HttpVerb.Enum.DELETE + HttpMethod = HttpVerb.Values.DELETE }, } }, @@ -160,7 +160,7 @@ public async Task Create_CreateDialog_WhenDataIsValid() { Id = Guid.NewGuid(), //CreatedAt = DateTimeOffset.UtcNow, - Type = DialogActivityType.Enum.Submission, + Type = DialogActivityType.Values.Submission, PerformedBy = new() { new() { CultureCode = "nb_NO", Value = "person:12018212345" } }, ExtendedType = new Uri("SKE:1234-received-precheck-ok"), Description = new() { new() { CultureCode = "nb_NO", Value = "Innsending er mottatt og sendt til behandling" } }, diff --git a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/GetDialogTests.cs b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/GetDialogTests.cs index fcba8b2ff..6625f7763 100644 --- a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/GetDialogTests.cs +++ b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/GetDialogTests.cs @@ -26,7 +26,7 @@ public async Task Get_ReturnsSimpleDialog_WhenDialogExists() Id = Guid.NewGuid(), ServiceResource = new("urn:altinn:resource:example_dialog_service"), Party = "org:991825827", - Status = DialogStatus.Enum.InProgress + Status = DialogStatus.Values.InProgress }; var createCommandResponse = await Application.Send(createDialogCommand); @@ -50,7 +50,7 @@ public async Task Get_ReturnsDialog_WhenDialogExists() Id = Guid.NewGuid(), ServiceResource = new("urn:altinn:resource:example_dialog_service"), Party = "org:991825827", - Status = DialogStatus.Enum.InProgress, + Status = DialogStatus.Values.InProgress, ExtendedStatus = "SKE-ABC", //DueAt = new(new DateTime(2022, 12, 01), TimeSpan.Zero), //ExpiresAt = new(new DateTime(2022, 12, 01), TimeSpan.Zero), @@ -70,7 +70,7 @@ public async Task Get_ReturnsDialog_WhenDialogExists() { new () { - ConsumerType = DialogElementUrlConsumerType.Enum.Gui, + ConsumerType = DialogElementUrlConsumerType.Values.Gui, MimeType = "application/pdf", Url = new Uri("http://example.com/some/deep/link/to/attachment1.pdf") } @@ -81,19 +81,19 @@ public async Task Get_ReturnsDialog_WhenDialogExists() { new() { Action = "open", - Priority = DialogGuiActionPriority.Enum.Primary, + Priority = DialogGuiActionPriority.Values.Primary, Title = new() { new() { CultureCode = "nb_NO", Value = "Åpne i dialogtjeneste" } }, Url = new("https://example.com/some/deep/link/to/dialogs/123456789")}, new() { Action = "confirm", - Priority = DialogGuiActionPriority.Enum.Secondary, + Priority = DialogGuiActionPriority.Values.Secondary, Title = new() { new() { CultureCode = "nb_NO", Value = "Bekreft mottatt" } }, Url = new("https://example.com/some/deep/link/to/dialogs/123456789/confirmReceived"), AuthorizationAttribute = "somesubresource", IsBackChannel = true}, new() { Action = "delete", - Priority = DialogGuiActionPriority.Enum.Tertiary, + Priority = DialogGuiActionPriority.Values.Tertiary, Title = new() { new() { CultureCode = "nb_NO", Value = "Avbryt" } }, Url = new("https://example.com/some/deep/link/to/dialogs/123456789/confirmReceived"), IsDeleteAction = true} @@ -105,7 +105,7 @@ public async Task Get_ReturnsDialog_WhenDialogExists() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789"), - HttpMethod = HttpVerb.Enum.GET, + HttpMethod = HttpVerb.Values.GET, ResponseSchema = new("https://schemas.altinn.no/dialogs/v1/dialogs.json"), DocumentationUrl = new("https://api-docs.example.com/dialogservice/open-action") }, @@ -116,7 +116,7 @@ public async Task Get_ReturnsDialog_WhenDialogExists() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789/confirmReceived"), - HttpMethod = HttpVerb.Enum.POST, + HttpMethod = HttpVerb.Values.POST, DocumentationUrl = new("https://api-docs.example.com/dialogservice/confirm-action") }, } @@ -126,7 +126,7 @@ public async Task Get_ReturnsDialog_WhenDialogExists() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789"), - HttpMethod = HttpVerb.Enum.POST, + HttpMethod = HttpVerb.Values.POST, RequestSchema = new("https://schemas.example.com/dialogservice/v1/dialogservice.json"), ResponseSchema = new("https://schemas.altinn.no/dialogs/v1/dialogs.json") }, @@ -137,7 +137,7 @@ public async Task Get_ReturnsDialog_WhenDialogExists() Endpoints = new() { new() { Url = new("https://example.com/api/dialogs/123456789"), - HttpMethod = HttpVerb.Enum.DELETE + HttpMethod = HttpVerb.Values.DELETE }, } }, @@ -148,7 +148,7 @@ public async Task Get_ReturnsDialog_WhenDialogExists() { Id = Guid.NewGuid(), //CreatedAt = DateTimeOffset.UtcNow, - Type = DialogActivityType.Enum.Submission, + Type = DialogActivityType.Values.Submission, PerformedBy = new() { new() { CultureCode = "nb_NO", Value = "Et navn" } }, ExtendedType = new Uri("SKE:1234-received-precheck-ok"), Description = new() { new() { CultureCode = "nb_NO", Value = "Innsending er mottatt og sendt til behandling" } }, diff --git a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/ListDialogTests.cs b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/SearchDialogTests.cs similarity index 64% rename from tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/ListDialogTests.cs rename to tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/SearchDialogTests.cs index 40c20cefc..79c46b791 100644 --- a/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/ListDialogTests.cs +++ b/tests/Digdir.Domain.Dialogporten.Application.Integration.Tests/Features/V1/Dialogs/Queries/SearchDialogTests.cs @@ -3,9 +3,9 @@ namespace Digdir.Domain.Dialogporten.Application.Integration.Tests.Features.V1.Dialogs.Queries; [Collection(nameof(DialogCqrsCollectionFixture))] -public class ListDialogTests : ApplicationCollectionFixture +public class SearchDialogTests : ApplicationCollectionFixture { - public ListDialogTests(DialogApplication application) : base(application) + public SearchDialogTests(DialogApplication application) : base(application) { } // TODO: Add tests diff --git a/tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests.csproj b/tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests.csproj index 20e82c1ad..a4b4877a0 100644 --- a/tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests.csproj +++ b/tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests/Digdir.Domain.Dialogporten.Infrastructure.Unit.Tests.csproj @@ -1,28 +1,27 @@ - - net7.0 - enable - enable + + net7.0 + enable + enable + false + - false - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - + + +