From e8f345514c5908282545d9862d2392faaf97d523 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 17 Apr 2013 01:36:56 -0400 Subject: [PATCH] added item by name counts --- .../UserLibrary/PersonsService.cs | 61 ++++++++++++++++++- MediaBrowser.Model/Dto/ItemByNameCounts.cs | 35 +++++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 MediaBrowser.Model/Dto/ItemByNameCounts.cs diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs index fe5cf39f6f..52e241318b 100644 --- a/MediaBrowser.Api/UserLibrary/PersonsService.cs +++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs @@ -1,6 +1,10 @@ using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; using ServiceStack.ServiceHost; using System; using System.Collections.Generic; @@ -23,12 +27,38 @@ namespace MediaBrowser.Api.UserLibrary /// The person types. public string PersonTypes { get; set; } } - + + /// + /// Class GetPersonItemCounts + /// + [Route("/Users/{UserId}/Persons/{Name}/Counts", "GET")] + [Api(Description = "Gets item counts of library items that a person appears in")] + public class GetPersonItemCounts : IReturn + { + /// + /// Gets or sets the user id. + /// + /// The user id. + public Guid UserId { get; set; } + + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + } + /// /// Class PersonsService /// public class PersonsService : BaseItemsByNameService { + /// + /// Initializes a new instance of the class. + /// + /// The user manager. + /// The library manager. + /// The user data repository. public PersonsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository) : base(userManager, libraryManager, userDataRepository) { @@ -46,6 +76,33 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(result); } + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetPersonItemCounts request) + { + var user = UserManager.GetUserById(request.UserId); + + var items = user.RootFolder.GetRecursiveChildren(user).Where(i => i.People != null && i.People.Any(p => string.Equals(p.Name, request.Name, StringComparison.OrdinalIgnoreCase))).ToList(); + + var counts = new ItemByNameCounts + { + TotalCount = items.Count, + + MovieCount = items.OfType().Count(), + + SeriesCount = items.OfType().Count(), + + GameCount = items.OfType().Count(), + + EpisodeGuestStarCount = items.OfType().Count(i => i.People.Any(p => string.Equals(p.Name, request.Name, StringComparison.OrdinalIgnoreCase) && string.Equals(p.Type, PersonType.GuestStar))) + }; + + return ToOptimizedResult(counts); + } + /// /// Gets all items. /// @@ -55,7 +112,7 @@ namespace MediaBrowser.Api.UserLibrary /// IEnumerable{Tuple{System.StringFunc{System.Int32}}}. protected override IEnumerable> GetAllItems(GetItemsByName request, IEnumerable items, User user) { - var inputPersonTypes = ((GetPersons) request).PersonTypes; + var inputPersonTypes = ((GetPersons)request).PersonTypes; var personTypes = string.IsNullOrEmpty(inputPersonTypes) ? new string[] { } : inputPersonTypes.Split(','); var itemsList = items.Where(i => i.People != null).ToList(); diff --git a/MediaBrowser.Model/Dto/ItemByNameCounts.cs b/MediaBrowser.Model/Dto/ItemByNameCounts.cs new file mode 100644 index 0000000000..5175fa1588 --- /dev/null +++ b/MediaBrowser.Model/Dto/ItemByNameCounts.cs @@ -0,0 +1,35 @@ + +namespace MediaBrowser.Model.Dto +{ + /// + /// Class ItemByNameCounts + /// + public class ItemByNameCounts + { + /// + /// Gets or sets the total count. + /// + /// The total count. + public int TotalCount { get; set; } + /// + /// Gets or sets the movie count. + /// + /// The movie count. + public int MovieCount { get; set; } + /// + /// Gets or sets the series count. + /// + /// The series count. + public int SeriesCount { get; set; } + /// + /// Gets or sets the episode guest star count. + /// + /// The episode guest star count. + public int EpisodeGuestStarCount { get; set; } + /// + /// Gets or sets the game count. + /// + /// The game count. + public int GameCount { get; set; } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 779fadf111..9df35463cc 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -45,6 +45,7 @@ +