using System;
using System.Linq;
using Jellyfin.Api.Constants;
using Jellyfin.Data.Entities;
using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api.Controllers
{
///
/// Activity log controller.
///
[Route("System/ActivityLog")]
[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. Filter log entries if it has user id, or not.
/// Activity log returned.
/// A containing the log entries.
[HttpGet("Entries")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult> GetLogEntries(
[FromQuery] int? startIndex,
[FromQuery] int? limit,
[FromQuery] DateTime? minDate,
[FromQuery] bool? hasUserId)
{
var filterFunc = new Func, IQueryable>(
entries => entries.Where(entry => entry.DateCreated >= minDate
&& (!hasUserId.HasValue || (hasUserId.Value
? entry.UserId != Guid.Empty
: entry.UserId == Guid.Empty))));
return _activityManager.GetPagedResult(filterFunc, startIndex, limit);
}
}
}