fix: only allow afterId or beforeId to be set. not both at same time.

This commit is contained in:
Stevan Freeborn
2025-01-05 21:55:53 -06:00
parent 9abad390f1
commit 3fe75f511d
3 changed files with 15 additions and 12 deletions
@@ -34,6 +34,7 @@ public class PagingRequest
/// <param name="beforeId">The ID of the item before which to start the page.</param>
/// <param name="afterId">The ID of the item after which to start the page.</param>
/// <param name="limit">The maximum number of items to return in the page.</param>
/// <exception cref="ArgumentException">Thrown when both <paramref name="beforeId"/> and <paramref name="afterId"/> are specified.</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="limit"/> is less than 1 or greater than 1000.</exception>
/// <returns>A new instance of the <see cref="PagingRequest"/> class.</returns>
public PagingRequest(
@@ -47,6 +48,11 @@ public class PagingRequest
throw new ArgumentOutOfRangeException(nameof(limit), $"{nameof(limit)} must be between {LimitMinimum} and {LimitMaximum}.");
}
if (string.IsNullOrEmpty(beforeId) is false && string.IsNullOrEmpty(afterId) is false)
{
throw new ArgumentException($"Only one of {nameof(beforeId)} or {nameof(afterId)} can be set.");
}
BeforeId = beforeId;
AfterId = afterId;
Limit = limit;