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

Migrate to Asp.Net Core Web Api #18

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>