From dc190e56833235c1b20fa76b8382da80fc62b0b7 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 9 Jun 2020 18:56:17 +0200 Subject: [PATCH 1/2] Move ActivityLogService to Jellyfin.Api --- .../System/ActivityLogController.cs | 54 ++++++++++++++++ MediaBrowser.Api/System/ActivityLogService.cs | 61 ------------------- 2 files changed, 54 insertions(+), 61 deletions(-) create mode 100644 Jellyfin.Api/Controllers/System/ActivityLogController.cs delete mode 100644 MediaBrowser.Api/System/ActivityLogService.cs diff --git a/Jellyfin.Api/Controllers/System/ActivityLogController.cs b/Jellyfin.Api/Controllers/System/ActivityLogController.cs new file mode 100644 index 0000000000..f1daed2edd --- /dev/null +++ b/Jellyfin.Api/Controllers/System/ActivityLogController.cs @@ -0,0 +1,54 @@ +using System; +using System.Globalization; +using Jellyfin.Api.Constants; +using MediaBrowser.Model.Activity; +using MediaBrowser.Model.Querying; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace Jellyfin.Api.Controllers.System +{ + /// + /// Activity log controller. + /// + [Route("/System/ActivityLog/Entries")] + [Authorize(Policy = Policies.RequiresElevation)] + public class ActivityLogController : BaseJellyfinApiController + { + private readonly IActivityManager _activityManager; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of interface. + public ActivityLogController(IActivityManager activityManager) + { + _activityManager = activityManager; + } + + /// + /// Gets activity log entries. + /// + /// Optional. The record index to start at. All items with a lower index will be dropped from the results. + /// Optional. The maximum number of records to return. + /// Optional. The minimum date. Format = ISO. + /// Optional. Only returns activities that have a user associated. + /// Activity log returned. + /// A containing the log entries. + [HttpGet] + [ProducesResponseType(StatusCodes.Status200OK)] + public ActionResult> GetLogEntries( + [FromQuery] int? startIndex, + [FromQuery] int? limit, + [FromQuery] string minDate, + bool? hasUserId) + { + DateTime? startDate = string.IsNullOrWhiteSpace(minDate) ? + (DateTime?)null : + DateTime.Parse(minDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); + + return _activityManager.GetActivityLogEntries(startDate, hasUserId, startIndex, limit); + } + } +} diff --git a/MediaBrowser.Api/System/ActivityLogService.cs b/MediaBrowser.Api/System/ActivityLogService.cs deleted file mode 100644 index f95fa7ca0b..0000000000 --- a/MediaBrowser.Api/System/ActivityLogService.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Globalization; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Net; -using MediaBrowser.Model.Activity; -using MediaBrowser.Model.Querying; -using MediaBrowser.Model.Services; -using Microsoft.Extensions.Logging; - -namespace MediaBrowser.Api.System -{ - [Route("/System/ActivityLog/Entries", "GET", Summary = "Gets activity log entries")] - public class GetActivityLogs : IReturn> - { - /// - /// Skips over a given number of items within the results. Use for paging. - /// - /// The start index. - [ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? StartIndex { get; set; } - - /// - /// The maximum number of items to return - /// - /// The limit. - [ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? Limit { get; set; } - - [ApiMember(Name = "MinDate", Description = "Optional. The minimum date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] - public string MinDate { get; set; } - - public bool? HasUserId { get; set; } - } - - [Authenticated(Roles = "Admin")] - public class ActivityLogService : BaseApiService - { - private readonly IActivityManager _activityManager; - - public ActivityLogService( - ILogger logger, - IServerConfigurationManager serverConfigurationManager, - IHttpResultFactory httpResultFactory, - IActivityManager activityManager) - : base(logger, serverConfigurationManager, httpResultFactory) - { - _activityManager = activityManager; - } - - public object Get(GetActivityLogs request) - { - DateTime? minDate = string.IsNullOrWhiteSpace(request.MinDate) ? - (DateTime?)null : - DateTime.Parse(request.MinDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); - - var result = _activityManager.GetActivityLogEntries(minDate, request.HasUserId, request.StartIndex, request.Limit); - - return ToOptimizedResult(result); - } - } -} From 1bf6c085eda59034687f24fa5b5997389aede9e5 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 10 Jun 2020 13:09:23 +0200 Subject: [PATCH 2/2] Move File; Move Route; use DateTime? in Query --- .../{System => }/ActivityLogController.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) rename Jellyfin.Api/Controllers/{System => }/ActivityLogController.cs (80%) diff --git a/Jellyfin.Api/Controllers/System/ActivityLogController.cs b/Jellyfin.Api/Controllers/ActivityLogController.cs similarity index 80% rename from Jellyfin.Api/Controllers/System/ActivityLogController.cs rename to Jellyfin.Api/Controllers/ActivityLogController.cs index f1daed2edd..8d37a83738 100644 --- a/Jellyfin.Api/Controllers/System/ActivityLogController.cs +++ b/Jellyfin.Api/Controllers/ActivityLogController.cs @@ -7,12 +7,12 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -namespace Jellyfin.Api.Controllers.System +namespace Jellyfin.Api.Controllers { /// /// Activity log controller. /// - [Route("/System/ActivityLog/Entries")] + [Route("/System/ActivityLog")] [Authorize(Policy = Policies.RequiresElevation)] public class ActivityLogController : BaseJellyfinApiController { @@ -36,19 +36,15 @@ namespace Jellyfin.Api.Controllers.System /// Optional. Only returns activities that have a user associated. /// Activity log returned. /// A containing the log entries. - [HttpGet] + [HttpGet("Entries")] [ProducesResponseType(StatusCodes.Status200OK)] public ActionResult> GetLogEntries( [FromQuery] int? startIndex, [FromQuery] int? limit, - [FromQuery] string minDate, + [FromQuery] DateTime? minDate, bool? hasUserId) { - DateTime? startDate = string.IsNullOrWhiteSpace(minDate) ? - (DateTime?)null : - DateTime.Parse(minDate, null, DateTimeStyles.RoundtripKind).ToUniversalTime(); - - return _activityManager.GetActivityLogEntries(startDate, hasUserId, startIndex, limit); + return _activityManager.GetActivityLogEntries(minDate, hasUserId, startIndex, limit); } } }