Add response type annotations, return IActionResult to handle errors

This commit is contained in:
ZadenRB 2020-04-19 21:06:28 -06:00
parent 7c8188194b
commit 16cae23bbe

View File

@ -10,6 +10,7 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Notifications; using MediaBrowser.Controller.Notifications;
using MediaBrowser.Model.Dto; using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Notifications; using MediaBrowser.Model.Notifications;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api.Controllers namespace Jellyfin.Api.Controllers
@ -42,13 +43,14 @@ namespace Jellyfin.Api.Controllers
/// <param name="limit">An optional limit on the number of notifications returned.</param> /// <param name="limit">An optional limit on the number of notifications returned.</param>
/// <returns>A read-only list of all of the user's notifications.</returns> /// <returns>A read-only list of all of the user's notifications.</returns>
[HttpGet("{UserID}")] [HttpGet("{UserID}")]
public NotificationResultDto GetNotifications( [ProducesResponseType(typeof(IEnumerable<NotificationResultDto>), StatusCodes.Status200OK)]
public IActionResult GetNotifications(
[FromRoute] string userId, [FromRoute] string userId,
[FromQuery] bool? isRead, [FromQuery] bool? isRead,
[FromQuery] int? startIndex, [FromQuery] int? startIndex,
[FromQuery] int? limit) [FromQuery] int? limit)
{ {
return new NotificationResultDto(); return Ok(new NotificationResultDto());
} }
/// <summary> /// <summary>
@ -57,10 +59,11 @@ namespace Jellyfin.Api.Controllers
/// <param name="userId">The user's ID.</param> /// <param name="userId">The user's ID.</param>
/// <returns>Notifications summary for the user.</returns> /// <returns>Notifications summary for the user.</returns>
[HttpGet("{UserID}/Summary")] [HttpGet("{UserID}/Summary")]
public NotificationsSummaryDto GetNotificationsSummary( [ProducesResponseType(typeof(NotificationsSummaryDto), StatusCodes.Status200OK)]
public IActionResult GetNotificationsSummary(
[FromRoute] string userId) [FromRoute] string userId)
{ {
return new NotificationsSummaryDto(); return Ok(new NotificationsSummaryDto());
} }
/// <summary> /// <summary>
@ -68,9 +71,18 @@ namespace Jellyfin.Api.Controllers
/// </summary> /// </summary>
/// <returns>All notification types.</returns> /// <returns>All notification types.</returns>
[HttpGet("Types")] [HttpGet("Types")]
public IEnumerable<NotificationTypeInfo> GetNotificationTypes() [ProducesResponseType(typeof(IEnumerable<NameIdPair>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult GetNotificationTypes()
{ {
return _notificationManager.GetNotificationTypes(); try
{
return Ok(_notificationManager.GetNotificationTypes());
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -78,9 +90,18 @@ namespace Jellyfin.Api.Controllers
/// </summary> /// </summary>
/// <returns>All notification services.</returns> /// <returns>All notification services.</returns>
[HttpGet("Services")] [HttpGet("Services")]
public IEnumerable<NameIdPair> GetNotificationServices() [ProducesResponseType(typeof(IEnumerable<NameIdPair>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult GetNotificationServices()
{ {
return _notificationManager.GetNotificationServices(); try
{
return Ok(_notificationManager.GetNotificationServices());
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -90,24 +111,36 @@ namespace Jellyfin.Api.Controllers
/// <param name="description">The description of the notification.</param> /// <param name="description">The description of the notification.</param>
/// <param name="url">The URL of the notification.</param> /// <param name="url">The URL of the notification.</param>
/// <param name="level">The level of the notification.</param> /// <param name="level">The level of the notification.</param>
/// <returns>Status.</returns>
[HttpPost("Admin")] [HttpPost("Admin")]
public void CreateAdminNotification( [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IActionResult CreateAdminNotification(
[FromQuery] string name, [FromQuery] string name,
[FromQuery] string description, [FromQuery] string description,
[FromQuery] string? url, [FromQuery] string? url,
[FromQuery] NotificationLevel? level) [FromQuery] NotificationLevel? level)
{ {
var notification = new NotificationRequest try
{ {
Name = name, var notification = new NotificationRequest
Description = description, {
Url = url, Name = name,
Level = level ?? NotificationLevel.Normal, Description = description,
UserIds = _userManager.Users.Where(i => i.Policy.IsAdministrator).Select(i => i.Id).ToArray(), Url = url,
Date = DateTime.UtcNow, 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); _notificationManager.SendNotification(notification, CancellationToken.None);
return Ok();
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
} }
/// <summary> /// <summary>
@ -115,11 +148,14 @@ namespace Jellyfin.Api.Controllers
/// </summary> /// </summary>
/// <param name="userId">The userID.</param> /// <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> /// <param name="ids">A comma-separated list of the IDs of notifications which should be set as read.</param>
/// <returns>Status.</returns>
[HttpPost("{UserID}/Read")] [HttpPost("{UserID}/Read")]
public void SetRead( [ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult SetRead(
[FromRoute] string userId, [FromRoute] string userId,
[FromQuery] string ids) [FromQuery] string ids)
{ {
return Ok();
} }
/// <summary> /// <summary>
@ -127,11 +163,14 @@ namespace Jellyfin.Api.Controllers
/// </summary> /// </summary>
/// <param name="userId">The userID.</param> /// <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> /// <param name="ids">A comma-separated list of the IDs of notifications which should be set as unread.</param>
/// <returns>Status.</returns>
[HttpPost("{UserID}/Unread")] [HttpPost("{UserID}/Unread")]
public void SetUnread( [ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult SetUnread(
[FromRoute] string userId, [FromRoute] string userId,
[FromQuery] string ids) [FromQuery] string ids)
{ {
return Ok();
} }
} }
} }