mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Add pagination for API GetNotifications (#3145)
This commit is contained in:
@@ -9,13 +9,22 @@ namespace BTCPayServer.Client
|
|||||||
{
|
{
|
||||||
public partial class BTCPayServerClient
|
public partial class BTCPayServerClient
|
||||||
{
|
{
|
||||||
public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null,
|
public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null, int? skip = null,
|
||||||
CancellationToken token = default)
|
int? take = null, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var response =
|
Dictionary<string, object> queryPayload = new Dictionary<string, object>();
|
||||||
await _httpClient.SendAsync(
|
|
||||||
|
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",
|
CreateHttpRequest($"api/v1/users/me/notifications",
|
||||||
seen != null ? new Dictionary<string, object>() {{nameof(seen), seen}} : null), token);
|
queryPayload), token);
|
||||||
|
|
||||||
return await HandleResponse<IEnumerable<NotificationData>>(response);
|
return await HandleResponse<IEnumerable<NotificationData>>(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -614,10 +614,10 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null,
|
public override async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null,
|
||||||
CancellationToken token = default)
|
int? skip = null, int? take = null, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
return GetFromActionResult<IEnumerable<NotificationData>>(
|
return GetFromActionResult<IEnumerable<NotificationData>>(
|
||||||
await _notificationsController.GetNotifications(seen));
|
await _notificationsController.GetNotifications(seen, skip, take));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<NotificationData> GetNotification(string notificationId,
|
public override async Task<NotificationData> GetNotification(string notificationId,
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ namespace BTCPayServer.Controllers.GreenField
|
|||||||
[Authorize(Policy = Policies.CanViewNotificationsForUser,
|
[Authorize(Policy = Policies.CanViewNotificationsForUser,
|
||||||
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
|
||||||
[HttpGet("~/api/v1/users/me/notifications")]
|
[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()
|
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));
|
return Ok(items.Items.Select(ToModel));
|
||||||
|
|||||||
@@ -16,6 +16,26 @@
|
|||||||
"type": "string",
|
"type": "string",
|
||||||
"nullable": true
|
"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",
|
"description": "View current user's notifications",
|
||||||
|
|||||||
Reference in New Issue
Block a user