diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-02-06 22:25:39 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-02-06 22:25:39 -0500 |
| commit | 49def5de6a105b2d9ddc91416fc9d6e3c4ab17bd (patch) | |
| tree | a7c896c002dd336a359e531e40254cb2cf5319a1 | |
| parent | 504e2099e2f11203c48dff94a67ec797a454d459 (diff) | |
stub out reports api
| -rw-r--r-- | MediaBrowser.Api/MediaBrowser.Api.csproj | 4 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/ReportFieldType.cs | 9 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/ReportRequests.cs | 33 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/ReportResult.cs | 16 | ||||
| -rw-r--r-- | MediaBrowser.Api/Reports/ReportsService.cs | 64 |
5 files changed, 126 insertions, 0 deletions
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 23cdf8b7a..271305921 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -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" /> diff --git a/MediaBrowser.Api/Reports/ReportFieldType.cs b/MediaBrowser.Api/Reports/ReportFieldType.cs new file mode 100644 index 000000000..d35c5cb2d --- /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 000000000..8dea00381 --- /dev/null +++ b/MediaBrowser.Api/Reports/ReportRequests.cs @@ -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 + { + } +} diff --git a/MediaBrowser.Api/Reports/ReportResult.cs b/MediaBrowser.Api/Reports/ReportResult.cs new file mode 100644 index 000000000..c033ae8fb --- /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<List<string>> Rows { get; set; } + public List<ReportFieldType> Columns { get; set; } + + public ReportResult() + { + Rows = new List<List<string>>(); + Columns = new List<ReportFieldType>(); + } + } +} diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs new file mode 100644 index 000000000..45bc4a889 --- /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<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; + } + } +} |
