Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for between both cursors #7800

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public static async ValueTask<Page<T>> ToPageAsync<T>(
if (arguments.After is not null)
{
var cursor = CursorParser.Parse(arguments.After, keys);
source = source.Where(BuildWhereExpression<T>(keys, cursor, forward));
source = source.Where(BuildWhereExpression<T>(keys, cursor, true));
}

if (arguments.Before is not null)
{
var cursor = CursorParser.Parse(arguments.Before, keys);
source = source.Where(BuildWhereExpression<T>(keys, cursor, forward));
source = source.Where(BuildWhereExpression<T>(keys, cursor, false));
}

if (arguments.First is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ public async Task Fetch_First_2_Items_Third_Page()
page.MatchMarkdownSnapshot();
}

[Fact]
public async Task Fetch_First_2_Items_Between()
{
// Arrange
var connectionString = CreateConnectionString();
await SeedAsync(connectionString);

// .. get first page
var arguments = new PagingArguments(4);
await using var context = new CatalogContext(connectionString);
var page = await context.Products.OrderBy(t => t.Name).ThenBy(t => t.Id)
.ToPageAsync(arguments);

// Act
arguments = new PagingArguments(2, after: page.CreateCursor(page.First!), before: page.CreateCursor(page.Last!));
page = await context.Products.OrderBy(t => t.Name).ThenBy(t => t.Id).ToPageAsync(arguments);

// Assert
page.MatchMarkdownSnapshot();
}

[Fact]
public async Task Fetch_Last_2_Items()
{
Expand Down Expand Up @@ -117,6 +138,29 @@ public async Task Fetch_Last_2_Items_Before_Last_Page()
page.MatchMarkdownSnapshot();
}

[Fact]
public async Task Fetch_Last_2_Items_Between()
{
// Arrange
var connectionString = CreateConnectionString();
await SeedAsync(connectionString);

// .. get last page
var arguments = new PagingArguments(last: 4);
await using var context = new CatalogContext(connectionString);
var page = await context.Products
.OrderBy(t => t.Name)
.ThenBy(t => t.Id)
.ToPageAsync(arguments);

// Act
arguments = new PagingArguments(after: page.CreateCursor(page.First!), last: 2, before: page.CreateCursor(page.Last!));
page = await context.Products.OrderBy(t => t.Name).ThenBy(t => t.Id).ToPageAsync(arguments);

// Assert
page.MatchMarkdownSnapshot();
}

[Fact]
public async Task Batch_Fetch_First_2_Items()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Fetch_First_2_Items_Between

```json
[
{
"Id": 2,
"Name": "Product 0-1",
"Description": null,
"Price": 0.0,
"ImageFileName": null,
"TypeId": 1,
"Type": null,
"BrandId": 1,
"Brand": null,
"AvailableStock": 0,
"RestockThreshold": 0,
"MaxStockThreshold": 0,
"OnReorder": false
},
{
"Id": 11,
"Name": "Product 0-10",
"Description": null,
"Price": 0.0,
"ImageFileName": null,
"TypeId": 1,
"Type": null,
"BrandId": 1,
"Brand": null,
"AvailableStock": 0,
"RestockThreshold": 0,
"MaxStockThreshold": 0,
"OnReorder": false
}
]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Fetch_Last_2_Items_Between

```json
[
{
"Id": 9998,
"Name": "Product 99-97",
"Description": null,
"Price": 0.0,
"ImageFileName": null,
"TypeId": 1,
"Type": null,
"BrandId": 100,
"Brand": null,
"AvailableStock": 0,
"RestockThreshold": 0,
"MaxStockThreshold": 0,
"OnReorder": false
},
{
"Id": 9999,
"Name": "Product 99-98",
"Description": null,
"Price": 0.0,
"ImageFileName": null,
"TypeId": 1,
"Type": null,
"BrandId": 100,
"Brand": null,
"AvailableStock": 0,
"RestockThreshold": 0,
"MaxStockThreshold": 0,
"OnReorder": false
}
]
```
Loading