From 8ce3e74e8112a94773df22827849bf274fc88198 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sun, 24 Feb 2013 16:53:54 -0500 Subject: More DI --- MediaBrowser.Api/UserLibrary/UserLibraryService.cs | 65 +++++++++++++++++----- 1 file changed, 51 insertions(+), 14 deletions(-) (limited to 'MediaBrowser.Api/UserLibrary/UserLibraryService.cs') diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index 576ff8892..4267947ad 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -1,11 +1,11 @@ using MediaBrowser.Common.Net; -using MediaBrowser.Common.Serialization; using MediaBrowser.Controller; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Serialization; using ServiceStack.ServiceHost; using System; using System.Collections.Generic; @@ -28,7 +28,7 @@ namespace MediaBrowser.Api.UserLibrary /// /// The user id. public Guid UserId { get; set; } - + /// /// Gets or sets the id. /// @@ -48,7 +48,7 @@ namespace MediaBrowser.Api.UserLibrary /// /// The user id. public Guid UserId { get; set; } - + /// /// Gets or sets the item id. /// @@ -68,7 +68,7 @@ namespace MediaBrowser.Api.UserLibrary /// /// The user id. public Guid UserId { get; set; } - + /// /// Gets or sets the id. /// @@ -106,7 +106,7 @@ namespace MediaBrowser.Api.UserLibrary /// /// The user id. public Guid UserId { get; set; } - + /// /// Gets or sets the id. /// @@ -125,7 +125,7 @@ namespace MediaBrowser.Api.UserLibrary /// /// The user id. public Guid UserId { get; set; } - + /// /// Gets or sets the id. /// @@ -144,7 +144,7 @@ namespace MediaBrowser.Api.UserLibrary /// /// The user id. public Guid UserId { get; set; } - + /// /// Gets or sets the id. /// @@ -163,7 +163,7 @@ namespace MediaBrowser.Api.UserLibrary /// /// The user id. public Guid UserId { get; set; } - + /// /// Gets or sets the id. /// @@ -215,6 +215,9 @@ namespace MediaBrowser.Api.UserLibrary public string Id { get; set; } } + /// + /// Class GetLocalTrailers + /// [Route("/Users/{UserId}/Items/{Id}/LocalTrailers", "GET")] public class GetLocalTrailers : IReturn> { @@ -231,6 +234,9 @@ namespace MediaBrowser.Api.UserLibrary public string Id { get; set; } } + /// + /// Class GetSpecialFeatures + /// [Route("/Users/{UserId}/Items/{Id}/SpecialFeatures", "GET")] public class GetSpecialFeatures : IReturn> { @@ -253,6 +259,32 @@ namespace MediaBrowser.Api.UserLibrary /// public class UserLibraryService : BaseRestService { + /// + /// The _json serializer + /// + private readonly IJsonSerializer _jsonSerializer; + + /// + /// Initializes a new instance of the class. + /// + /// The json serializer. + /// jsonSerializer + public UserLibraryService(IJsonSerializer jsonSerializer) + : base() + { + if (jsonSerializer == null) + { + throw new ArgumentNullException("jsonSerializer"); + } + + _jsonSerializer = jsonSerializer; + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. public object Get(GetSpecialFeatures request) { var kernel = (Kernel)Kernel; @@ -260,7 +292,7 @@ namespace MediaBrowser.Api.UserLibrary var user = kernel.GetUserById(request.UserId); var item = DtoBuilder.GetItemByClientId(request.Id, user.Id); - + // Get everything var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList(); @@ -272,7 +304,12 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(items); } - + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. public object Get(GetLocalTrailers request) { var kernel = (Kernel)Kernel; @@ -280,7 +317,7 @@ namespace MediaBrowser.Api.UserLibrary var user = kernel.GetUserById(request.UserId); var item = DtoBuilder.GetItemByClientId(request.Id, user.Id); - + // Get everything var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList(); @@ -290,7 +327,7 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(items); } - + /// /// Gets the specified request. /// @@ -303,7 +340,7 @@ namespace MediaBrowser.Api.UserLibrary var user = kernel.GetUserById(request.UserId); var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, user.Id); - + // Get everything var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList(); @@ -366,7 +403,7 @@ namespace MediaBrowser.Api.UserLibrary var item = (Folder)DtoBuilder.GetItemByClientId(itemId, user.Id); - var displayPreferences = JsonSerializer.DeserializeFromStream(request.RequestStream); + var displayPreferences = _jsonSerializer.DeserializeFromStream(request.RequestStream); var task = kernel.LibraryManager.SaveDisplayPreferencesForFolder(user, item, displayPreferences); -- cgit v1.2.3