diff --git a/MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs b/MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs deleted file mode 100644 index b8afb5b..0000000 --- a/MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using MediaBrowser.Controller.Notifications; -using MediaBrowser.Controller.Library; -using MediaBrowser.Model.Services; -using Microsoft.Extensions.Logging; - -namespace MediaBrowser.Plugins.SmtpNotifications.Api -{ - [Route("/Notification/SMTP/Test/{UserID}", "POST", Summary = "Tests SMTP")] - public class TestNotification : IReturnVoid - { - [ApiMember(Name = "UserID", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")] - public string UserId { get; set; } - } - - public class ServerApiEndpoints : IService - { - private readonly IUserManager _userManager; - private readonly ILogger _logger; - private readonly ILogger _notifierLogger; - - public ServerApiEndpoints(IUserManager userManager, ILogger logger, ILogger notifierLogger) - { - _userManager = userManager; - _logger = logger; - _notifierLogger = notifierLogger; - } - - public Task Post(TestNotification request) - { - return new Notifier(_notifierLogger).SendNotification(new UserNotification - { - Date = DateTime.UtcNow, - Description = "This is a test notification from Jellyfin Server", - Level = Model.Notifications.NotificationLevel.Normal, - Name = "Test Notification", - User = _userManager.GetUserById(Guid.Parse(request.UserId)) - }, CancellationToken.None); - } - } -} diff --git a/MediaBrowser.Plugins.SmtpNotifications/Api/SmtpNotificationsController.cs b/MediaBrowser.Plugins.SmtpNotifications/Api/SmtpNotificationsController.cs new file mode 100644 index 0000000..ad08a0e --- /dev/null +++ b/MediaBrowser.Plugins.SmtpNotifications/Api/SmtpNotificationsController.cs @@ -0,0 +1,53 @@ +using System; +using System.Net.Mime; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Notifications; +using MediaBrowser.Controller.Library; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace MediaBrowser.Plugins.SmtpNotifications.Api +{ + [ApiController] + [Route("Notification/SMTP")] + [Produces(MediaTypeNames.Application.Json)] + public class SmtpNotificationsController : ControllerBase + { + private readonly IUserManager _userManager; + private readonly ILogger _logger; + private readonly ILogger _notifierLogger; + + public SmtpNotificationsController(IUserManager userManager, ILogger logger, ILogger notifierLogger) + { + _userManager = userManager; + _logger = logger; + _notifierLogger = notifierLogger; + } + + /// + /// Send test SMTP notification. + /// + /// The user id of the Jellyfin user. + /// Test SMTP notification send successfully. + /// A indicating success. + [HttpPost("Test/{userId}")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + public async Task SendSmtpTestNotification([FromRoute] string userId) + { + await new Notifier(_notifierLogger).SendNotification(new UserNotification + { + Date = DateTime.UtcNow, + Description = "This is a test notification from Jellyfin Server", + Level = Model.Notifications.NotificationLevel.Normal, + Name = "Test Notification", + User = _userManager.GetUserById(Guid.Parse(userId)) + }, CancellationToken.None); + + _logger.LogInformation("Test SMTP notification sent successfully."); + + return NoContent(); + } + } +} diff --git a/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj b/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj index 94f8f72..f170bf3 100644 --- a/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj +++ b/MediaBrowser.Plugins.SmtpNotifications/MediaBrowser.Plugins.SmtpNotifications.csproj @@ -14,6 +14,7 @@ + \ No newline at end of file