mirror of
https://github.com/bitwarden/server
synced 2025-12-28 22:23:30 +00:00
[PM-10563] Notification Center API (#4852)
* 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
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#nullable enable
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Api.NotificationCenter.Models.Request;
|
||||
|
||||
public class NotificationFilterRequestModel : IValidatableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Filters notifications by read status. When not set, includes notifications without a status.
|
||||
/// </summary>
|
||||
public bool? ReadStatusFilter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Filters notifications by deleted status. When not set, includes notifications without a status.
|
||||
/// </summary>
|
||||
public bool? DeletedStatusFilter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A cursor for use in pagination.
|
||||
/// </summary>
|
||||
[StringLength(9)]
|
||||
public string? ContinuationToken { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of items to return in a single page.
|
||||
/// Default 10. Minimum 10, maximum 1000.
|
||||
/// </summary>
|
||||
[Range(10, 1000)]
|
||||
public int PageSize { get; set; } = 10;
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(ContinuationToken) &&
|
||||
(!int.TryParse(ContinuationToken, out var pageNumber) || pageNumber <= 0))
|
||||
{
|
||||
yield return new ValidationResult(
|
||||
"Continuation token must be a positive, non zero integer.",
|
||||
[nameof(ContinuationToken)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#nullable enable
|
||||
using Bit.Core.Models.Api;
|
||||
using Bit.Core.NotificationCenter.Enums;
|
||||
using Bit.Core.NotificationCenter.Models.Data;
|
||||
|
||||
namespace Bit.Api.NotificationCenter.Models.Response;
|
||||
|
||||
public class NotificationResponseModel : ResponseModel
|
||||
{
|
||||
private const string _objectName = "notification";
|
||||
|
||||
public NotificationResponseModel(NotificationStatusDetails notificationStatusDetails, string obj = _objectName)
|
||||
: base(obj)
|
||||
{
|
||||
if (notificationStatusDetails == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(notificationStatusDetails));
|
||||
}
|
||||
|
||||
Id = notificationStatusDetails.Id;
|
||||
Priority = notificationStatusDetails.Priority;
|
||||
Title = notificationStatusDetails.Title;
|
||||
Body = notificationStatusDetails.Body;
|
||||
Date = notificationStatusDetails.RevisionDate;
|
||||
ReadDate = notificationStatusDetails.ReadDate;
|
||||
DeletedDate = notificationStatusDetails.DeletedDate;
|
||||
}
|
||||
|
||||
public NotificationResponseModel() : base(_objectName)
|
||||
{
|
||||
}
|
||||
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Priority Priority { get; set; }
|
||||
|
||||
public string? Title { get; set; }
|
||||
|
||||
public string? Body { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public DateTime? ReadDate { get; set; }
|
||||
|
||||
public DateTime? DeletedDate { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user