mirror of
https://github.com/bitwarden/server
synced 2025-12-25 04:33:26 +00:00
* PM-10563: Notification Center API * PM-10563: continuation token hack * PM-10563: Resolving merge conflicts * PM-10563: Unit Tests * PM-10563: Paging simplification by page number and size in database * PM-10563: Request validation * PM-10563: Read, Deleted status filters change * PM-10563: Plural name for tests * PM-10563: Request validation to always for int type * PM-10563: Continuation Token returns null on response when no more records available * PM-10563: Integration tests for GET * PM-10563: Mark notification read, deleted commands date typos fix * PM-10563: Integration tests for PATCH read, deleted * PM-10563: Request, Response models tests * PM-10563: EditorConfig compliance * PM-10563: Extracting to const * PM-10563: Update db migration script date * PM-10563: Update migration script date
72 lines
2.6 KiB
C#
72 lines
2.6 KiB
C#
#nullable enable
|
|
using Bit.Api.Models.Response;
|
|
using Bit.Api.NotificationCenter.Models.Request;
|
|
using Bit.Api.NotificationCenter.Models.Response;
|
|
using Bit.Core.Models.Data;
|
|
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
|
using Bit.Core.NotificationCenter.Models.Filter;
|
|
using Bit.Core.NotificationCenter.Queries.Interfaces;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Bit.Api.NotificationCenter.Controllers;
|
|
|
|
[Route("notifications")]
|
|
[Authorize("Application")]
|
|
public class NotificationsController : Controller
|
|
{
|
|
private readonly IGetNotificationStatusDetailsForUserQuery _getNotificationStatusDetailsForUserQuery;
|
|
private readonly IMarkNotificationDeletedCommand _markNotificationDeletedCommand;
|
|
private readonly IMarkNotificationReadCommand _markNotificationReadCommand;
|
|
|
|
public NotificationsController(
|
|
IGetNotificationStatusDetailsForUserQuery getNotificationStatusDetailsForUserQuery,
|
|
IMarkNotificationDeletedCommand markNotificationDeletedCommand,
|
|
IMarkNotificationReadCommand markNotificationReadCommand)
|
|
{
|
|
_getNotificationStatusDetailsForUserQuery = getNotificationStatusDetailsForUserQuery;
|
|
_markNotificationDeletedCommand = markNotificationDeletedCommand;
|
|
_markNotificationReadCommand = markNotificationReadCommand;
|
|
}
|
|
|
|
[HttpGet("")]
|
|
public async Task<ListResponseModel<NotificationResponseModel>> ListAsync(
|
|
[FromQuery] NotificationFilterRequestModel filter)
|
|
{
|
|
var pageOptions = new PageOptions
|
|
{
|
|
ContinuationToken = filter.ContinuationToken,
|
|
PageSize = filter.PageSize
|
|
};
|
|
|
|
var notificationStatusFilter = new NotificationStatusFilter
|
|
{
|
|
Read = filter.ReadStatusFilter,
|
|
Deleted = filter.DeletedStatusFilter
|
|
};
|
|
|
|
var notificationStatusDetailsPagedResult =
|
|
await _getNotificationStatusDetailsForUserQuery.GetByUserIdStatusFilterAsync(notificationStatusFilter,
|
|
pageOptions);
|
|
|
|
var responses = notificationStatusDetailsPagedResult.Data
|
|
.Select(n => new NotificationResponseModel(n))
|
|
.ToList();
|
|
|
|
return new ListResponseModel<NotificationResponseModel>(responses,
|
|
notificationStatusDetailsPagedResult.ContinuationToken);
|
|
}
|
|
|
|
[HttpPatch("{id}/delete")]
|
|
public async Task MarkAsDeletedAsync([FromRoute] Guid id)
|
|
{
|
|
await _markNotificationDeletedCommand.MarkDeletedAsync(id);
|
|
}
|
|
|
|
[HttpPatch("{id}/read")]
|
|
public async Task MarkAsReadAsync([FromRoute] Guid id)
|
|
{
|
|
await _markNotificationReadCommand.MarkReadAsync(id);
|
|
}
|
|
}
|