Skip to content

Commit

Permalink
Fix RefDataMulti (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun authored Dec 22, 2023
1 parent 46f8096 commit 4b6b075
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 151 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v3.7.2
- *Fixed*: The `ReferenceDataMultiCollection` and `ReferenceDataMultiItem` have been replaced with the `ReferenceDataMultiDictionary` as existing resulted in an unintended format with which to return the data. This fix also removed the need for the `ReferenceDataMultiCollectionConverterFactory` as custom serialization for this is no longer required.

## v3.7.1
- *Fixed*: The `WebApi.PutWithResultAsync` methods that support `get` function parameter have had the result nullability corrected.
- *Fixed*: The `BidirectionalMapper<TFrom, TTo>` has been added to further simplify the specification of a bidirectional mapping capability.
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>3.7.1</Version>
<Version>3.7.2</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Package | Status | Source & documentation
`CoreEx.EntityFrameworkCore` | [![NuGet version](https://badge.fury.io/nu/CoreEx.EntityFrameworkCore.svg)](https://badge.fury.io/nu/CoreEx.EntityFrameworkCore) | [Link](./src/CoreEx.EntityFrameworkCore)
`CoreEx.FluentValidation` | [![NuGet version](https://badge.fury.io/nu/CoreEx.FluentValidation.svg)](https://badge.fury.io/nu/CoreEx.FluentValidation) | [Link](./src/CoreEx.FluentValidation)
`CoreEx.Newtonsoft` | [![NuGet version](https://badge.fury.io/nu/CoreEx.Newtonsoft.svg)](https://badge.fury.io/nu/CoreEx.Newtonsoft) | [Link](./src/CoreEx.Newtonsoft)
`CoreEx.OData` | [![NuGet version](https://badge.fury.io/nu/CoreEx.OData.svg)](https://badge.fury.io/nu/CoreEx.OData) | [Link](./src/CoreEx.OData)
`CoreEx.Solace` | [![NuGet version](https://badge.fury.io/nu/CoreEx.Solace.svg)](https://badge.fury.io/nu/CoreEx.Solace) | [Link](./src/CoreEx.Solace)
`CoreEx.Validation` | [![NuGet version](https://badge.fury.io/nu/CoreEx.Validation.svg)](https://badge.fury.io/nu/CoreEx.Validation) | [Link](./src/CoreEx.Validation)
-- | -- | --
Expand Down Expand Up @@ -59,8 +60,7 @@ These other _Avanade_ repositories leverage _CoreEx_:
Repo | Description
-|-
[Beef](https://github.com/Avanade/beef) | Code-generation capabilities to support the industrialization of API development leveraging `CoreEx` as the primary runtime framework (_Beef_ version `v5+`).
[DbEx](https://github.com/Avanade/dbex) | DbEx provides database extensions for DbUp-inspired database migrations.
[UnitTestEx](https://github.com/Avanade/unittestex) | Provides .NET testing extensions to the most popular testing frameworks (MSTest, NUnit and Xunit).
[DbEx](https://github.com/Avanade/dbex) | Provides database extensions for DbUp-inspired database migrations.
[NTangle](https://github.com/Avanade/ntangle) | Change Data Capture (CDC) code generation tool and runtime.

<br/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public Task<IActionResult> GenderGetAll([FromQuery] IEnumerable<string>? codes =
_webApi.GetAsync(Request, x => _orchestrator.GetWithFilterAsync<Gender>(codes, text, x.RequestOptions.IncludeInactive));

[HttpGet()]
[ProducesResponseType(typeof(IEnumerable<CoreEx.RefData.ReferenceDataMultiItem>), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ReferenceDataMultiDictionary), (int)HttpStatusCode.OK)]
[ApiExplorerSettings(IgnoreApi = true)]
public Task<IActionResult> GetNamed() => _webApi.GetAsync(Request, p => _orchestrator.GetNamedAsync(p.RequestOptions));
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static class ReferenceDataOrchestratorExtensions
/// <param name="orchestrator">The <see cref="ReferenceDataOrchestrator"/>.</param>
/// <param name="requestOptions">The <see cref="WebApiRequestOptions"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The <see cref="ReferenceDataMultiCollection"/>.</returns>
/// <returns>The <see cref="ReferenceDataMultiDictionary"/>.</returns>
/// <remarks>The reference data names and codes are specified as part of the query string. Either '<c>?names=RefA,RefB,RefX</c>' or <c>?RefA,RefB=CodeA,CodeB,RefX=CodeX</c> or any combination thereof.</remarks>
public static Task<ReferenceDataMultiCollection> GetNamedAsync(this ReferenceDataOrchestrator orchestrator, WebApiRequestOptions requestOptions, CancellationToken cancellationToken = default)
public static Task<ReferenceDataMultiDictionary> GetNamedAsync(this ReferenceDataOrchestrator orchestrator, WebApiRequestOptions requestOptions, CancellationToken cancellationToken = default)
{
var dict = new Dictionary<string, List<string>>();

Expand All @@ -32,7 +32,7 @@ public static Task<ReferenceDataMultiCollection> GetNamedAsync(this ReferenceDat
{
foreach (var v in SplitStringValues(q.Value.Where(x => !string.IsNullOrEmpty(x)).Distinct()!))
{
dict.TryAdd(v, new List<string>());
dict.TryAdd(v, []);
}
}
else
Expand Down
11 changes: 0 additions & 11 deletions src/CoreEx/RefData/ReferenceDataMultiCollection.cs

This file was deleted.

19 changes: 19 additions & 0 deletions src/CoreEx/RefData/ReferenceDataMultiDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Avanade. Licensed under the MIT License. See https://github.com/Avanade/CoreEx

using System;
using System.Collections.Generic;

namespace CoreEx.RefData
{
/// <summary>
/// Represents a dictionary where the key is the <see cref="IReferenceData"/> <see cref="Type"/> and the value is the corresponding <see cref="IReferenceData"/> items.
/// </summary>
/// <remarks>This is generally intended for the <see cref="ReferenceDataOrchestrator"/>.</remarks>
public class ReferenceDataMultiDictionary : Dictionary<string, IEnumerable<IReferenceData>>
{
/// <summary>
/// Initializes a new instance of the <see cref="ReferenceDataMultiDictionary"/> class.
/// </summary>
public ReferenceDataMultiDictionary() : base(StringComparer.OrdinalIgnoreCase) { }
}
}
34 changes: 0 additions & 34 deletions src/CoreEx/RefData/ReferenceDataMultiItem.cs

This file was deleted.

16 changes: 8 additions & 8 deletions src/CoreEx/RefData/ReferenceDataOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -521,19 +521,19 @@ public Task PrefetchAsync(IEnumerable<string> names, CancellationToken cancellat
/// <param name="names">The reference data names.</param>
/// <param name="includeInactive">Indicates whether to include inactive (<see cref="IReferenceData.IsActive"/> equal <c>false</c>) entries.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The <see cref="ReferenceDataMultiCollection"/>.</returns>
/// <returns>The <see cref="ReferenceDataMultiDictionary"/>.</returns>
/// <remarks>Will return an empty collection where no <paramref name="names"/> are specified.</remarks>
public async Task<ReferenceDataMultiCollection> GetNamedAsync(IEnumerable<string> names, bool includeInactive = false, CancellationToken cancellationToken = default)
public async Task<ReferenceDataMultiDictionary> GetNamedAsync(IEnumerable<string> names, bool includeInactive = false, CancellationToken cancellationToken = default)
{
var mc = new ReferenceDataMultiCollection();
var mc = new ReferenceDataMultiDictionary();

if (names != null)
{
await PrefetchAsync(names, cancellationToken).ConfigureAwait(false);

foreach (var name in names.Where(ContainsName).Distinct(StringComparer.OrdinalIgnoreCase))
{
mc.Add(new ReferenceDataMultiItem(_nameToType[name].Name, await GetWithFilterAsync(name, includeInactive: includeInactive, cancellationToken: cancellationToken).ConfigureAwait(false)));
mc.Add(_nameToType[name].Name, await GetWithFilterAsync(name, includeInactive: includeInactive, cancellationToken: cancellationToken).ConfigureAwait(false));
}
}

Expand All @@ -546,19 +546,19 @@ public async Task<ReferenceDataMultiCollection> GetNamedAsync(IEnumerable<string
/// <param name="namesAndCodes">The reference data names and related codes.</param>
/// <param name="includeInactive">Indicates whether to include inactive (<see cref="IReferenceData.IsActive"/> equal <c>false</c>) entries.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>The <see cref="ReferenceDataMultiCollection"/>.</returns>
/// <returns>The <see cref="ReferenceDataMultiDictionary"/>.</returns>
/// <remarks>Will return an empty collection where no <paramref name="namesAndCodes"/> are specified.</remarks>
public async Task<ReferenceDataMultiCollection> GetNamedAsync(IEnumerable<KeyValuePair<string, List<string>>> namesAndCodes, bool includeInactive = false, CancellationToken cancellationToken = default)
public async Task<ReferenceDataMultiDictionary> GetNamedAsync(IEnumerable<KeyValuePair<string, List<string>>> namesAndCodes, bool includeInactive = false, CancellationToken cancellationToken = default)
{
var mc = new ReferenceDataMultiCollection();
var mc = new ReferenceDataMultiDictionary();

if (namesAndCodes != null)
{
await PrefetchAsync(namesAndCodes.Select(x => x.Key).AsEnumerable(), cancellationToken).ConfigureAwait(false);

foreach (var kvp in namesAndCodes.Where(x => ContainsName(x.Key)))
{
mc.Add(new ReferenceDataMultiItem(_nameToType[kvp.Key].Name, await GetWithFilterAsync(kvp.Key, codes: kvp.Value, includeInactive: includeInactive, cancellationToken: cancellationToken).ConfigureAwait(false)));
mc.Add(_nameToType[kvp.Key].Name, await GetWithFilterAsync(kvp.Key, codes: kvp.Value, includeInactive: includeInactive, cancellationToken: cancellationToken).ConfigureAwait(false));
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/CoreEx/Text/Json/ReferenceDataContentJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace CoreEx.Text.Json
/// Provides the JSON Serialize and Deserialize implementation to allow <see cref="IReferenceData"/> types to serialize contents.
/// </summary>
/// <remarks>Generally, <see cref="IReferenceData"/> types will serialize the <see cref="IReferenceData.Code"/> as the value; this allows for full <see cref="IReferenceData"/> contents to be serialized.</remarks>
public class ReferenceDataContentJsonSerializer : JsonSerializer, IReferenceDataContentJsonSerializer
/// <param name="options">The <see cref="Stj.JsonSerializerOptions"/>. Defaults to <see cref="DefaultOptions"/>.</param>
public class ReferenceDataContentJsonSerializer(Stj.JsonSerializerOptions? options = null) : JsonSerializer(options ?? DefaultOptions), IReferenceDataContentJsonSerializer
{
/// <summary>
/// Gets or sets the default <see cref="Stj.JsonSerializerOptions"/> without <see cref="CollectionResultConverterFactory"/> to allow <see cref="IReferenceData"/> types to serialize contents.
Expand All @@ -22,7 +23,7 @@ public class ReferenceDataContentJsonSerializer : JsonSerializer, IReferenceData
/// <item><description><see cref="Stj.JsonSerializerOptions.WriteIndented"/> = <c>false</c></description></item>
/// <item><description><see cref="Stj.JsonSerializerOptions.DictionaryKeyPolicy"/> = <see cref="SubstituteNamingPolicy.Substitute"/>.</description></item>
/// <item><description><see cref="Stj.JsonSerializerOptions.PropertyNamingPolicy"/> = <see cref="SubstituteNamingPolicy.Substitute"/>.</description></item>
/// <item><description><see cref="Stj.JsonSerializerOptions.Converters"/> = <see cref="JsonStringEnumConverter"/>, <see cref="ExceptionConverterFactory"/> and <see cref="CollectionResultConverterFactory"/>.</description></item>
/// <item><description><see cref="Stj.JsonSerializerOptions.Converters"/> = <see cref="JsonStringEnumConverter"/>, <see cref="ExceptionConverterFactory"/>, <see cref="CollectionResultConverterFactory"/> and <see cref="ResultConverterFactory"/>.</description></item>
/// </list>
/// </remarks>
public static new Stj.JsonSerializerOptions DefaultOptions { get; set; } = new Stj.JsonSerializerOptions(Stj.JsonSerializerDefaults.Web)
Expand All @@ -31,13 +32,7 @@ public class ReferenceDataContentJsonSerializer : JsonSerializer, IReferenceData
WriteIndented = false,
DictionaryKeyPolicy = SubstituteNamingPolicy.Substitute,
PropertyNamingPolicy = SubstituteNamingPolicy.Substitute,
Converters = { new JsonStringEnumConverter(), new ExceptionConverterFactory(), new CollectionResultConverterFactory(), new ReferenceDataMultiCollectionConverterFactory(), new ResultConverterFactory() }
Converters = { new JsonStringEnumConverter(), new ExceptionConverterFactory(), new CollectionResultConverterFactory(), new ResultConverterFactory() }
};

/// <summary>
/// Initializes a new instance of the <see cref="JsonSerializer"/> class.
/// </summary>
/// <param name="options">The <see cref="Stj.JsonSerializerOptions"/>. Defaults to <see cref="DefaultOptions"/>.</param>
public ReferenceDataContentJsonSerializer(Stj.JsonSerializerOptions? options = null) : base(options ?? DefaultOptions) { }
}
}

This file was deleted.

Loading

0 comments on commit 4b6b075

Please sign in to comment.