Add offset pagination parameter to dotnet client.

This commit is contained in:
Sebastian Jeltsch
2025-04-27 23:46:31 +02:00
parent a7a931f51f
commit dc8521752e
2 changed files with 27 additions and 8 deletions
+9 -1
View File
@@ -73,11 +73,14 @@ public class Pagination {
public int? limit { get; }
/// <summary>Offset cursor.</summary>
public string? cursor { get; }
/// <summary>Numeric offset parameter. Prefer cursor when possible.</summary>
public int? offset { get; }
/// <summary>Pagination constructor.</summary>
public Pagination(int? limit = null, string? cursor = null) {
public Pagination(int? limit = null, string? cursor = null, int? offset = null) {
this.cursor = cursor;
this.limit = limit;
this.offset = offset;
}
}
@@ -394,6 +397,11 @@ public class RecordApi {
if (limit != null) {
param.Add("limit", $"{limit}");
}
var offset = pagination.offset;
if (offset != null) {
param.Add("offset", $"{offset}");
}
}
if (order != null) {
+18 -7
View File
@@ -342,18 +342,29 @@ public class ClientTest : IClassFixture<ClientTestFixture> {
{
var response = await api.List<JsonObject>(
pagination: new Pagination(limit: 1),
pagination: new Pagination(limit: 2),
expand: ["author", "post"],
order: ["-id"]
);
Assert.Single(response.records);
var comment = response.records[0];
Assert.Equal(2, response.records.Count);
var first = response.records[0];
Assert.Equal(2, comment["id"]!.GetValue<int>());
Assert.Equal("second comment", comment["body"]!.GetValue<string>());
Assert.Equal("SecondUser", comment["author"]!["data"]!["name"]!.GetValue<string>());
Assert.Equal("first post", comment["post"]!["data"]!["title"]!.GetValue<string>());
Assert.Equal(2, first["id"]!.GetValue<int>());
Assert.Equal("second comment", first["body"]!.GetValue<string>());
Assert.Equal("SecondUser", first["author"]!["data"]!["name"]!.GetValue<string>());
Assert.Equal("first post", first["post"]!["data"]!["title"]!.GetValue<string>());
var second = response.records[1];
var offsetResponse = await api.List<JsonObject>(
pagination: new Pagination(limit: 1, offset: 1),
expand: ["author", "post"],
order: ["-id"]
);
Assert.Single(offsetResponse.records);
Assert.True(JsonObject.DeepEquals(second, offsetResponse.records[0]));
}
}