diff options
| author | crobibero <cody@robibe.ro> | 2020-06-04 15:16:04 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-06-04 15:16:04 -0600 |
| commit | a787efc66027b678cb09e83002ce3f9ba00e206d (patch) | |
| tree | cc460c9a764461158c548eb72332d82d3c1d7280 /Jellyfin.Api/Controllers/NotificationsController.cs | |
| parent | 341b947cdecdfc791c1bc3e72da1e68cd3754c3a (diff) | |
| parent | 601e4a88c94ea0ccaab9f3c148d4bbdca2e532ee (diff) | |
Merge remote-tracking branch 'upstream/api-migration' into api-scheduled-tasks
Diffstat (limited to 'Jellyfin.Api/Controllers/NotificationsController.cs')
| -rw-r--r-- | Jellyfin.Api/Controllers/NotificationsController.cs | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/Jellyfin.Api/Controllers/NotificationsController.cs b/Jellyfin.Api/Controllers/NotificationsController.cs new file mode 100644 index 000000000..8d82ca10f --- /dev/null +++ b/Jellyfin.Api/Controllers/NotificationsController.cs @@ -0,0 +1,159 @@ +#nullable enable +#pragma warning disable CA1801 + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using Jellyfin.Api.Models.NotificationDtos; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Notifications; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Notifications; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Jellyfin.Api.Controllers +{ + /// <summary> + /// The notification controller. + /// </summary> + public class NotificationsController : BaseJellyfinApiController + { + private readonly INotificationManager _notificationManager; + private readonly IUserManager _userManager; + + /// <summary> + /// Initializes a new instance of the <see cref="NotificationsController" /> class. + /// </summary> + /// <param name="notificationManager">The notification manager.</param> + /// <param name="userManager">The user manager.</param> + public NotificationsController(INotificationManager notificationManager, IUserManager userManager) + { + _notificationManager = notificationManager; + _userManager = userManager; + } + + /// <summary> + /// Gets a user's notifications. + /// </summary> + /// <param name="userId">The user's ID.</param> + /// <param name="isRead">An optional filter by notification read state.</param> + /// <param name="startIndex">The optional index to start at. All notifications with a lower index will be omitted from the results.</param> + /// <param name="limit">An optional limit on the number of notifications returned.</param> + /// <response code="200">Notifications returned.</response> + /// <returns>An <see cref="OkResult"/> containing a list of notifications.</returns> + [HttpGet("{UserID}")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult<NotificationResultDto> GetNotifications( + [FromRoute] string userId, + [FromQuery] bool? isRead, + [FromQuery] int? startIndex, + [FromQuery] int? limit) + { + return new NotificationResultDto(); + } + + /// <summary> + /// Gets a user's notification summary. + /// </summary> + /// <param name="userId">The user's ID.</param> + /// <response code="200">Summary of user's notifications returned.</response> + /// <returns>An <cref see="OkResult"/> containing a summary of the users notifications.</returns> + [HttpGet("{UserID}/Summary")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult<NotificationsSummaryDto> GetNotificationsSummary( + [FromRoute] string userId) + { + return new NotificationsSummaryDto(); + } + + /// <summary> + /// Gets notification types. + /// </summary> + /// <response code="200">All notification types returned.</response> + /// <returns>An <cref see="OkResult"/> containing a list of all notification types.</returns> + [HttpGet("Types")] + [ProducesResponseType(StatusCodes.Status200OK)] + public IEnumerable<NotificationTypeInfo> GetNotificationTypes() + { + return _notificationManager.GetNotificationTypes(); + } + + /// <summary> + /// Gets notification services. + /// </summary> + /// <response code="200">All notification services returned.</response> + /// <returns>An <cref see="OkResult"/> containing a list of all notification services.</returns> + [HttpGet("Services")] + [ProducesResponseType(StatusCodes.Status200OK)] + public IEnumerable<NameIdPair> GetNotificationServices() + { + return _notificationManager.GetNotificationServices(); + } + + /// <summary> + /// Sends a notification to all admins. + /// </summary> + /// <param name="name">The name of the notification.</param> + /// <param name="description">The description of the notification.</param> + /// <param name="url">The URL of the notification.</param> + /// <param name="level">The level of the notification.</param> + /// <response code="200">Notification sent.</response> + /// <returns>An <cref see="OkResult"/>.</returns> + [HttpPost("Admin")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult CreateAdminNotification( + [FromQuery] string name, + [FromQuery] string description, + [FromQuery] string? url, + [FromQuery] NotificationLevel? level) + { + var notification = new NotificationRequest + { + Name = name, + Description = description, + Url = url, + Level = level ?? NotificationLevel.Normal, + UserIds = _userManager.Users.Where(i => i.Policy.IsAdministrator).Select(i => i.Id).ToArray(), + Date = DateTime.UtcNow, + }; + + _notificationManager.SendNotification(notification, CancellationToken.None); + + return Ok(); + } + + /// <summary> + /// Sets notifications as read. + /// </summary> + /// <param name="userId">The userID.</param> + /// <param name="ids">A comma-separated list of the IDs of notifications which should be set as read.</param> + /// <response code="200">Notifications set as read.</response> + /// <returns>An <cref see="OkResult"/>.</returns> + [HttpPost("{UserID}/Read")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult SetRead( + [FromRoute] string userId, + [FromQuery] string ids) + { + return Ok(); + } + + /// <summary> + /// Sets notifications as unread. + /// </summary> + /// <param name="userId">The userID.</param> + /// <param name="ids">A comma-separated list of the IDs of notifications which should be set as unread.</param> + /// <response code="200">Notifications set as unread.</response> + /// <returns>An <cref see="OkResult"/>.</returns> + [HttpPost("{UserID}/Unread")] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult SetUnread( + [FromRoute] string userId, + [FromQuery] string ids) + { + return Ok(); + } + } +} |
