aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Reports
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2015-02-09 16:58:30 -0500
committerLuke <luke.pulverenti@gmail.com>2015-02-09 16:58:30 -0500
commit4cc3b2f0ccd7c092a4acf72db4903415e175037a (patch)
treef9f90f8665b726253b8b357674f2f141aa43abc9 /MediaBrowser.Api/Reports
parente7037a9b80843c127712f11430239f8fa3cb4aed (diff)
parent3d7089a7dbabb652730c892206ca050f52f832b1 (diff)
Merge pull request #1005 from MediaBrowser/dev
3.0.5518.0
Diffstat (limited to 'MediaBrowser.Api/Reports')
-rw-r--r--MediaBrowser.Api/Reports/ReportFieldType.cs9
-rw-r--r--MediaBrowser.Api/Reports/ReportRequests.cs33
-rw-r--r--MediaBrowser.Api/Reports/ReportResult.cs16
-rw-r--r--MediaBrowser.Api/Reports/ReportsService.cs64
4 files changed, 122 insertions, 0 deletions
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<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 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<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 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<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;
+ }
+ }
+}