mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-20 02:28:31 +01:00
0652e30c30
* GreenField: Notifications API This refactors notifications so that we dont have a bunch of duplicated direct access to db contexts in controllers and then introduces new endpoints to fetch/toggle seen/remove notifications of the current user. * add tests + docs * fix test * pr changes * fix permission json
48 lines
2.0 KiB
C#
48 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Client.Models;
|
|
|
|
namespace BTCPayServer.Client
|
|
{
|
|
public partial class BTCPayServerClient
|
|
{
|
|
public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = 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);
|
|
return await HandleResponse<IEnumerable<NotificationData>>(response);
|
|
}
|
|
|
|
public virtual async Task<NotificationData> GetNotification(string notificationId,
|
|
CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}"), token);
|
|
return await HandleResponse<NotificationData>(response);
|
|
}
|
|
|
|
public virtual async Task<NotificationData> UpdateNotification(string notificationId, bool? seen,
|
|
CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}",
|
|
method: HttpMethod.Put, bodyPayload: new UpdateNotification() {Seen = seen}), token);
|
|
return await HandleResponse<NotificationData>(response);
|
|
}
|
|
|
|
public virtual async Task RemoveNotification(string notificationId, CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(
|
|
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}",
|
|
method: HttpMethod.Delete), token);
|
|
await HandleResponse(response);
|
|
}
|
|
}
|
|
}
|