mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-05-05 08:00:06 -05:00
Add offset pagination parameter to dotnet client.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user