2013-02-26 21:05:52 +00:00
|
|
|
|
using MediaBrowser.Common.Implementations.HttpServer;
|
|
|
|
|
using MediaBrowser.Controller;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-02-25 02:41:51 +00:00
|
|
|
|
using MediaBrowser.Model.Connectivity;
|
2013-02-21 17:50:46 +00:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-24 21:53:54 +00:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using ServiceStack.ServiceHost;
|
2013-02-26 03:43:04 +00:00
|
|
|
|
using ServiceStack.Text.Controller;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}", "GET")]
|
|
|
|
|
[Route("/Users/{UserId}/Items/Root", "GET")]
|
2013-02-21 17:50:46 +00:00
|
|
|
|
public class GetItem : IReturn<BaseItemDto>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetIntros
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/Intros", "GET")]
|
|
|
|
|
[ServiceStack.ServiceHost.Api(("Gets intros to play before the main media item plays"))]
|
|
|
|
|
public class GetIntros : IReturn<List<string>>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the item id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The item id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdateDisplayPreferences
|
|
|
|
|
/// </summary>
|
2013-03-02 07:16:52 +00:00
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/DisplayPreferences", "POST")]
|
2013-02-21 01:33:05 +00:00
|
|
|
|
[ServiceStack.ServiceHost.Api(("Updates a user's display preferences for an item"))]
|
2013-03-05 02:05:59 +00:00
|
|
|
|
public class UpdateDisplayPreferences : DisplayPreferences, IReturnVoid
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MarkFavoriteItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/FavoriteItems/{Id}", "POST")]
|
|
|
|
|
public class MarkFavoriteItem : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UnmarkFavoriteItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/FavoriteItems/{Id}", "DELETE")]
|
|
|
|
|
public class UnmarkFavoriteItem : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ClearUserItemRating
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/Rating", "DELETE")]
|
|
|
|
|
public class DeleteUserItemRating : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdateUserItemRating
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/Rating", "POST")]
|
|
|
|
|
public class UpdateUserItemRating : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating" /> is likes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if likes; otherwise, <c>false</c>.</value>
|
|
|
|
|
public bool Likes { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MarkPlayedItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/PlayedItems/{Id}", "POST")]
|
|
|
|
|
public class MarkPlayedItem : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MarkUnplayedItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/PlayedItems/{Id}", "DELETE")]
|
|
|
|
|
public class MarkUnplayedItem : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-25 02:41:51 +00:00
|
|
|
|
[Route("/Users/{UserId}/PlayingItems/{Id}", "POST")]
|
|
|
|
|
public class OnPlaybackStart : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Users/{UserId}/PlayingItems/{Id}/Progress", "POST")]
|
|
|
|
|
public class OnPlaybackProgress : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the position ticks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The position ticks.</value>
|
|
|
|
|
public long? PositionTicks { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/Users/{UserId}/PlayingItems/{Id}", "DELETE")]
|
|
|
|
|
public class OnPlaybackStopped : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the position ticks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The position ticks.</value>
|
|
|
|
|
public long? PositionTicks { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetLocalTrailers
|
|
|
|
|
/// </summary>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/LocalTrailers", "GET")]
|
2013-02-21 17:50:46 +00:00
|
|
|
|
public class GetLocalTrailers : IReturn<List<BaseItemDto>>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetSpecialFeatures
|
|
|
|
|
/// </summary>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/SpecialFeatures", "GET")]
|
2013-02-21 17:50:46 +00:00
|
|
|
|
public class GetSpecialFeatures : IReturn<List<BaseItemDto>>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UserLibraryService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UserLibraryService : BaseRestService
|
|
|
|
|
{
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _json serializer
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IJsonSerializer _jsonSerializer;
|
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _user manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IUserManager _userManager;
|
2013-02-28 19:32:41 +00:00
|
|
|
|
|
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-02-27 20:25:45 +00:00
|
|
|
|
|
2013-02-24 21:53:54 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UserLibraryService" /> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="jsonSerializer">The json serializer.</param>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
|
2013-02-28 19:32:41 +00:00
|
|
|
|
public UserLibraryService(IJsonSerializer jsonSerializer, IUserManager userManager, ILibraryManager libraryManager)
|
2013-02-24 21:53:54 +00:00
|
|
|
|
: base()
|
|
|
|
|
{
|
|
|
|
|
if (jsonSerializer == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("jsonSerializer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_jsonSerializer = jsonSerializer;
|
2013-02-27 20:25:45 +00:00
|
|
|
|
_userManager = userManager;
|
2013-02-28 19:32:41 +00:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-02-24 21:53:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public object Get(GetSpecialFeatures request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
// Get everything
|
|
|
|
|
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
|
|
|
|
|
|
|
|
|
var movie = (Movie)item;
|
|
|
|
|
|
2013-02-22 01:26:35 +00:00
|
|
|
|
var dtoBuilder = new DtoBuilder(Logger);
|
|
|
|
|
|
2013-03-03 18:34:41 +00:00
|
|
|
|
var items = movie.SpecialFeatures.Select(i => dtoBuilder.GetDtoBaseItem(i, user, fields, _libraryManager)).AsParallel().Select(t => t.Result).ToList();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(items);
|
|
|
|
|
}
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2013-02-21 01:33:05 +00:00
|
|
|
|
public object Get(GetLocalTrailers request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
// Get everything
|
|
|
|
|
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
|
|
|
|
|
2013-02-22 01:26:35 +00:00
|
|
|
|
var dtoBuilder = new DtoBuilder(Logger);
|
|
|
|
|
|
2013-03-03 18:34:41 +00:00
|
|
|
|
var items = item.LocalTrailers.Select(i => dtoBuilder.GetDtoBaseItem(i, user, fields, _libraryManager)).AsParallel().Select(t => t.Result).ToList();
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(items);
|
|
|
|
|
}
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetItem request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-24 21:53:54 +00:00
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
// Get everything
|
|
|
|
|
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
|
|
|
|
|
2013-02-22 01:26:35 +00:00
|
|
|
|
var dtoBuilder = new DtoBuilder(Logger);
|
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var result = dtoBuilder.GetDtoBaseItem(item, user, fields, _libraryManager).Result;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetIntros request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-02 02:44:46 +00:00
|
|
|
|
var result = _libraryManager.GetIntros(item, user);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(UpdateDisplayPreferences request)
|
|
|
|
|
{
|
|
|
|
|
// We need to parse this manually because we told service stack not to with IRequiresRequestStream
|
|
|
|
|
// https://code.google.com/p/servicestack/source/browse/trunk/Common/ServiceStack.Text/ServiceStack.Text/Controller/PathInfo.cs
|
|
|
|
|
var pathInfo = PathInfo.Parse(Request.PathInfo);
|
|
|
|
|
var userId = new Guid(pathInfo.GetArgumentValue<string>(1));
|
|
|
|
|
var itemId = pathInfo.GetArgumentValue<string>(3);
|
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(userId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = (Folder)DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-03-05 02:05:59 +00:00
|
|
|
|
var displayPreferences = request;
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var task = _libraryManager.SaveDisplayPreferencesForFolder(user, item, displayPreferences);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(MarkFavoriteItem request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = (Folder)DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
// Get the user data for this item
|
|
|
|
|
var data = item.GetUserData(user, true);
|
|
|
|
|
|
|
|
|
|
// Set favorite status
|
|
|
|
|
data.IsFavorite = true;
|
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var task = _userManager.SaveUserDataForItem(user, item, data);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Delete(UnmarkFavoriteItem request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = (Folder)DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
// Get the user data for this item
|
|
|
|
|
var data = item.GetUserData(user, true);
|
|
|
|
|
|
|
|
|
|
// Set favorite status
|
|
|
|
|
data.IsFavorite = false;
|
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var task = _userManager.SaveUserDataForItem(user, item, data);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Delete(DeleteUserItemRating request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = (Folder)DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
// Get the user data for this item
|
|
|
|
|
var data = item.GetUserData(user, true);
|
|
|
|
|
|
|
|
|
|
data.Rating = null;
|
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var task = _userManager.SaveUserDataForItem(user, item, data);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(UpdateUserItemRating request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = (Folder)DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
// Get the user data for this item
|
|
|
|
|
var data = item.GetUserData(user, true);
|
|
|
|
|
|
|
|
|
|
data.Likes = request.Likes;
|
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var task = _userManager.SaveUserDataForItem(user, item, data);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(MarkPlayedItem request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
var task = UpdatePlayedStatus(user, request.Id, true);
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-25 02:41:51 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(OnPlaybackStart request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
_userManager.OnPlaybackStart(user, item, ClientType.Other, string.Empty);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(OnPlaybackProgress request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var task = _userManager.OnPlaybackProgress(user, item, request.PositionTicks, ClientType.Other, string.Empty);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(OnPlaybackStopped request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var task = _userManager.OnPlaybackStopped(user, item, request.PositionTicks, ClientType.Other, string.Empty);
|
2013-02-25 02:41:51 +00:00
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-21 01:33:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Delete(MarkUnplayedItem request)
|
|
|
|
|
{
|
2013-02-27 20:25:45 +00:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
|
|
|
|
var task = UpdatePlayedStatus(user, request.Id, false);
|
|
|
|
|
|
|
|
|
|
Task.WaitAll(task);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the played status.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
|
/// <param name="itemId">The item id.</param>
|
|
|
|
|
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
|
private Task UpdatePlayedStatus(User user, string itemId, bool wasPlayed)
|
|
|
|
|
{
|
2013-02-28 19:32:41 +00:00
|
|
|
|
var item = DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
|
2013-02-27 20:25:45 +00:00
|
|
|
|
return item.SetPlayedStatus(user, wasPlayed, _userManager);
|
2013-02-21 01:33:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|