aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/System/ActivityLogService.cs
blob: 0a5fc9433b6ff17c173d6b46db34ffd233cc722d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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<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; }

        [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<ActivityLogService> 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.GetPagedResult(request.StartIndex, request.Limit);

            return ToOptimizedResult(result);
        }
    }
}