stub out reports api

This commit is contained in:
Luke Pulverenti 2015-02-06 22:25:39 -05:00
parent 504e2099e2
commit 49def5de6a
5 changed files with 126 additions and 0 deletions

View file

@ -82,6 +82,10 @@
<Compile Include="Playback\Hls\MpegDashService.cs" />
<Compile Include="Playback\MediaInfoService.cs" />
<Compile Include="PlaylistService.cs" />
<Compile Include="Reports\ReportFieldType.cs" />
<Compile Include="Reports\ReportResult.cs" />
<Compile Include="Reports\ReportsService.cs" />
<Compile Include="Reports\ReportRequests.cs" />
<Compile Include="StartupWizardService.cs" />
<Compile Include="Subtitles\SubtitleService.cs" />
<Compile Include="Movies\CollectionService.cs" />

View file

@ -0,0 +1,9 @@

namespace MediaBrowser.Api.Reports
{
public enum ReportFieldType
{
String,
Boolean
}
}

View file

@ -0,0 +1,33 @@
using ServiceStack;
namespace MediaBrowser.Api.Reports
{
public class BaseReportRequest : IReturn<ReportResult>
{
/// <summary>
/// Specify this to localize the search to a specific item or folder. Omit to use the root.
/// </summary>
/// <value>The parent id.</value>
[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; }
/// <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; }
}
[Route("/Reports/Items", "GET", Summary = "Gets reports based on library items")]
public class GetItemReport : BaseReportRequest
{
}
}

View file

@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace MediaBrowser.Api.Reports
{
public class ReportResult
{
public List<List<string>> Rows { get; set; }
public List<ReportFieldType> Columns { get; set; }
public ReportResult()
{
Rows = new List<List<string>>();
Columns = new List<ReportFieldType>();
}
}
}

View file

@ -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<object> Get(GetItemReport request)
{
var queryResult = await GetQueryResult(request).ConfigureAwait(false);
var reportResult = GetReportResult(queryResult);
return ToOptimizedResult(reportResult);
}
private ReportResult GetReportResult(QueryResult<BaseItem> queryResult)
{
var reportResult = new ReportResult();
// Fill rows and columns
return reportResult;
}
private Task<QueryResult<BaseItem>> 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;
}
}
}