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

Remove auto parsing of int for after/before #5

Closed
mrahhal opened this issue Nov 5, 2022 · 0 comments
Closed

Remove auto parsing of int for after/before #5

mrahhal opened this issue Nov 5, 2022 · 0 comments
Assignees

Comments

@mrahhal
Copy link
Owner

mrahhal commented Nov 5, 2022

Today we try to automatically parse the id in after/value as an int:

if (requestQuery.ContainsKey(_options.BeforeQueryParameterName))
{
var before = requestQuery[_options.BeforeQueryParameterName][0];
if (int.TryParse(before, out var beforeIntValue))
{
model.Before = beforeIntValue;
}
else
{
model.Before = before;
}
}
if (requestQuery.ContainsKey(_options.AfterQueryParameterName))
{
var after = requestQuery[_options.AfterQueryParameterName][0];
if (int.TryParse(after, out var afterIntValue))
{
model.After = afterIntValue;
}
else
{
model.After = after;
}
}

This is problematic for cases when the id is not an int (maybe a string) but it looks like one. We should completely remove this behavior, the caller should parse the id instead (it'll always be a string now):

await _paginationService.KeysetPaginateAsync(
    query,
    b => b.Descending(x => x.Created),
    async id => await _dbContext.Posts.FindAsync(int.Parse(id)));
@mrahhal mrahhal self-assigned this Nov 5, 2022
@mrahhal mrahhal closed this as completed in c06d144 Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant