Skip to content
This repository has been archived by the owner on Jun 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #18 from Ullmie02/api-migration
Browse files Browse the repository at this point in the history
Migrate to Asp.Net Core Web Api
  • Loading branch information
oddstr13 committed Nov 30, 2020
2 parents 0551dcf + c66eda0 commit 6afac26
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 43 deletions.
43 changes: 0 additions & 43 deletions MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<SmtpNotificationsController> _logger;
private readonly ILogger<Notifier> _notifierLogger;

public SmtpNotificationsController(IUserManager userManager, ILogger<SmtpNotificationsController> logger, ILogger<Notifier> notifierLogger)
{
_userManager = userManager;
_logger = logger;
_notifierLogger = notifierLogger;
}

/// <summary>
/// Send test SMTP notification.
/// </summary>
/// <param name="userId">The user id of the Jellyfin user.</param>
/// <response code="204">Test SMTP notification send successfully.</response>
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns>
[HttpPost("Test/{userId}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<ActionResult> 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="Jellyfin.Data" Version="10.*-*"/>
<PackageReference Include="Jellyfin.Controller" Version="10.*-*"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

</Project>

0 comments on commit 6afac26

Please sign in to comment.