From 936c40e05019f3f61ad70a1ea1472de6d7099094 Mon Sep 17 00:00:00 2001 From: Jan Cerman Date: Fri, 7 Jun 2024 17:00:26 +0200 Subject: [PATCH] CTC-2299 Extend filtering examples on linked items --- ...filtering_get_items_by_linked_item.graphql | 26 ++++++++++++++++--- .../filtering_get_items_by_linked_item.java | 20 +++++++++++--- .../filtering_get_items_by_linked_item.js | 16 +++++++++--- .../filtering_get_items_by_linked_item.cs | 16 +++++++++--- .../filtering_get_items_by_linked_item.php | 16 +++++++++--- .../filtering_get_items_by_linked_item.curl | 16 +++++++++--- .../filtering_get_items_by_linked_item.rb | 12 ++++++--- .../filtering_get_items_by_linked_item.ts | 16 +++++++++--- 8 files changed, 113 insertions(+), 25 deletions(-) diff --git a/graphql/filter-content/filtering_get_items_by_linked_item.graphql b/graphql/filter-content/filtering_get_items_by_linked_item.graphql index 45c34217..c1ff40d3 100644 --- a/graphql/filter-content/filtering_get_items_by_linked_item.graphql +++ b/graphql/filter-content/filtering_get_items_by_linked_item.graphql @@ -1,13 +1,13 @@ -# Gets items attributed to Jane. -query GetArticlesByAuthor { - article_All(where: {author: {containsAll: ["jane_doe"]}}) { +// # Gets a list of items where the 'my_page' item is used in the 'navigation' element. +query GetItemsByUsedIn { + page_All(where: {navigation: {containsAll: ["my_page"]}}) { items { title } } } -# Gets items attributed to at least Jane, John, or both. +# Gets items linked to at least Jane, John, or both. query GetArticlesByOneOfAuthors { article_All(where: {author: {containsAny: ["jane_doe", "john_wick"]}}) { items { @@ -15,3 +15,21 @@ query GetArticlesByOneOfAuthors { } } } + +# Gets pages linking travel insurance as their subpage. +query GetArticlesTaggedWithATerm { + article_All(where: {subpages: {containsAll: ["travel_insurance"]}}) { + items { + title + } + } +} + +# Gets pages linking at least travel insurance, car insurance, or both as their subpage. +query GetArticlesTaggedWithTerms { + article_All(where: {subpages: {containsAny: ["travel_insurance", "car_insurance"]}}) { + items { + title + } + } +} \ No newline at end of file diff --git a/java/filter-content/filtering_get_items_by_linked_item.java b/java/filter-content/filtering_get_items_by_linked_item.java index e1256428..e2e8d16b 100644 --- a/java/filter-content/filtering_get_items_by_linked_item.java +++ b/java/filter-content/filtering_get_items_by_linked_item.java @@ -1,14 +1,28 @@ -// Gets items attributed to Jane. +// Gets a list of items where the 'my_page' item is used in the 'navigation' element. CompletionStage items = client.getItems( DeliveryParameterBuilder.params() - .filterContains("elements.author", "jane_doe") + .filterContains("elements.navigation", "my_page") .build() ); -// Gets items attributed to at least Jane, John, or both. +// Gets items linked to at least Jane, John, or both. CompletionStage items = client.getItems( DeliveryParameterBuilder.params() .filterAny("elements.author", "jane_doe", "john_wick") .build() ); + +// Gets pages linking travel insurance as their subpage. +CompletionStage items = client.getItems( + DeliveryParameterBuilder.params() + .filterContains("elements.subpages", "travel_insurance") + .build() +); + +// Gets pages linking at least travel insurance, car insurance, or both as their subpage. +CompletionStage items = client.getItems( + DeliveryParameterBuilder.params() + .filterAny("elements.subpages", "travel_insurance", "car_insurance") + .build() +); diff --git a/js/filter-content/filtering_get_items_by_linked_item.js b/js/filter-content/filtering_get_items_by_linked_item.js index 2973808c..1e5f7ce0 100644 --- a/js/filter-content/filtering_get_items_by_linked_item.js +++ b/js/filter-content/filtering_get_items_by_linked_item.js @@ -1,9 +1,19 @@ -// Gets items attributed to Jane. +// Gets a list of items where the 'my_page' item is used in the 'navigation' element. const response = await deliveryClient.items() - .containsFilter('elements.author', ['jane_doe']) + .containsFilter('elements.navigation', ['my_page']) .toPromise(); -// Gets items attributed to at least Jane, John, or both. +// Gets items linked to at least Jane, John, or both. const response = await deliveryClient.items() .anyFilter('elements.author', ['jane_doe', 'john_wick']) .toPromise(); + +// Gets pages linking travel insurance as their subpage. +const response = await deliveryClient.items() + .containsFilter('elements.subpages', ['travel_insurance']) + .toPromise(); + +// Gets pages linking at least travel insurance, car insurance, or both as their subpage. +const response = await deliveryClient.items() + .anyFilter('elements.subpages', ['travel_insurance', 'car_insurance']) + .toPromise(); diff --git a/net/filter-content/filtering_get_items_by_linked_item.cs b/net/filter-content/filtering_get_items_by_linked_item.cs index 074266d1..1b4e304d 100644 --- a/net/filter-content/filtering_get_items_by_linked_item.cs +++ b/net/filter-content/filtering_get_items_by_linked_item.cs @@ -1,9 +1,19 @@ -// Gets items attributed to Jane. +// Gets a list of items where the 'my_page' item is used in the 'navigation' element. IDeliveryItemListingResponse response = await deliveryClient.GetItemsAsync( - new ContainsFilter("elements.author", "jane_doe") + new ContainsFilter("elements.navigation", "my_page") ); -// Gets items attributed to at least Jane, John, or both. +// Gets items linked to at least Jane, John, or both. IDeliveryItemListingResponse response = await deliveryClient.GetItemsAsync( new AnyFilter("elements.author", "jane_doe", "john_wick") ); + +// Gets pages linking travel insurance as their subpage. +IDeliveryItemListingResponse response = await deliveryClient.GetItemsAsync( + new ContainsFilter("elements.subpages", "travel_insurance") +); + +// Gets pages linking at least travel insurance, car insurance, or both as their subpage. +IDeliveryItemListingResponse response = await deliveryClient.GetItemsAsync( + new AnyFilter("elements.subpages", "travel_insurance", "car_insurance") +); \ No newline at end of file diff --git a/php/filter-content/filtering_get_items_by_linked_item.php b/php/filter-content/filtering_get_items_by_linked_item.php index a90438b7..5a66396e 100644 --- a/php/filter-content/filtering_get_items_by_linked_item.php +++ b/php/filter-content/filtering_get_items_by_linked_item.php @@ -1,9 +1,19 @@ getItems((new QueryParams()) - ->contains('elements.author', 'jane_doe')); + ->contains('elements.navigation', 'my_page')); -// Gets items attributed to at least Jane, John, or both. +// Gets items linked to at least Jane, John, or both. $items = $client->getItems((new QueryParams()) ->any('elements.author', ['jane_doe','john_wick'])); +?> + +getItems((new QueryParams()) + ->contains('elements.subpages', 'travel_insurance')); + +// Gets pages linking at least travel insurance, car insurance, or both as their subpage. +$items = $client->getItems((new QueryParams()) + ->any('elements.subpages', ['travel_insurance','car_insurance'])); ?> \ No newline at end of file diff --git a/rest/filter-content/filtering_get_items_by_linked_item.curl b/rest/filter-content/filtering_get_items_by_linked_item.curl index 535bb0e1..cd9439ad 100644 --- a/rest/filter-content/filtering_get_items_by_linked_item.curl +++ b/rest/filter-content/filtering_get_items_by_linked_item.curl @@ -1,9 +1,19 @@ -# Gets items attributed to Jane. +# Gets a list of items where the 'my_page' item is used in the 'navigation' element. curl --request GET \ - --url 'https://deliver.kontent.ai//items?elements.author[contains]=jane_doe' \ + --url 'https://deliver.kontent.ai//items?elements.navigation[contains]=my_page' \ --header 'content-type: application/json' -# Gets items attributed to at least Jane, John, or both. +# Gets items linked to at least Jane, John, or both. curl --request GET \ --url 'https://deliver.kontent.ai//items?elements.author[any]=jane_doe,john_wick' \ --header 'content-type: application/json' + +# Gets pages linking travel insurance as their subpage. +curl --request GET \ + --url 'https://deliver.kontent.ai//items?elements.subpages[contains]=travel_insurance' \ + --header 'content-type: application/json' + +# Gets pages linking at least travel insurance, car insurance, or both as their subpage. +curl --request GET \ + --url 'https://deliver.kontent.ai//items?elements.subpages[any]=travel_insurance,car_insurance' \ + --header 'content-type: application/json' \ No newline at end of file diff --git a/ruby/filter-content/filtering_get_items_by_linked_item.rb b/ruby/filter-content/filtering_get_items_by_linked_item.rb index 8fe54005..67c0b398 100644 --- a/ruby/filter-content/filtering_get_items_by_linked_item.rb +++ b/ruby/filter-content/filtering_get_items_by_linked_item.rb @@ -1,5 +1,11 @@ -# Gets items attributed to Jane. -delivery_client.items('elements.author'.contains('jane_doe')) +# Gets a list of items where the 'my_page' item is used in the 'navigation' element. +delivery_client.items('elements.navigation'.contains('my_page')) -# Gets items attributed to at least Jane, John, or both. +# Gets items linked to at least Jane, John, or both. delivery_client.items('elements.author'.any('jane_doe', 'john_wick')) + +# Gets pages linking travel insurance as their subpage. +delivery_client.items('elements.subpages'.contains('travel_insurance')) + +# Gets pages linking at least travel insurance, car insurance, or both as their subpage. +delivery_client.items('elements.subpages'.any('travel_insurance', 'car_insurance')) \ No newline at end of file diff --git a/ts/filter-content/filtering_get_items_by_linked_item.ts b/ts/filter-content/filtering_get_items_by_linked_item.ts index c93c7c5d..f12e8eef 100644 --- a/ts/filter-content/filtering_get_items_by_linked_item.ts +++ b/ts/filter-content/filtering_get_items_by_linked_item.ts @@ -1,9 +1,19 @@ -// Gets items attributed to Jane. +// # Gets a list of items where the 'my_page' item is used in the 'navigation' element. const response = await deliveryClient.items() - .containsFilter('elements.author', ['jane_doe']) + .containsFilter('elements.navigation', ['my_page']) .toPromise(); -// Gets items attributed to at least Jane, John, or both. +// Gets items linked to at least Jane, John, or both. const response = await deliveryClient.items() .anyFilter('elements.author', ['jane_doe', 'john_wick']) .toPromise(); + + // Gets pages linking travel insurance as their subpage. +const response = await deliveryClient.items() +.containsFilter('elements.subpages', ['travel_insurance']) +.toPromise(); + +// Gets pages linking at least travel insurance, car insurance, or both as their subpage. +const response = await deliveryClient.items() +.anyFilter('elements.subpages', ['travel_insurance', 'car_insurance']) +.toPromise(); \ No newline at end of file