From 80b3ad7bd20329e6a5bbf6eeb76af62c87434a7c Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 19 Jul 2012 22:22:44 -0400 Subject: Moved the http server to it's own assembly. added comments and made other minor re-organizations. --- MediaBrowser.Api/ApiService.cs | 91 ++++++++++-------------------------------- 1 file changed, 20 insertions(+), 71 deletions(-) (limited to 'MediaBrowser.Api/ApiService.cs') diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.cs index 2687ce81a..e49593779 100644 --- a/MediaBrowser.Api/ApiService.cs +++ b/MediaBrowser.Api/ApiService.cs @@ -1,10 +1,16 @@ using System; using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; using MediaBrowser.Controller; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Users; namespace MediaBrowser.Api { + /// + /// Contains some helpers for the api + /// public static class ApiService { public static BaseItem GetItemById(string id) @@ -14,86 +20,29 @@ namespace MediaBrowser.Api return Kernel.Instance.GetItemById(guid); } - public static IEnumerable GetAllStudios(Folder parent, Guid userId) + /// + /// Takes a BaseItem and returns the actual object that will be serialized by the api + /// + public static ApiBaseItemWrapper GetSerializationObject(BaseItem item, bool includeChildren, Guid userId) { - Dictionary data = new Dictionary(); - - IEnumerable allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId); - - foreach (var item in allItems) + ApiBaseItemWrapper wrapper = new ApiBaseItemWrapper() { - if (item.Studios == null) - { - continue; - } - - foreach (string val in item.Studios) - { - if (!data.ContainsKey(val)) - { - data.Add(val, 1); - } - else - { - data[val]++; - } - } - } + Item = item, + UserItemData = Kernel.Instance.GetUserItemData(userId, item.Id), + ItemType = item.GetType() + }; - List list = new List(); - - foreach (string key in data.Keys) + if (includeChildren) { - list.Add(new CategoryInfo() - { - Name = key, - ItemCount = data[key] - - }); - } - - return list; - } + var folder = item as Folder; - public static IEnumerable GetAllGenres(Folder parent, Guid userId) - { - Dictionary data = new Dictionary(); - - IEnumerable allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId); - - foreach (var item in allItems) - { - if (item.Genres == null) - { - continue; - } - - foreach (string val in item.Genres) + if (folder != null) { - if (!data.ContainsKey(val)) - { - data.Add(val, 1); - } - else - { - data[val]++; - } + wrapper.Children = Kernel.Instance.GetParentalAllowedChildren(folder, userId).Select(c => GetSerializationObject(c, false, userId)); } } - List list = new List(); - - foreach (string key in data.Keys) - { - list.Add(new CategoryInfo() - { - Name = key, - ItemCount = data[key] - - }); - } - - return list; + return wrapper; } } } -- cgit v1.2.3