diff --git a/.gitignore b/.gitignore index d02e18d..0555a55 100644 --- a/.gitignore +++ b/.gitignore @@ -374,3 +374,4 @@ FodyWeavers.xsd /Tests.Contentful/appsettings.json /Tests.Contentful/TestFiles/Input/Product Acceleration_en-US-en_us-de-QC-C.html /Tests.Contentful/appsettings.json +/Tests.Contentful/appsettings.json diff --git a/Apps.Contentful/Actions/EntryActions.cs b/Apps.Contentful/Actions/EntryActions.cs index 99f213b..64fda3e 100644 --- a/Apps.Contentful/Actions/EntryActions.cs +++ b/Apps.Contentful/Actions/EntryActions.cs @@ -108,16 +108,6 @@ await client.Paginate>( entries = entries.Where(e => e.SystemProperties.PublishedVersion.HasValue == false); } - if (request.Tags is not null && request.Tags.Any()) - { - entries = entries.Where(e => e.Metadata.Tags.Any(t => request.Tags.Contains(t.Sys.Id))); - } - - if (request.ExcludeTags is not null && request.ExcludeTags.Any()) - { - entries = entries.Where(e => e.Metadata.Tags.All(t => !request.ExcludeTags.Contains(t.Sys.Id))); - } - var entriesResponse = entries.Select(e => new EntryEntity(e)).ToArray(); return new ListEntriesResponse(entriesResponse, entriesResponse.Length); } @@ -1234,6 +1224,16 @@ private static void ApplyListEntriesRequestFilters(NameValueCollection queryStri { queryString.Add("query", request.SearchTerm); } + + if (request.Tags is not null && request.Tags.Any()) + { + queryString.Add("metadata.tags.sys.id[in]", string.Join(",", request.Tags)); + } + + if (request.ExcludeTags is not null && request.ExcludeTags.Any()) + { + queryString.Add("metadata.tags.sys.id[nin]", string.Join(",", request.ExcludeTags)); + } } private IEnumerable ExtractReferencedIds( diff --git a/Apps.Contentful/Apps.Contentful.csproj b/Apps.Contentful/Apps.Contentful.csproj index 11a580d..8c4f621 100644 --- a/Apps.Contentful/Apps.Contentful.csproj +++ b/Apps.Contentful/Apps.Contentful.csproj @@ -6,7 +6,7 @@ enable Contentful The headless content management system - 1.8.11 + 1.8.12 Apps.Contentful diff --git a/README.md b/README.md index 2be0e28..441d0b7 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Follow [this guide](https://www.contentful.com/help/working-with-translations/) ### Entries -- **Search entries** returns a list of entries. Optionally filter by content model, environment, tags and the last updated date. +- **Search entries** returns a list of entries. Optionally filter by content model, environment, tags, excluded tags and the last updated date. - **Search refereced entries** returns a list of all entries that are referenced by the specified entry. - **Search links to entry** returns a list of all entries that link to the specified entry. - **Find entry by field value** Given a field and a desired value for the field, the first matching entry will be returned. diff --git a/Tests.Contentful/EntryActionsTests.cs b/Tests.Contentful/EntryActionsTests.cs index 0502adc..4d7ad75 100644 --- a/Tests.Contentful/EntryActionsTests.cs +++ b/Tests.Contentful/EntryActionsTests.cs @@ -46,8 +46,7 @@ public async Task ListEntries_WithValidPublishedDateFilters_ShouldReturnFiltered var entryActions = new EntryActions(InvocationContext, FileManager); var listEntriesRequest = new ListEntriesRequest { - PublishedAfter = new DateTime(2025, 10, 01), - PublishedBefore = new DateTime(2025, 10, 04) + Tags = ["danDemo"], }; // Act @@ -56,7 +55,7 @@ public async Task ListEntries_WithValidPublishedDateFilters_ShouldReturnFiltered // Assert foreach (var entry in result.Entries) { - Console.WriteLine($"{entry.ContentId}"); + Console.WriteLine($"Id: {entry.ContentId} - Name: {entry.ContentTypeId}"); } IsNotNull(result); } diff --git a/Tests.Contentful/Tests.Contentful.csproj b/Tests.Contentful/Tests.Contentful.csproj index afb6ec2..2dfd680 100644 --- a/Tests.Contentful/Tests.Contentful.csproj +++ b/Tests.Contentful/Tests.Contentful.csproj @@ -33,6 +33,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest