Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yaochangyu committed Nov 12, 2024
1 parent e238a4b commit 3cf1bd9
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,31 @@ public async Task<ActionResult<CursorPagination<MemberDataEntity>>> GetCursor()
PreviousCursorToken = previousCursorToken,
PageSize = pageSize
};

await using var dbContext = await this._memberDbContextFactory.CreateDbContextAsync();
var query = dbContext.Members.Select(p => p);

if (!string.IsNullOrWhiteSpace(nextCursorToken))
if (string.IsNullOrWhiteSpace(nextCursorToken) == false)
{
var decodePageToken = DecodePageToken(nextCursorToken);
var sequenceId = decodePageToken.sequenceId;

query = query.Where(x => x.SequenceId > sequenceId);
query = query.Take(pageSize + 1);
}
else if (!string.IsNullOrWhiteSpace(previousCursorToken))
else if (string.IsNullOrWhiteSpace(previousCursorToken) == false)
{
var decodePageToken = DecodePageToken(previousCursorToken);
var sequenceId = decodePageToken.sequenceId;
var start = sequenceId - pageSize;
query = query.Where(x => x.SequenceId > start && x.SequenceId <= sequenceId);
}
else
{
// 第一頁
query = query.Take(pageSize + 1);
}

query = query.Take(pageSize + 1);
var items = await query.AsNoTracking().ToListAsync();

if (nextCursorToken != null)
Expand Down

0 comments on commit 3cf1bd9

Please sign in to comment.