mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-02-20 13:34:37 +01:00
Add pagination for API GetNotifications (#3145)
This commit is contained in:
parent
57852821f5
commit
9b730e784f
4 changed files with 41 additions and 12 deletions
|
@ -9,13 +9,22 @@ namespace BTCPayServer.Client
|
|||
{
|
||||
public partial class BTCPayServerClient
|
||||
{
|
||||
public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null,
|
||||
CancellationToken token = default)
|
||||
public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null, int? skip = null,
|
||||
int? take = null, CancellationToken token = default)
|
||||
{
|
||||
var response =
|
||||
await _httpClient.SendAsync(
|
||||
CreateHttpRequest($"api/v1/users/me/notifications",
|
||||
seen != null ? new Dictionary<string, object>() {{nameof(seen), seen}} : null), token);
|
||||
Dictionary<string, object> queryPayload = new Dictionary<string, object>();
|
||||
|
||||
if (seen != null)
|
||||
queryPayload.Add(nameof(seen), seen);
|
||||
if (skip != null)
|
||||
queryPayload.Add(nameof(skip), skip);
|
||||
if (take != null)
|
||||
queryPayload.Add(nameof(take), take);
|
||||
|
||||
var response = await _httpClient.SendAsync(
|
||||
CreateHttpRequest($"api/v1/users/me/notifications",
|
||||
queryPayload), token);
|
||||
|
||||
return await HandleResponse<IEnumerable<NotificationData>>(response);
|
||||
}
|
||||
|
||||
|
|
|
@ -612,12 +612,12 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
{
|
||||
HandleActionResult(await _apiKeysController.RevokeKey(apikey));
|
||||
}
|
||||
|
||||
public override async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null,
|
||||
CancellationToken token = default)
|
||||
|
||||
public override async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null,
|
||||
int? skip = null, int? take = null, CancellationToken token = default)
|
||||
{
|
||||
return GetFromActionResult<IEnumerable<NotificationData>>(
|
||||
await _notificationsController.GetNotifications(seen));
|
||||
await _notificationsController.GetNotifications(seen, skip, take));
|
||||
}
|
||||
|
||||
public override async Task<NotificationData> GetNotification(string notificationId,
|
||||
|
|
|
@ -33,11 +33,11 @@ namespace BTCPayServer.Controllers.GreenField
|
|||
[Authorize(Policy = Policies.CanViewNotificationsForUser,
|
||||
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||
[HttpGet("~/api/v1/users/me/notifications")]
|
||||
public async Task<IActionResult> GetNotifications(bool? seen = null)
|
||||
public async Task<IActionResult> GetNotifications(bool? seen = null, [FromQuery] int? skip = null, [FromQuery] int? take = null)
|
||||
{
|
||||
var items = await _notificationManager.GetNotifications(new NotificationsQuery()
|
||||
{
|
||||
Seen = seen, UserId = _userManager.GetUserId(User)
|
||||
Seen = seen, UserId = _userManager.GetUserId(User), Skip = skip, Take = take
|
||||
});
|
||||
|
||||
return Ok(items.Items.Select(ToModel));
|
||||
|
|
|
@ -16,6 +16,26 @@
|
|||
"type": "string",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "skip",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Number of records to skip",
|
||||
"schema": {
|
||||
"nullable": true,
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "take",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "Number of records returned in response",
|
||||
"schema": {
|
||||
"nullable": true,
|
||||
"type": "number"
|
||||
}
|
||||
}
|
||||
],
|
||||
"description": "View current user's notifications",
|
||||
|
|
Loading…
Add table
Reference in a new issue