2019-01-13 15:01:16 -05:00
using System ;
2019-01-13 14:24:58 -05:00
using System.Globalization ;
2019-11-17 17:05:39 -05:00
using MediaBrowser.Controller.Configuration ;
2019-01-13 14:24:58 -05:00
using MediaBrowser.Controller.Net ;
2014-08-10 18:13:17 -04:00
using MediaBrowser.Model.Activity ;
using MediaBrowser.Model.Querying ;
2016-10-25 15:02:04 -04:00
using MediaBrowser.Model.Services ;
2019-11-17 17:05:39 -05:00
using Microsoft.Extensions.Logging ;
2014-08-10 18:13:17 -04:00
namespace MediaBrowser.Api.System
{
[Route("/System/ActivityLog/Entries", "GET", Summary = "Gets activity log entries")]
public class GetActivityLogs : IReturn < QueryResult < ActivityLogEntry > >
{
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[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 ; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[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 ; }
2014-08-14 09:24:30 -04:00
2018-09-12 13:26:21 -04:00
[ApiMember(Name = "MinDate", Description = "Optional. The minimum date. Format = ISO", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
2014-08-14 09:24:30 -04:00
public string MinDate { get ; set ; }
2018-09-12 13:26:21 -04:00
public bool? HasUserId { get ; set ; }
2014-08-10 18:13:17 -04:00
}
2014-11-14 21:31:03 -05:00
[Authenticated(Roles = "Admin")]
2014-08-10 18:13:17 -04:00
public class ActivityLogService : BaseApiService
{
private readonly IActivityManager _activityManager ;
2019-11-17 17:05:39 -05:00
public ActivityLogService (
ILogger < ActivityLogService > logger ,
IServerConfigurationManager serverConfigurationManager ,
IHttpResultFactory httpResultFactory ,
IActivityManager activityManager )
: base ( logger , serverConfigurationManager , httpResultFactory )
2014-08-10 18:13:17 -04:00
{
_activityManager = activityManager ;
}
public object Get ( GetActivityLogs request )
{
2014-08-14 09:24:30 -04:00
DateTime ? minDate = string . IsNullOrWhiteSpace ( request . MinDate ) ?
( DateTime ? ) null :
DateTime . Parse ( request . MinDate , null , DateTimeStyles . RoundtripKind ) . ToUniversalTime ( ) ;
2018-09-12 13:26:21 -04:00
var result = _activityManager . GetActivityLogEntries ( minDate , request . HasUserId , request . StartIndex , request . Limit ) ;
2014-08-10 18:13:17 -04:00
return ToOptimizedResult ( result ) ;
}
}
}