From 0d15e1d631a220f2d1288ad9632e3cfaa8ede479 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 24 Apr 2013 10:30:12 -0400 Subject: [PATCH] added IsOnTour artists filter --- .../UserLibrary/ArtistsService.cs | 25 +++++++++++++++++++ .../UserLibrary/BaseItemsByNameService.cs | 2 +- MediaBrowser.Model/MediaBrowser.Model.csproj | 2 ++ MediaBrowser.Model/Querying/ArtistsQuery.cs | 15 +++++++++++ MediaBrowser.Model/Querying/ItemQuery.cs | 7 ++++++ .../Querying/ItemsByNameQuery.cs | 7 ------ MediaBrowser.Model/Querying/PersonsQuery.cs | 23 +++++++++++++++++ 7 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 MediaBrowser.Model/Querying/ArtistsQuery.cs create mode 100644 MediaBrowser.Model/Querying/PersonsQuery.cs diff --git a/MediaBrowser.Api/UserLibrary/ArtistsService.cs b/MediaBrowser.Api/UserLibrary/ArtistsService.cs index c5f7f492a..ad1007a31 100644 --- a/MediaBrowser.Api/UserLibrary/ArtistsService.cs +++ b/MediaBrowser.Api/UserLibrary/ArtistsService.cs @@ -20,6 +20,11 @@ namespace MediaBrowser.Api.UserLibrary [Api(Description = "Gets all artists from a given item, folder, or the entire library")] public class GetArtists : GetItemsByName { + /// + /// Filter by artists that are on tour, or not + /// + /// null if [is on tour] contains no value, true if [is on tour]; otherwise, false. + public bool? IsOnTour { get; set; } } /// @@ -148,6 +153,26 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(result); } + /// + /// Filters the items. + /// + /// The request. + /// The items. + /// IEnumerable{BaseItem}. + protected override IEnumerable FilterItems(GetItemsByName request, IEnumerable items) + { + items = base.FilterItems(request, items); + + var getArtists = (GetArtists) request; + + if (getArtists.IsOnTour.HasValue) + { + items = items.OfType().Where(i => i.IsOnTour == getArtists.IsOnTour.Value); + } + + return items; + } + /// /// Gets all items. /// diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs index 8f2264c6a..7305dfe3b 100644 --- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs +++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs @@ -204,7 +204,7 @@ namespace MediaBrowser.Api.UserLibrary /// The request. /// The items. /// IEnumerable{BaseItem}. - private IEnumerable FilterItems(GetItemsByName request, IEnumerable items) + protected virtual IEnumerable FilterItems(GetItemsByName request, IEnumerable items) { // Exclude item types if (!string.IsNullOrEmpty(request.ExcludeItemTypes)) diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index e60fe9c2d..41aa86693 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -50,6 +50,7 @@ + @@ -82,6 +83,7 @@ + diff --git a/MediaBrowser.Model/Querying/ArtistsQuery.cs b/MediaBrowser.Model/Querying/ArtistsQuery.cs new file mode 100644 index 000000000..4d52eaf4b --- /dev/null +++ b/MediaBrowser.Model/Querying/ArtistsQuery.cs @@ -0,0 +1,15 @@ + +namespace MediaBrowser.Model.Querying +{ + /// + /// Class ArtistsQuery + /// + public class ArtistsQuery : ItemsByNameQuery + { + /// + /// Filter by artists that are on tour, or not + /// + /// null if [is on tour] contains no value, true if [is on tour]; otherwise, false. + public bool? IsOnTour { get; set; } + } +} diff --git a/MediaBrowser.Model/Querying/ItemQuery.cs b/MediaBrowser.Model/Querying/ItemQuery.cs index 80ec350a7..dfb2cad74 100644 --- a/MediaBrowser.Model/Querying/ItemQuery.cs +++ b/MediaBrowser.Model/Querying/ItemQuery.cs @@ -38,6 +38,12 @@ namespace MediaBrowser.Model.Querying /// The sort by. public string[] SortBy { get; set; } + /// + /// Filter by artists + /// + /// The artists. + public string[] Artists { get; set; } + /// /// The sort order to return results with /// @@ -194,6 +200,7 @@ namespace MediaBrowser.Model.Querying Years = new int[] { }; PersonTypes = new string[] { }; Ids = new string[] { }; + Artists = new string[] { }; ImageTypes = new ImageType[] { }; AirDays = new DayOfWeek[] { }; diff --git a/MediaBrowser.Model/Querying/ItemsByNameQuery.cs b/MediaBrowser.Model/Querying/ItemsByNameQuery.cs index 4569e32c0..354bc0e0f 100644 --- a/MediaBrowser.Model/Querying/ItemsByNameQuery.cs +++ b/MediaBrowser.Model/Querying/ItemsByNameQuery.cs @@ -42,11 +42,6 @@ namespace MediaBrowser.Model.Querying /// /// The fields. public ItemFields[] Fields { get; set; } - /// - /// Gets or sets the person types. - /// - /// The person types. - public string[] PersonTypes { get; set; } /// /// Initializes a new instance of the class. @@ -54,8 +49,6 @@ namespace MediaBrowser.Model.Querying public ItemsByNameQuery() { Fields = new ItemFields[] {}; - - PersonTypes = new string[] {}; } } } diff --git a/MediaBrowser.Model/Querying/PersonsQuery.cs b/MediaBrowser.Model/Querying/PersonsQuery.cs new file mode 100644 index 000000000..a4b7eab71 --- /dev/null +++ b/MediaBrowser.Model/Querying/PersonsQuery.cs @@ -0,0 +1,23 @@ + +namespace MediaBrowser.Model.Querying +{ + /// + /// Class PersonsQuery + /// + public class PersonsQuery : ItemsByNameQuery + { + /// + /// Gets or sets the person types. + /// + /// The person types. + public string[] PersonTypes { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public PersonsQuery() + { + PersonTypes = new string[] { }; + } + } +}