From b34abf113b6c95a580f1beb1a58da2342bef0fdc Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 16 Oct 2024 16:15:31 +0530 Subject: [PATCH] Added Support for fetch Asset by Query --- CHANGELOG.md | 6 ++++++ Contentstack.Core.Tests/AssetTest.cs | 17 +++++++++++++++++ .../Internals/HttpRequestHandler.cs | 2 +- Contentstack.Core/Models/AssetLibrary.cs | 13 +++++++++++++ Directory.Build.props | 2 +- 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec2ed05..4d3d9b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### Version: 2.17.0 +#### Date: Oct-21-2024 + +##### Feat: +- Added support for fetch asset by Query + ### Version: 2.16.0 #### Date: Oct-11-2024 diff --git a/Contentstack.Core.Tests/AssetTest.cs b/Contentstack.Core.Tests/AssetTest.cs index 88bc5d4..a49aa6d 100644 --- a/Contentstack.Core.Tests/AssetTest.cs +++ b/Contentstack.Core.Tests/AssetTest.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using Newtonsoft.Json.Linq; + namespace Contentstack.Core.Tests { public class AssetTest @@ -121,6 +122,22 @@ public async Task FetchAssetsIncludeRelativeURL() } } + [Fact] + public async Task FetchAssetWithQuery() + { + JObject queryObject = new JObject + { + { "filename", "image3.png" } + }; + ContentstackCollection assets = await client.AssetLibrary().Query(queryObject).FetchAll(); + Assert.True(assets.Count() > 0); + foreach (Asset asset in assets) + { + Assert.DoesNotContain(asset.Url, "http"); + Assert.True(asset.FileName.Length > 0); + } + } + [Fact] public async Task FetchAssetCountAsync() { diff --git a/Contentstack.Core/Internals/HttpRequestHandler.cs b/Contentstack.Core/Internals/HttpRequestHandler.cs index 095ee04..86a180d 100644 --- a/Contentstack.Core/Internals/HttpRequestHandler.cs +++ b/Contentstack.Core/Internals/HttpRequestHandler.cs @@ -48,7 +48,7 @@ public async Task ProcessRequest(string Url, Dictionary var request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/json"; - request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.16.0"; + request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.17.0"; request.Timeout = timeout; if (proxy != null) diff --git a/Contentstack.Core/Models/AssetLibrary.cs b/Contentstack.Core/Models/AssetLibrary.cs index 8bfe118..2c7e88d 100644 --- a/Contentstack.Core/Models/AssetLibrary.cs +++ b/Contentstack.Core/Models/AssetLibrary.cs @@ -92,6 +92,18 @@ public async Task Count() return await Exec(); } + public AssetLibrary Query(JObject QueryObject) + { + try + { + UrlQueries.Add("query", QueryObject); + } + catch (Exception e) + { + throw new Exception(StackConstants.ErrorMessage_QueryFilterException, e); + } + return this; + } /// /// Include fallback locale publish content, if specified locale content is not publish. /// @@ -155,6 +167,7 @@ public AssetLibrary IncludeBranch() /// ContentstackCollection>Asset< contentstackCollection = await assetLibrary.FetchAll(); /// /// + /// Where function public AssetLibrary AddParam(string key, string value) { UrlQueries.Add(key, value); diff --git a/Directory.Build.props b/Directory.Build.props index 0b3a5c9..db361ea 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,5 @@ - 2.16.0 + 2.17.0