From 8fe7dfd4ce39d4bb3d9a96e3ada8783c26e291a2 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 11 Apr 2013 23:50:47 -0400 Subject: added people pages --- .../UserLibrary/BaseItemsByNameService.cs | 34 ++++++++++++++++++++-- MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs | 23 --------------- MediaBrowser.Api/UserLibrary/ItemsService.cs | 25 +++++++++++++++- 3 files changed, 55 insertions(+), 27 deletions(-) (limited to 'MediaBrowser.Api/UserLibrary') diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index ae1e0a3f8..583f7460d 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -64,9 +64,8 @@ namespace MediaBrowser.Api.UserLibrary items = FilterItems(request, items, user); - items = ItemsService.ApplySortOrder(request, items, user, LibraryManager); - - var ibnItemsArray = GetAllItems(request, items, user).ToArray(); + var extractedItems = GetAllItems(request, items, user); + var ibnItemsArray = SortItems(request, extractedItems).ToArray(); IEnumerable>>> ibnItems = ibnItemsArray; @@ -100,6 +99,29 @@ namespace MediaBrowser.Api.UserLibrary return result; } + /// + /// Sorts the items. + /// + /// The request. + /// The items. + /// IEnumerable{BaseItem}. + private IEnumerable>>> SortItems(GetItemsByName request, IEnumerable>>> items) + { + if (string.Equals(request.SortBy, "SortName", StringComparison.OrdinalIgnoreCase)) + { + if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending) + { + items = items.OrderByDescending(i => i.Item1); + } + else + { + items = items.OrderBy(i => i.Item1); + } + } + + return items; + } + /// /// Filters the items. /// @@ -181,5 +203,11 @@ namespace MediaBrowser.Api.UserLibrary /// public class GetItemsByName : BaseItemsRequest, IReturn { + /// + /// What to sort the results by + /// + /// The sort by. + [ApiMember(Name = "SortBy", Description = "Optional. Options: SortName", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + public string SortBy { get; set; } } } diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs index 4975b653a..c9dd86381 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsRequest.cs @@ -16,13 +16,6 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public Guid UserId { get; set; } - /// - /// What to sort the results by - /// - /// The sort by. - [ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, CommunityRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] - public string SortBy { get; set; } - /// /// Skips over a given number of items within the results. Use for paging. /// @@ -117,21 +110,5 @@ namespace MediaBrowser.Api.UserLibrary return val.Split(',').Select(v => (ItemFields)Enum.Parse(typeof(ItemFields), v, true)); } - - /// - /// Gets the order by. - /// - /// IEnumerable{ItemSortBy}. - public IEnumerable GetOrderBy() - { - var val = SortBy; - - if (string.IsNullOrEmpty(val)) - { - return new string[] { }; - } - - return val.Split(','); - } } } diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index 6a86c27f0..dc29ba341 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -25,6 +25,13 @@ namespace MediaBrowser.Api.UserLibrary [ApiMember(Name = "Person", Description = "Optional. If specified, results will be filtered to include only those containing the specified person.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] public string Person { get; set; } + /// + /// What to sort the results by + /// + /// The sort by. + [ApiMember(Name = "SortBy", Description = "Optional. Specify one or more sort orders, comma delimeted. Options: Album, AlbumArtist, Artist, CommunityRating, DateCreated, DatePlayed, PlayCount, PremiereDate, ProductionYear, SortName, Random, Runtime", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] + public string SortBy { get; set; } + /// /// If the Person filter is used, this can also be used to restrict to a specific person type /// @@ -114,6 +121,22 @@ namespace MediaBrowser.Api.UserLibrary /// The air days. [ApiMember(Name = "AirDays", Description = "Optional filter by Series Air Days. Allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)] public string AirDays { get; set; } + + /// + /// Gets the order by. + /// + /// IEnumerable{ItemSortBy}. + public IEnumerable GetOrderBy() + { + var val = SortBy; + + if (string.IsNullOrEmpty(val)) + { + return new string[] { }; + } + + return val.Split(','); + } } /// @@ -238,7 +261,7 @@ namespace MediaBrowser.Api.UserLibrary /// The user. /// The library manager. /// IEnumerable{BaseItem}. - internal static IEnumerable ApplySortOrder(BaseItemsRequest request, IEnumerable items, User user, ILibraryManager libraryManager) + internal static IEnumerable ApplySortOrder(GetItems request, IEnumerable items, User user, ILibraryManager libraryManager) { var orderBy = request.GetOrderBy().ToArray(); -- cgit v1.2.3