From 5c6ec34a9cff0819957fe5e4278f6e0d1ecc1fa3 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Fri, 17 Aug 2012 12:47:35 -0400 Subject: [PATCH] Consolidated handlers that return lists of items. Renamed ApiBaseItemWrapper to ApiBaseItemContainer. Added Person and Studio DTO's to BaseItemWrapper --- MediaBrowser.Api/ApiService.cs | 44 +++++++++++++- .../HttpHandlers/GenresHandler.cs | 4 +- .../HttpHandlers/InProgressItemsHandler.cs | 19 ------ MediaBrowser.Api/HttpHandlers/ItemHandler.cs | 4 +- .../HttpHandlers/ItemListHandler.cs | 59 +++++++++++++++++-- .../HttpHandlers/ItemsWithGenreHandler.cs | 22 ------- .../HttpHandlers/ItemsWithPersonHandler.cs | 32 ---------- .../HttpHandlers/ItemsWithStudioHandler.cs | 22 ------- .../HttpHandlers/ItemsWithYearHandler.cs | 22 ------- .../HttpHandlers/RecentlyAddedItemsHandler.cs | 24 -------- .../HttpHandlers/StudiosHandler.cs | 4 +- .../HttpHandlers/UserConfigurationHandler.cs | 17 ------ MediaBrowser.Api/HttpHandlers/YearsHandler.cs | 4 +- MediaBrowser.Api/MediaBrowser.Api.csproj | 7 --- MediaBrowser.Api/Plugin.cs | 28 +-------- MediaBrowser.ApiInteraction/ApiClient.cs | 58 +++++++----------- .../Configuration/ServerConfiguration.cs | 27 --------- MediaBrowser.Controller/Kernel.cs | 34 +++++------ .../Configuration/UserConfiguration.cs | 16 ----- MediaBrowser.Model/DTO/ApiBaseItem.cs | 13 ++-- MediaBrowser.Model/DTO/CategoryInfo.cs | 19 ------ MediaBrowser.Model/DTO/IBNItem.cs | 38 ++++++++++++ MediaBrowser.Model/Entities/Person.cs | 1 - MediaBrowser.Model/MediaBrowser.Model.csproj | 3 +- MediaBrowser.Model/Users/User.cs | 7 +++ 25 files changed, 195 insertions(+), 333 deletions(-) delete mode 100644 MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs delete mode 100644 MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs delete mode 100644 MediaBrowser.Model/Configuration/UserConfiguration.cs delete mode 100644 MediaBrowser.Model/DTO/CategoryInfo.cs create mode 100644 MediaBrowser.Model/DTO/IBNItem.cs diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs index e4a7f71bf5..25a7ff9ec1 100644 --- a/MediaBrowser.Api/ApiService.cs +++ b/MediaBrowser.Api/ApiService.cs @@ -24,9 +24,9 @@ namespace MediaBrowser.Api /// /// Takes a BaseItem and returns the actual object that will be serialized by the api /// - public static BaseItemWrapper GetSerializationObject(BaseItem item, bool includeChildren, Guid userId) + public static BaseItemContainer GetSerializationObject(BaseItem item, bool includeChildren, Guid userId) { - BaseItemWrapper wrapper = new BaseItemWrapper() + BaseItemContainer wrapper = new BaseItemContainer() { Item = item, UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id), @@ -60,7 +60,45 @@ namespace MediaBrowser.Api wrapper.Children = Kernel.Instance.GetParentalAllowedChildren(folder, userId).Select(c => GetSerializationObject(c, false, userId)); } - wrapper.People = item.People; + // Attach People by transforming them into BaseItemPerson (DTO) + if (item.People != null) + { + wrapper.People = item.People.Select(p => + { + BaseItemPerson baseItemPerson = new BaseItemPerson(); + + baseItemPerson.PersonInfo = p; + + Person ibnObject = Kernel.Instance.ItemController.GetPerson(p.Name); + + if (ibnObject != null) + { + baseItemPerson.PrimaryImagePath = ibnObject.PrimaryImagePath; + } + + return baseItemPerson; + }); + } + } + + // Attach Studios by transforming them into BaseItemStudio (DTO) + if (item.Studios != null) + { + wrapper.Studios = item.Studios.Select(s => + { + BaseItemStudio baseItemStudio = new BaseItemStudio(); + + baseItemStudio.Name = s; + + Studio ibnObject = Kernel.Instance.ItemController.GetStudio(s); + + if (ibnObject != null) + { + baseItemStudio.PrimaryImagePath = ibnObject.PrimaryImagePath; + } + + return baseItemStudio; + }); } return wrapper; diff --git a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs index c3292d3633..902871fa11 100644 --- a/MediaBrowser.Api/HttpHandlers/GenresHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/GenresHandler.cs @@ -7,9 +7,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class GenresHandler : BaseJsonHandler>> + public class GenresHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs b/MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs deleted file mode 100644 index 2bee275a45..0000000000 --- a/MediaBrowser.Api/HttpHandlers/InProgressItemsHandler.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - class InProgressItemsHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetInProgressItems(parent, UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs index efb67db54e..3df8e914fb 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemHandler.cs @@ -5,9 +5,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class ItemHandler : BaseJsonHandler> + public class ItemHandler : BaseJsonHandler> { - protected sealed override BaseItemWrapper GetObjectToSerialize() + protected sealed override BaseItemContainer GetObjectToSerialize() { Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs index 6e08561b23..b3d85687fe 100644 --- a/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/ItemListHandler.cs @@ -2,14 +2,15 @@ using System.Collections.Generic; using System.Linq; using MediaBrowser.Common.Net.Handlers; +using MediaBrowser.Controller; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public abstract class ItemListHandler : BaseJsonHandler>> + public class ItemListHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { return ItemsToSerialize.Select(i => { @@ -18,9 +19,51 @@ namespace MediaBrowser.Api.HttpHandlers }); } - protected abstract IEnumerable ItemsToSerialize + protected IEnumerable ItemsToSerialize { - get; + get + { + Folder parent = ApiService.GetItemById(ItemId) as Folder; + + if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetInProgressItems(parent, UserId); + } + else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetRecentlyAddedItems(parent, UserId); + } + else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetRecentlyAddedUnplayedItems(parent, UserId); + } + else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithGenre(parent, QueryString["name"], UserId); + } + else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithYear(parent, int.Parse(QueryString["year"]), UserId); + } + else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithStudio(parent, QueryString["name"], UserId); + } + else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase)) + { + return Kernel.Instance.GetItemsWithPerson(parent, QueryString["name"], UserId); + } + + throw new InvalidOperationException(); + } + } + + protected string ItemId + { + get + { + return QueryString["id"]; + } } protected Guid UserId @@ -30,5 +73,13 @@ namespace MediaBrowser.Api.HttpHandlers return Guid.Parse(QueryString["userid"]); } } + + private string ListType + { + get + { + return QueryString["listtype"] ?? string.Empty; + } + } } } diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs deleted file mode 100644 index 16bb561967..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithGenreHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within a Genre - /// - public class ItemsWithGenreHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetItemsWithGenre(parent, QueryString["name"], UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs deleted file mode 100644 index 624abc7620..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithPersonHandler.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within containing a person - /// - public class ItemsWithPersonHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - PersonType? personType = null; - - string type = QueryString["persontype"]; - - if (!string.IsNullOrEmpty(type)) - { - personType = (PersonType)Enum.Parse(typeof(PersonType), type, true); - } - - return Kernel.Instance.GetItemsWithPerson(parent, QueryString["name"], personType, UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs deleted file mode 100644 index 30120d5248..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithStudioHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within containing a studio - /// - public class ItemsWithStudioHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetItemsWithStudio(parent, QueryString["name"], UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs b/MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs deleted file mode 100644 index d5d4df4446..0000000000 --- a/MediaBrowser.Api/HttpHandlers/ItemsWithYearHandler.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - /// - /// Gets all items within containing a studio - /// - public class ItemsWithYearHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - return Kernel.Instance.GetItemsWithYear(parent, int.Parse(QueryString["name"]), UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs b/MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs deleted file mode 100644 index f36c9c9975..0000000000 --- a/MediaBrowser.Api/HttpHandlers/RecentlyAddedItemsHandler.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Collections.Generic; -using MediaBrowser.Controller; -using MediaBrowser.Model.Entities; - -namespace MediaBrowser.Api.HttpHandlers -{ - class RecentlyAddedItemsHandler : ItemListHandler - { - protected override IEnumerable ItemsToSerialize - { - get - { - Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; - - if (QueryString["unplayed"] == "1") - { - return Kernel.Instance.GetRecentlyAddedUnplayedItems(parent, UserId); - } - - return Kernel.Instance.GetRecentlyAddedItems(parent, UserId); - } - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs index b1be2cad2a..b33988b3ec 100644 --- a/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/StudiosHandler.cs @@ -7,9 +7,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class StudiosHandler : BaseJsonHandler>> + public class StudiosHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs deleted file mode 100644 index 12e80f3060..0000000000 --- a/MediaBrowser.Api/HttpHandlers/UserConfigurationHandler.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using MediaBrowser.Common.Net.Handlers; -using MediaBrowser.Controller; -using MediaBrowser.Model.Configuration; - -namespace MediaBrowser.Api.HttpHandlers -{ - public class UserConfigurationHandler : BaseJsonHandler - { - protected override UserConfiguration GetObjectToSerialize() - { - Guid userId = Guid.Parse(QueryString["userid"]); - - return Kernel.Instance.GetUserConfiguration(userId); - } - } -} diff --git a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs index cc34748805..8a58a2a19d 100644 --- a/MediaBrowser.Api/HttpHandlers/YearsHandler.cs +++ b/MediaBrowser.Api/HttpHandlers/YearsHandler.cs @@ -7,9 +7,9 @@ using MediaBrowser.Model.Entities; namespace MediaBrowser.Api.HttpHandlers { - public class YearsHandler : BaseJsonHandler>> + public class YearsHandler : BaseJsonHandler>> { - protected override IEnumerable> GetObjectToSerialize() + protected override IEnumerable> GetObjectToSerialize() { Folder parent = ApiService.GetItemById(QueryString["id"]) as Folder; Guid userId = Guid.Parse(QueryString["userid"]); diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index e6a1816f6d..4b6b6aa1a2 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -49,23 +49,16 @@ - - - - - - - diff --git a/MediaBrowser.Api/Plugin.cs b/MediaBrowser.Api/Plugin.cs index 6bfdd5134a..659763c5fc 100644 --- a/MediaBrowser.Api/Plugin.cs +++ b/MediaBrowser.Api/Plugin.cs @@ -49,46 +49,22 @@ namespace MediaBrowser.Api { return new UsersHandler(); } - else if (localPath.EndsWith("/api/itemswithgenre", StringComparison.OrdinalIgnoreCase)) + else if (localPath.EndsWith("/api/itemlist", StringComparison.OrdinalIgnoreCase)) { - return new ItemsWithGenreHandler(); + return new ItemListHandler(); } else if (localPath.EndsWith("/api/genres", StringComparison.OrdinalIgnoreCase)) { return new GenresHandler(); } - else if (localPath.EndsWith("/api/itemswithyear", StringComparison.OrdinalIgnoreCase)) - { - return new ItemsWithYearHandler(); - } - else if (localPath.EndsWith("/api/itemswithperson", StringComparison.OrdinalIgnoreCase)) - { - return new ItemsWithPersonHandler(); - } else if (localPath.EndsWith("/api/years", StringComparison.OrdinalIgnoreCase)) { return new YearsHandler(); } - else if (localPath.EndsWith("/api/itemswithstudio", StringComparison.OrdinalIgnoreCase)) - { - return new ItemsWithStudioHandler(); - } else if (localPath.EndsWith("/api/studios", StringComparison.OrdinalIgnoreCase)) { return new StudiosHandler(); } - else if (localPath.EndsWith("/api/recentlyaddeditems", StringComparison.OrdinalIgnoreCase)) - { - return new RecentlyAddedItemsHandler(); - } - else if (localPath.EndsWith("/api/inprogressitems", StringComparison.OrdinalIgnoreCase)) - { - return new InProgressItemsHandler(); - } - else if (localPath.EndsWith("/api/userconfiguration", StringComparison.OrdinalIgnoreCase)) - { - return new UserConfigurationHandler(); - } else if (localPath.EndsWith("/api/plugins", StringComparison.OrdinalIgnoreCase)) { return new PluginsHandler(); diff --git a/MediaBrowser.ApiInteraction/ApiClient.cs b/MediaBrowser.ApiInteraction/ApiClient.cs index 7818dbdf8b..af79513e09 100644 --- a/MediaBrowser.ApiInteraction/ApiClient.cs +++ b/MediaBrowser.ApiInteraction/ApiClient.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Users; @@ -91,7 +90,7 @@ namespace MediaBrowser.ApiInteraction /// Use if a max width is required. Aspect ratio will be preserved. /// Use if a max height is required. Aspect ratio will be preserved. /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. - public IEnumerable GetBackdropImageUrls(BaseItemWrapper itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + public IEnumerable GetBackdropImageUrls(ApiBaseItemContainer itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) { Guid? backdropItemId = null; int backdropCount = 0; @@ -131,7 +130,7 @@ namespace MediaBrowser.ApiInteraction /// Use if a max width is required. Aspect ratio will be preserved. /// Use if a max height is required. Aspect ratio will be preserved. /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. - public string GetLogoImageUrl(BaseItemWrapper itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) + public string GetLogoImageUrl(ApiBaseItemContainer itemWrapper, int? width = null, int? height = null, int? maxWidth = null, int? maxHeight = null, int? quality = null) { Guid? logoItemId = !string.IsNullOrEmpty(itemWrapper.Item.LogoImagePath) ? itemWrapper.Item.Id : itemWrapper.ParentLogoItemId; @@ -154,7 +153,7 @@ namespace MediaBrowser.ApiInteraction /// /// Gets a BaseItem /// - public async Task> GetItemAsync(Guid id, Guid userId) + public async Task GetItemAsync(Guid id, Guid userId) { string url = ApiUrl + "/item?userId=" + userId.ToString(); @@ -165,7 +164,7 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>(stream); + return JsonSerializer.DeserializeFromStream(stream); } } @@ -185,61 +184,61 @@ namespace MediaBrowser.ApiInteraction /// /// Gets all Genres /// - public async Task>> GetAllGenresAsync(Guid userId) + public async Task>> GetAllGenresAsync(Guid userId) { string url = ApiUrl + "/genres?userId=" + userId.ToString(); using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>>(stream); } } /// /// Gets all Years /// - public async Task>> GetAllYearsAsync(Guid userId) + public async Task>> GetAllYearsAsync(Guid userId) { string url = ApiUrl + "/years?userId=" + userId.ToString(); using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>>(stream); } } /// /// Gets all items that contain a given Year /// - public async Task>> GetItemsWithYearAsync(string name, Guid userId) + public async Task> GetItemsWithYearAsync(string name, Guid userId) { - string url = ApiUrl + "/itemswithyear?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithyear&userId=" + userId.ToString() + "&name=" + name; using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } /// /// Gets all items that contain a given Genre /// - public async Task>> GetItemsWithGenreAsync(string name, Guid userId) + public async Task> GetItemsWithGenreAsync(string name, Guid userId) { - string url = ApiUrl + "/itemswithgenre?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithgenre&userId=" + userId.ToString() + "&name=" + name; using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } /// /// Gets all items that contain a given Person /// - public async Task>> GetItemsWithPersonAsync(string name, PersonType? personType, Guid userId) + public async Task> GetItemsWithPersonAsync(string name, PersonType? personType, Guid userId) { - string url = ApiUrl + "/itemswithperson?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithperson&userId=" + userId.ToString() + "&name=" + name; if (personType.HasValue) { @@ -248,46 +247,33 @@ namespace MediaBrowser.ApiInteraction using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } /// /// Gets all studious /// - public async Task>> GetAllStudiosAsync(Guid userId) + public async Task>> GetAllStudiosAsync(Guid userId) { string url = ApiUrl + "/studios?userId=" + userId.ToString(); using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); - } - } - - /// - /// Gets the current personalized configuration - /// - public async Task GetUserConfigurationAsync(Guid userId) - { - string url = ApiUrl + "/userconfiguration?userId=" + userId.ToString(); - - using (Stream stream = await HttpClient.GetStreamAsync(url)) - { - return JsonSerializer.DeserializeFromStream(stream); + return JsonSerializer.DeserializeFromStream>>(stream); } } /// /// Gets all items that contain a given Studio /// - public async Task>> GetItemsWithStudioAsync(string name, Guid userId) + public async Task> GetItemsWithStudioAsync(string name, Guid userId) { - string url = ApiUrl + "/itemswithstudio?userId=" + userId.ToString() + "&name=" + name; + string url = ApiUrl + "/itemlist?listtype=itemswithstudio&userId=" + userId.ToString() + "&name=" + name; using (Stream stream = await HttpClient.GetStreamAsync(url)) { - return JsonSerializer.DeserializeFromStream>>(stream); + return JsonSerializer.DeserializeFromStream>(stream); } } diff --git a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs index 56f3a854fa..88d1012b18 100644 --- a/MediaBrowser.Controller/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Controller/Configuration/ServerConfiguration.cs @@ -1,37 +1,10 @@ using System.Collections.Generic; using MediaBrowser.Common.Configuration; -using MediaBrowser.Model.Configuration; namespace MediaBrowser.Controller.Configuration { public class ServerConfiguration : BaseApplicationConfiguration { public string ImagesByNamePath { get; set; } - - /// - /// Gets or sets the default UI configuration - /// - public UserConfiguration DefaultUserConfiguration { get; set; } - - /// - /// Gets or sets a list of registered UI device names - /// - public List DeviceNames { get; set; } - - /// - /// Gets or sets all available UIConfigurations - /// The key contains device name and user id - /// - public Dictionary UserConfigurations { get; set; } - - public ServerConfiguration() - : base() - { - DefaultUserConfiguration = new UserConfiguration(); - - UserConfigurations = new Dictionary(); - - DeviceNames = new List(); - } } } diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index ef9a07814b..375b11a593 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -12,7 +12,6 @@ using MediaBrowser.Controller.Events; using MediaBrowser.Controller.IO; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Resolvers; -using MediaBrowser.Model.Configuration; using MediaBrowser.Model.DTO; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Progress; @@ -155,11 +154,6 @@ namespace MediaBrowser.Controller } } - public UserConfiguration GetUserConfiguration(Guid userId) - { - return Configuration.DefaultUserConfiguration; - } - public void ReloadItem(BaseItem item) { Folder folder = item as Folder; @@ -263,9 +257,9 @@ namespace MediaBrowser.Controller { DateTime now = DateTime.Now; - UserConfiguration config = GetUserConfiguration(userId); + User user = Users.First(u => u.Id == userId); - return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < config.RecentItemDays); + return GetParentalAllowedRecursiveChildren(parent, userId).Where(i => !(i is Folder) && (now - i.DateCreated).TotalDays < user.RecentItemDays); } /// @@ -358,7 +352,7 @@ namespace MediaBrowser.Controller /// Gets all years from all recursive children of a folder /// The CategoryInfo class is used to keep track of the number of times each year appears /// - public IEnumerable> GetAllYears(Folder parent, Guid userId) + public IEnumerable> GetAllYears(Folder parent, Guid userId) { Dictionary data = new Dictionary(); @@ -385,7 +379,7 @@ namespace MediaBrowser.Controller } // Now go through the dictionary and create a Category for each studio - List> list = new List>(); + List> list = new List>(); foreach (int key in data.Keys) { @@ -394,10 +388,10 @@ namespace MediaBrowser.Controller if (entity != null) { - list.Add(new CategoryInfo() + list.Add(new IBNItem() { Item = entity, - ItemCount = data[key] + BaseItemCount = data[key] }); } } @@ -409,7 +403,7 @@ namespace MediaBrowser.Controller /// Gets all studios from all recursive children of a folder /// The CategoryInfo class is used to keep track of the number of times each studio appears /// - public IEnumerable> GetAllStudios(Folder parent, Guid userId) + public IEnumerable> GetAllStudios(Folder parent, Guid userId) { Dictionary data = new Dictionary(); @@ -439,7 +433,7 @@ namespace MediaBrowser.Controller } // Now go through the dictionary and create a Category for each studio - List> list = new List>(); + List> list = new List>(); foreach (string key in data.Keys) { @@ -448,10 +442,10 @@ namespace MediaBrowser.Controller if (entity != null) { - list.Add(new CategoryInfo() + list.Add(new IBNItem() { Item = entity, - ItemCount = data[key] + BaseItemCount = data[key] }); } } @@ -463,7 +457,7 @@ namespace MediaBrowser.Controller /// Gets all genres from all recursive children of a folder /// The CategoryInfo class is used to keep track of the number of times each genres appears /// - public IEnumerable> GetAllGenres(Folder parent, Guid userId) + public IEnumerable> GetAllGenres(Folder parent, Guid userId) { Dictionary data = new Dictionary(); @@ -493,7 +487,7 @@ namespace MediaBrowser.Controller } // Now go through the dictionary and create a Category for each genre - List> list = new List>(); + List> list = new List>(); foreach (string key in data.Keys) { @@ -502,10 +496,10 @@ namespace MediaBrowser.Controller if (entity != null) { - list.Add(new CategoryInfo() + list.Add(new IBNItem() { Item = entity, - ItemCount = data[key] + BaseItemCount = data[key] }); } } diff --git a/MediaBrowser.Model/Configuration/UserConfiguration.cs b/MediaBrowser.Model/Configuration/UserConfiguration.cs deleted file mode 100644 index 5616f6dd60..0000000000 --- a/MediaBrowser.Model/Configuration/UserConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ - -namespace MediaBrowser.Model.Configuration -{ - /// - /// This holds settings that can be personalized on a per-user, per-device basis. - /// - public class UserConfiguration - { - public int RecentItemDays { get; set; } - - public UserConfiguration() - { - RecentItemDays = 14; - } - } -} diff --git a/MediaBrowser.Model/DTO/ApiBaseItem.cs b/MediaBrowser.Model/DTO/ApiBaseItem.cs index d6b0f4a047..eca45c9f8b 100644 --- a/MediaBrowser.Model/DTO/ApiBaseItem.cs +++ b/MediaBrowser.Model/DTO/ApiBaseItem.cs @@ -20,14 +20,14 @@ namespace MediaBrowser.Model.DTO /// /// This is the full return object when requesting an Item /// - public class BaseItemWrapper - where T : BaseItem + public class BaseItemContainer + where TItemType : BaseItem { - public T Item { get; set; } + public TItemType Item { get; set; } public UserItemData UserItemData { get; set; } - public IEnumerable> Children { get; set; } + public IEnumerable> Children { get; set; } public bool IsFolder { get; set; } @@ -45,7 +45,8 @@ namespace MediaBrowser.Model.DTO return Type.Equals(type, StringComparison.OrdinalIgnoreCase); } - public IEnumerable People { get; set; } + public IEnumerable People { get; set; } + public IEnumerable Studios { get; set; } /// /// If the item does not have a logo, this will hold the Id of the Parent that has one. @@ -60,7 +61,7 @@ namespace MediaBrowser.Model.DTO /// /// This is strictly for convenience so the UI's don't have to use the verbose generic syntax of BaseItemWrapper /// - public class ApiBaseItemWrapper : BaseItemWrapper + public class ApiBaseItemContainer : BaseItemContainer { } } diff --git a/MediaBrowser.Model/DTO/CategoryInfo.cs b/MediaBrowser.Model/DTO/CategoryInfo.cs deleted file mode 100644 index e6b2aeafb0..0000000000 --- a/MediaBrowser.Model/DTO/CategoryInfo.cs +++ /dev/null @@ -1,19 +0,0 @@ - -namespace MediaBrowser.Model.DTO -{ - /// - /// This is a stub class used by the api to get IBN types along with their item counts - /// - public class CategoryInfo - { - /// - /// The actual genre, year, studio, etc - /// - public T Item { get; set; } - - /// - /// The number of items that have the genre, year, studio, etc - /// - public int ItemCount { get; set; } - } -} diff --git a/MediaBrowser.Model/DTO/IBNItem.cs b/MediaBrowser.Model/DTO/IBNItem.cs new file mode 100644 index 0000000000..8a0620767f --- /dev/null +++ b/MediaBrowser.Model/DTO/IBNItem.cs @@ -0,0 +1,38 @@ +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Model.DTO +{ + /// + /// This is a stub class used by the api to get IBN types along with their item counts + /// + public class IBNItem + { + /// + /// The actual genre, year, studio, etc + /// + public T Item { get; set; } + + /// + /// The number of items that have the genre, year, studio, etc + /// + public int BaseItemCount { get; set; } + } + + /// + /// This is used by BaseItemContainer + /// + public class BaseItemPerson + { + public PersonInfo PersonInfo { get; set; } + public string PrimaryImagePath { get; set; } + } + + /// + /// This is used by BaseItemContainer + /// + public class BaseItemStudio + { + public string Name { get; set; } + public string PrimaryImagePath { get; set; } + } +} diff --git a/MediaBrowser.Model/Entities/Person.cs b/MediaBrowser.Model/Entities/Person.cs index 690a2de857..e85f8a9050 100644 --- a/MediaBrowser.Model/Entities/Person.cs +++ b/MediaBrowser.Model/Entities/Person.cs @@ -6,7 +6,6 @@ namespace MediaBrowser.Model.Entities /// public class Person : BaseEntity { - public PersonType PersonType { get; set; } } /// diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index dd9034ed56..14c7843edf 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -32,12 +32,11 @@ 4 - - + diff --git a/MediaBrowser.Model/Users/User.cs b/MediaBrowser.Model/Users/User.cs index 63698dc857..85776fb8b8 100644 --- a/MediaBrowser.Model/Users/User.cs +++ b/MediaBrowser.Model/Users/User.cs @@ -10,5 +10,12 @@ namespace MediaBrowser.Model.Users private Dictionary _ItemData = new Dictionary(); public Dictionary ItemData { get { return _ItemData; } set { _ItemData = value; } } + + public int RecentItemDays { get; set; } + + public User() + { + RecentItemDays = 14; + } } }