Skip to content

Commit 1778565

Browse files
committed
Add querystring to contentypes calls
1 parent e4a0e5e commit 1778565

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

Diff for: Contentful.Core.Tests/ContentfulManagementClientTests.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -3078,7 +3078,29 @@ public async Task SettingEnvironmentForContentTypesShouldYieldCorrectUrl()
30783078
Assert.Equal(5, res.Count());
30793079
Assert.Equal("someName", res.First().Name);
30803080
Assert.Equal(8, (res.First().Fields.First().Validations.First() as SizeValidator).Max);
3081-
Assert.Equal("https://api.contentful.com/spaces/564/environments/special/content_types", path);
3081+
Assert.Equal("https://api.contentful.com/spaces/564/environments/special/content_types/", path);
3082+
}
3083+
3084+
[Fact]
3085+
public async Task SettingEnvironmentAndQueryContentTypesShouldYieldCorrectUrl()
3086+
{
3087+
//Arrange
3088+
_handler.Response = GetResponseFromFile(@"ContenttypesCollectionManagement.json");
3089+
var client = GetClientWithEnvironment();
3090+
var path = "";
3091+
_handler.VerifyRequest = (HttpRequestMessage request) =>
3092+
{
3093+
path = request.RequestUri.ToString();
3094+
};
3095+
3096+
//Act
3097+
var res = await client.GetContentTypes("?limit=1000", "564");
3098+
3099+
//Assert
3100+
Assert.Equal(5, res.Count());
3101+
Assert.Equal("someName", res.First().Name);
3102+
Assert.Equal(8, (res.First().Fields.First().Validations.First() as SizeValidator).Max);
3103+
Assert.Equal("https://api.contentful.com/spaces/564/environments/special/content_types/?limit=1000", path);
30823104
}
30833105

30843106
[Fact]

Diff for: Contentful.Core/ContentfulClient.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,18 @@ public async Task<ContentType> GetContentType(string contentTypeId, Cancellation
472472
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
473473
public async Task<IEnumerable<ContentType>> GetContentTypes(CancellationToken cancellationToken = default)
474474
{
475-
var res = await Get($"{_baseUrl}{_options.SpaceId}/{EnvironmentsBase}content_types/", cancellationToken).ConfigureAwait(false);
475+
return await GetContentTypes(null, cancellationToken);
476+
}
477+
478+
/// <summary>
479+
/// Get all content types of a space.
480+
/// </summary>
481+
/// <param name="queryString">The optional querystring to add additional filtering to the query.</param>
482+
/// <param name="cancellationToken">The optional cancellation token to cancel the operation.</param>
483+
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
484+
public async Task<IEnumerable<ContentType>> GetContentTypes(string queryString, CancellationToken cancellationToken = default)
485+
{
486+
var res = await Get($"{_baseUrl}{_options.SpaceId}/{EnvironmentsBase}content_types/{queryString}", cancellationToken).ConfigureAwait(false);
476487

477488
var jsonObject = JObject.Parse(await res.Content.ReadAsStringAsync().ConfigureAwait(false));
478489
var contentTypes = jsonObject.SelectTokens("$..items[*]").Select(t => t.ToObject<ContentType>(Serializer));

Diff for: Contentful.Core/ContentfulManagementClient.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,19 @@ public async Task DeleteSpace(string id, CancellationToken cancellationToken = d
167167
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
168168
public async Task<IEnumerable<ContentType>> GetContentTypes(string spaceId = null, CancellationToken cancellationToken = default)
169169
{
170-
var res = await GetAsync($"{_baseUrl}{spaceId ?? _options.SpaceId}/{EnvironmentsBase}content_types", cancellationToken).ConfigureAwait(false);
170+
return await GetContentTypes(null, spaceId, cancellationToken);
171+
}
172+
173+
/// <summary>
174+
/// Get all content types of a space.
175+
/// </summary>
176+
/// <param name="queryString">The optional querystring to add additional filtering to the query.</param>
177+
/// <param name="spaceId">The id of the space to get the content types of. Will default to the one set when creating the client.</param>
178+
/// <param name="cancellationToken">The optional cancellation token to cancel the operation.</param>
179+
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
180+
public async Task<IEnumerable<ContentType>> GetContentTypes(string queryString, string spaceId = null, CancellationToken cancellationToken = default)
181+
{
182+
var res = await GetAsync($"{_baseUrl}{spaceId ?? _options.SpaceId}/{EnvironmentsBase}content_types/{queryString}", cancellationToken).ConfigureAwait(false);
171183

172184
await EnsureSuccessfulResult(res).ConfigureAwait(false);
173185

Diff for: Contentful.Core/IContentfulClient.cs

+7
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ public interface IContentfulClient
157157
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
158158
Task<IEnumerable<ContentType>> GetContentTypes(CancellationToken cancellationToken = default);
159159

160+
/// <summary>
161+
/// Get all content types of a space.
162+
/// </summary>
163+
/// <param name="queryString">The optional querystring to add additional filtering to the query.</param>
164+
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
165+
Task<IEnumerable<ContentType>> GetContentTypes(string queryString, CancellationToken cancellationToken = default);
166+
160167
/// <summary>
161168
/// Get all locales of an environment.
162169
/// </summary>

Diff for: Contentful.Core/IContentfulManagementClient.cs

+9
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,15 @@ public interface IContentfulManagementClient
410410
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
411411
Task<IEnumerable<ContentType>> GetContentTypes(string spaceId = null, CancellationToken cancellationToken = default);
412412

413+
/// <summary>
414+
/// Get all content types of a space.
415+
/// </summary>
416+
/// <param name="queryString">The optional querystring to add additional filtering to the query.</param>
417+
/// <param name="spaceId">The id of the space to get the content types of. Will default to the one set when creating the client.</param>
418+
/// <param name="cancellationToken">The optional cancellation token to cancel the operation.</param>
419+
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ContentType"/>.</returns>
420+
Task<IEnumerable<ContentType>> GetContentTypes(string queryString, string spaceId = null, CancellationToken cancellationToken = default);
421+
413422
/// <summary>
414423
/// Gets a <see cref="Contentful.Core.Models.Management.EditorInterface"/> for a specific <seealso cref="ContentType"/>.
415424
/// </summary>

0 commit comments

Comments
 (0)