diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 23cdf8b7a7..2713059212 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -82,6 +82,10 @@ + + + + diff --git a/MediaBrowser.Api/Reports/ReportFieldType.cs b/MediaBrowser.Api/Reports/ReportFieldType.cs new file mode 100644 index 0000000000..d35c5cb2da --- /dev/null +++ b/MediaBrowser.Api/Reports/ReportFieldType.cs @@ -0,0 +1,9 @@ + +namespace MediaBrowser.Api.Reports +{ + public enum ReportFieldType + { + String, + Boolean + } +} diff --git a/MediaBrowser.Api/Reports/ReportRequests.cs b/MediaBrowser.Api/Reports/ReportRequests.cs new file mode 100644 index 0000000000..8dea003814 --- /dev/null +++ b/MediaBrowser.Api/Reports/ReportRequests.cs @@ -0,0 +1,33 @@ +using ServiceStack; + +namespace MediaBrowser.Api.Reports +{ + public class BaseReportRequest : IReturn + { + /// + /// Specify this to localize the search to a specific item or folder. Omit to use the root. + /// + /// The parent id. + [ApiMember(Name = "ParentId", Description = "Specify this to localize the search to a specific item or folder. Omit to use the root", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string ParentId { get; set; } + + /// + /// 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; } + } + + [Route("/Reports/Items", "GET", Summary = "Gets reports based on library items")] + public class GetItemReport : BaseReportRequest + { + } +} diff --git a/MediaBrowser.Api/Reports/ReportResult.cs b/MediaBrowser.Api/Reports/ReportResult.cs new file mode 100644 index 0000000000..c033ae8fb7 --- /dev/null +++ b/MediaBrowser.Api/Reports/ReportResult.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Api.Reports +{ + public class ReportResult + { + public List> Rows { get; set; } + public List Columns { get; set; } + + public ReportResult() + { + Rows = new List>(); + Columns = new List(); + } + } +} diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs new file mode 100644 index 0000000000..45bc4a8893 --- /dev/null +++ b/MediaBrowser.Api/Reports/ReportsService.cs @@ -0,0 +1,64 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Model.Querying; +using System.Threading.Tasks; + +namespace MediaBrowser.Api.Reports +{ + public class ReportsService : BaseApiService + { + private readonly ILibraryManager _libraryManager; + + public ReportsService(ILibraryManager libraryManager) + { + _libraryManager = libraryManager; + } + + public async Task Get(GetItemReport request) + { + var queryResult = await GetQueryResult(request).ConfigureAwait(false); + + var reportResult = GetReportResult(queryResult); + + return ToOptimizedResult(reportResult); + } + + private ReportResult GetReportResult(QueryResult queryResult) + { + var reportResult = new ReportResult(); + + // Fill rows and columns + + return reportResult; + } + + private Task> GetQueryResult(BaseReportRequest request) + { + // Placeholder in case needed later + User user = null; + + var parentItem = string.IsNullOrEmpty(request.ParentId) ? + (user == null ? _libraryManager.RootFolder : user.RootFolder) : + _libraryManager.GetItemById(request.ParentId); + + return ((Folder)parentItem).GetItems(GetItemsQuery(request, user)); + } + + private InternalItemsQuery GetItemsQuery(BaseReportRequest request, User user) + { + var query = new InternalItemsQuery + { + User = user, + CollapseBoxSetItems = false + }; + + // Set query values based on request + + // Example + //query.IncludeItemTypes = new[] {"Movie"}; + + + return query; + } + } +}