From 6d532640a9589c330904d49b0edffb7284f5d8fc Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 15 Sep 2013 17:53:18 -0400 Subject: [PATCH] fixes #543 - Support filtering games by number of players --- .../DefaultTheme/DefaultThemeService.cs | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs index 21ddcd0283..fef87788a4 100644 --- a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs +++ b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs @@ -17,6 +17,13 @@ using System.Threading.Tasks; namespace MediaBrowser.Api.DefaultTheme { + [Route("/MBT/DefaultTheme/Games", "GET")] + public class GetGamesView : IReturn + { + [ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] + public Guid UserId { get; set; } + } + [Route("/MBT/DefaultTheme/TV", "GET")] public class GetTvView : IReturn { @@ -104,6 +111,45 @@ namespace MediaBrowser.Api.DefaultTheme return view; } + public object Get(GetGamesView request) + { + var result = GetGamesView(request).Result; + + return ToOptimizedResult(result); + } + + private async Task GetGamesView(GetGamesView request) + { + var user = _userManager.GetUserById(request.UserId); + + var items = user.RootFolder.GetRecursiveChildren(user) + .Where(i => i is Game || string.Equals(i.GetType().Name, "GamePlatform", StringComparison.OrdinalIgnoreCase)) + .ToList(); + + var itemsWithBackdrops = FilterItemsForBackdropDisplay(items.Where(i => i.BackdropImagePaths.Count > 0)).ToList(); + + var view = new GamesView(); + + var fields = new List(); + + var spotlightItemTasks = itemsWithBackdrops + .OfType() + .OrderBy(i => Guid.NewGuid()) + .Take(50) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)); + + view.SpotlightItems = await Task.WhenAll(spotlightItemTasks).ConfigureAwait(false); + + return view; + } + + public object Get(GetMovieView request) + { + var result = GetMovieView(request).Result; + + return ToOptimizedResult(result); + } + public object Get(GetTvView request) { var result = GetTvView(request).Result; @@ -164,13 +210,6 @@ namespace MediaBrowser.Api.DefaultTheme return view; } - public object Get(GetMovieView request) - { - var result = GetMovieView(request).Result; - - return ToOptimizedResult(result); - } - private async Task GetMovieView(GetMovieView request) { var user = _userManager.GetUserById(request.UserId);