diff --git a/AccountDownloaderLibrary/Implementations/CloudAccountDataStore.cs b/AccountDownloaderLibrary/Implementations/CloudAccountDataStore.cs index 3ba6b82..2c5bb91 100644 --- a/AccountDownloaderLibrary/Implementations/CloudAccountDataStore.cs +++ b/AccountDownloaderLibrary/Implementations/CloudAccountDataStore.cs @@ -1,6 +1,6 @@ -using System.Net; -using AccountDownloaderLibrary.Implementations; +using AccountDownloaderLibrary.Implementations; using AccountDownloaderLibrary.Mime; +using AccountDownloaderLibrary.Models; using CloudX.Shared; using ILogger = Microsoft.Extensions.Logging.ILogger; @@ -146,7 +146,7 @@ public virtual async Task GetRecord(string ownerId, string recordId) public virtual async IAsyncEnumerable> GetRecords(string ownerId, DateTime? from) { - var searchParams = new SearchParameters + var searchParams = new AccountDownloaderSearchParameters { ByOwner = ownerId, Private = true, diff --git a/AccountDownloaderLibrary/Implementations/PaginatedRecordSearch.cs b/AccountDownloaderLibrary/Implementations/PaginatedRecordSearch.cs index b64d289..19dd60c 100644 --- a/AccountDownloaderLibrary/Implementations/PaginatedRecordSearch.cs +++ b/AccountDownloaderLibrary/Implementations/PaginatedRecordSearch.cs @@ -1,28 +1,35 @@ -using CloudX.Shared; +using AccountDownloaderLibrary.Models; +using CloudX.Shared; namespace AccountDownloaderLibrary.Implementations; public class PaginatedRecordSearch where R : class, IRecord, new() { - private SearchParameters searchParameters; + private AccountDownloaderSearchParameters searchParameters; private CloudXInterface cloud; public bool HasMoreResults { get; private set; } public int Offset { get; private set; } = 0; - public PaginatedRecordSearch(SearchParameters searchParameters, CloudXInterface cloud) + public PaginatedRecordSearch(AccountDownloaderSearchParameters searchParameters, CloudXInterface cloud) { this.searchParameters = searchParameters; this.cloud = cloud; HasMoreResults = true; } + public Task>> FindRecords(AccountDownloaderSearchParameters search) + { + return cloud.POST>("api/records/pagedSearch", search); + } + public async Task> Next() { searchParameters.Offset = Offset; searchParameters.Count = searchParameters.Count; - CloudResult> cloudResult = await cloud.FindRecords(searchParameters).ConfigureAwait(continueOnCapturedContext: false); + searchParameters.OnlyFeatured = null; + CloudResult> cloudResult = await FindRecords(searchParameters).ConfigureAwait(continueOnCapturedContext: false); if (cloudResult.IsOK) { Offset += searchParameters.Count; diff --git a/AccountDownloaderLibrary/Models/AccountDownloaderSearchParameters.cs b/AccountDownloaderLibrary/Models/AccountDownloaderSearchParameters.cs new file mode 100644 index 0000000..54edc82 --- /dev/null +++ b/AccountDownloaderLibrary/Models/AccountDownloaderSearchParameters.cs @@ -0,0 +1,21 @@ +using CloudX.Shared; +using Newtonsoft.Json; +using System.Text.Json.Serialization; + +namespace AccountDownloaderLibrary.Models; + +/** + * CloudX will filter on OnlyFeatured defaulting it to false, even if the user hasn't specified their preference. + * + * This is rather silly. So we extend the class and re-define it as a nullable. This allows it to be ignored when sent to the cloud. + * + * We'll have to log this as a bug for Neos to fix in CloudX too. + */ + +[JsonObject(MemberSerialization = MemberSerialization.OptIn)] +public class AccountDownloaderSearchParameters : SearchParameters +{ + [JsonProperty(PropertyName = "onlyFeatured", NullValueHandling = NullValueHandling.Ignore)] + [JsonPropertyName("onlyFeatured")] + public new bool? OnlyFeatured { get; set; } = null; +} diff --git a/AcountDownloaderLibrary.Tests/AcountDownloaderLibrary.Tests.csproj b/AcountDownloaderLibrary.Tests/AcountDownloaderLibrary.Tests.csproj index 8a938f1..7ba9487 100644 --- a/AcountDownloaderLibrary.Tests/AcountDownloaderLibrary.Tests.csproj +++ b/AcountDownloaderLibrary.Tests/AcountDownloaderLibrary.Tests.csproj @@ -1,4 +1,4 @@ - + net7.0 @@ -14,6 +14,7 @@ + diff --git a/AcountDownloaderLibrary.Tests/SearchParameterTests.cs b/AcountDownloaderLibrary.Tests/SearchParameterTests.cs new file mode 100644 index 0000000..d579f57 --- /dev/null +++ b/AcountDownloaderLibrary.Tests/SearchParameterTests.cs @@ -0,0 +1,51 @@ +using AccountDownloaderLibrary.Models; +using Newtonsoft.Json; + +namespace AcountDownloaderLibrary.Tests; + + +[TestClass] +public class SearchParameterTests +{ + [TestMethod] + public void TestFeaturedNullNewtonSoft() + { + var ap = new AccountDownloaderSearchParameters(); + + ap.OnlyFeatured = null; + + var jsonA = JsonConvert.SerializeObject(ap); + var deSerialize = JsonConvert.DeserializeObject(jsonA); + + Assert.IsNull(deSerialize?.OnlyFeatured, "OnlyFeatured should only be present if the user included it"); + + ap.OnlyFeatured = false; + jsonA = JsonConvert.SerializeObject(ap); + + deSerialize = JsonConvert.DeserializeObject(jsonA); + + Assert.IsFalse(deSerialize?.OnlyFeatured, "OnlyFeatured was included and should be false"); + + } + + [TestMethod] + public void TestFeaturedNullNET() + { + var ap = new AccountDownloaderSearchParameters(); + + ap.OnlyFeatured = null; + + var jsonA = System.Text.Json.JsonSerializer.Serialize(ap); + var deSerialize = System.Text.Json.JsonSerializer.Deserialize(jsonA); + + Assert.IsNull(deSerialize?.OnlyFeatured, "OnlyFeatured should only be present if the user included it"); + + ap.OnlyFeatured = false; + jsonA = JsonConvert.SerializeObject(ap); + + deSerialize = JsonConvert.DeserializeObject(jsonA); + + Assert.IsFalse(deSerialize?.OnlyFeatured, "OnlyFeatured was included and should be false"); + + } +}