2013-04-13 11:02:30 -07:00
|
|
|
|
using MediaBrowser.Controller.Dto;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2013-08-30 18:08:32 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-04-13 11:02:30 -07:00
|
|
|
|
using MediaBrowser.Controller.Persistence;
|
2013-05-09 10:38:02 -07:00
|
|
|
|
using MediaBrowser.Controller.Session;
|
2013-02-21 10:50:46 -07:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2013-03-09 22:36:39 -07:00
|
|
|
|
using MediaBrowser.Model.Querying;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using ServiceStack.ServiceHost;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2013-04-05 10:10:55 -07:00
|
|
|
|
using System.Threading;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.UserLibrary
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}", "GET")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Gets an item from a user's library")]
|
2013-02-21 10:50:46 -07:00
|
|
|
|
public class GetItem : IReturn<BaseItemDto>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-08 19:34:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/Root", "GET")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Gets the root folder from a user's library")]
|
2013-03-08 19:34:54 -07:00
|
|
|
|
public class GetRootFolder : IReturn<BaseItemDto>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetIntros
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/Intros", "GET")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(("Gets intros to play before the main media item plays"))]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public class GetIntros : IReturn<List<string>>
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the item id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The item id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MarkFavoriteItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/FavoriteItems/{Id}", "POST")]
|
2013-03-29 10:25:12 -07:00
|
|
|
|
[Api(Description = "Marks an item as a favorite")]
|
2013-08-22 14:33:39 -07:00
|
|
|
|
public class MarkFavoriteItem : IReturn<UserItemDataDto>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UnmarkFavoriteItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/FavoriteItems/{Id}", "DELETE")]
|
2013-03-29 10:25:12 -07:00
|
|
|
|
[Api(Description = "Unmarks an item as a favorite")]
|
2013-08-22 14:33:39 -07:00
|
|
|
|
public class UnmarkFavoriteItem : IReturn<UserItemDataDto>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class ClearUserItemRating
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/Rating", "DELETE")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Deletes a user's saved personal rating for an item")]
|
2013-08-22 14:33:39 -07:00
|
|
|
|
public class DeleteUserItemRating : IReturn<UserItemDataDto>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UpdateUserItemRating
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/Rating", "POST")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Updates a user's rating for an item")]
|
2013-08-22 14:33:39 -07:00
|
|
|
|
public class UpdateUserItemRating : IReturn<UserItemDataDto>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating" /> is likes.
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value><c>true</c> if likes; otherwise, <c>false</c>.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Likes", Description = "Whether the user likes the item or not. true/false", IsRequired = true, DataType = "boolean", ParameterType = "query", Verb = "POST")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public bool Likes { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MarkPlayedItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/PlayedItems/{Id}", "POST")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Marks an item as played")]
|
2013-08-22 14:33:39 -07:00
|
|
|
|
public class MarkPlayedItem : IReturn<UserItemDataDto>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class MarkUnplayedItem
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("/Users/{UserId}/PlayedItems/{Id}", "DELETE")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Marks an item as unplayed")]
|
2013-08-22 14:33:39 -07:00
|
|
|
|
public class MarkUnplayedItem : IReturn<UserItemDataDto>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class OnPlaybackStart
|
|
|
|
|
/// </summary>
|
2013-02-24 19:41:51 -07:00
|
|
|
|
[Route("/Users/{UserId}/PlayingItems/{Id}", "POST")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Reports that a user has begun playing an item")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public class OnPlaybackStart : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class OnPlaybackProgress
|
|
|
|
|
/// </summary>
|
2013-02-24 19:41:51 -07:00
|
|
|
|
[Route("/Users/{UserId}/PlayingItems/{Id}/Progress", "POST")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Reports a user's playback progress")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public class OnPlaybackProgress : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the position ticks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The position ticks.</value>
|
2013-03-08 22:15:51 -07:00
|
|
|
|
[ApiMember(Name = "PositionTicks", Description = "Optional. The current position, in ticks. 1 tick = 10000 ms", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "POST")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public long? PositionTicks { get; set; }
|
2013-05-10 05:18:07 -07:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "IsPaused", Description = "Indicates if the player is paused.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
|
|
|
|
|
public bool IsPaused { get; set; }
|
2013-08-29 14:00:27 -07:00
|
|
|
|
|
|
|
|
|
[ApiMember(Name = "IsMuted", Description = "Indicates if the player is muted.", IsRequired = false, DataType = "boolean", ParameterType = "query", Verb = "POST")]
|
|
|
|
|
public bool IsMuted { get; set; }
|
2013-02-24 19:41:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class OnPlaybackStopped
|
|
|
|
|
/// </summary>
|
2013-02-24 19:41:51 -07:00
|
|
|
|
[Route("/Users/{UserId}/PlayingItems/{Id}", "DELETE")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Reports that a user has stopped playing an item")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public class OnPlaybackStopped : IReturnVoid
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the position ticks.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The position ticks.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "PositionTicks", Description = "Optional. The position, in ticks, where playback stopped. 1 tick = 10000 ms", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "DELETE")]
|
2013-02-24 19:41:51 -07:00
|
|
|
|
public long? PositionTicks { get; set; }
|
|
|
|
|
}
|
2013-04-24 09:37:12 -07:00
|
|
|
|
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetLocalTrailers
|
|
|
|
|
/// </summary>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/LocalTrailers", "GET")]
|
2013-04-05 10:10:55 -07:00
|
|
|
|
[Api(Description = "Gets local trailers for an item")]
|
2013-02-21 10:50:46 -07:00
|
|
|
|
public class GetLocalTrailers : IReturn<List<BaseItemDto>>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class GetSpecialFeatures
|
|
|
|
|
/// </summary>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
[Route("/Users/{UserId}/Items/{Id}/SpecialFeatures", "GET")]
|
2013-08-30 18:08:32 -07:00
|
|
|
|
[Api(Description = "Gets special features for an item")]
|
2013-02-21 10:50:46 -07:00
|
|
|
|
public class GetSpecialFeatures : IReturn<List<BaseItemDto>>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the user id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The user id.</value>
|
2013-03-08 15:41:38 -07:00
|
|
|
|
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public Guid UserId { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the id.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The id.</value>
|
2013-03-08 16:10:37 -07:00
|
|
|
|
[ApiMember(Name = "Id", Description = "Movie Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UserLibraryService
|
|
|
|
|
/// </summary>
|
2013-03-15 22:52:33 -07:00
|
|
|
|
public class UserLibraryService : BaseApiService
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _user manager
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly IUserManager _userManager;
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _user data repository
|
|
|
|
|
/// </summary>
|
2013-04-13 11:02:30 -07:00
|
|
|
|
private readonly IUserDataRepository _userDataRepository;
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _library manager
|
|
|
|
|
/// </summary>
|
2013-02-28 12:32:41 -07:00
|
|
|
|
private readonly ILibraryManager _libraryManager;
|
2013-04-24 09:37:12 -07:00
|
|
|
|
|
2013-05-08 13:58:52 -07:00
|
|
|
|
private readonly IItemRepository _itemRepo;
|
|
|
|
|
|
2013-05-09 10:38:02 -07:00
|
|
|
|
private readonly ISessionManager _sessionManager;
|
2013-09-04 10:02:19 -07:00
|
|
|
|
private readonly IDtoService _dtoService;
|
2013-05-09 10:38:02 -07:00
|
|
|
|
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UserLibraryService" /> class.
|
|
|
|
|
/// </summary>
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// <param name="userManager">The user manager.</param>
|
|
|
|
|
/// <param name="libraryManager">The library manager.</param>
|
|
|
|
|
/// <param name="userDataRepository">The user data repository.</param>
|
2013-05-08 13:58:52 -07:00
|
|
|
|
/// <param name="itemRepo">The item repo.</param>
|
2013-02-24 14:53:54 -07:00
|
|
|
|
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
|
2013-09-04 10:02:19 -07:00
|
|
|
|
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository, IItemRepository itemRepo, ISessionManager sessionManager, IDtoService dtoService)
|
2013-02-24 14:53:54 -07:00
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
_userManager = userManager;
|
2013-02-28 12:32:41 -07:00
|
|
|
|
_libraryManager = libraryManager;
|
2013-04-13 11:02:30 -07:00
|
|
|
|
_userDataRepository = userDataRepository;
|
2013-05-08 13:58:52 -07:00
|
|
|
|
_itemRepo = itemRepo;
|
2013-05-09 10:38:02 -07:00
|
|
|
|
_sessionManager = sessionManager;
|
2013-09-04 10:02:19 -07:00
|
|
|
|
_dtoService = dtoService;
|
2013-02-24 14:53:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public object Get(GetSpecialFeatures request)
|
2013-08-22 14:33:39 -07:00
|
|
|
|
{
|
2013-08-22 14:56:19 -07:00
|
|
|
|
var result = GetAsync(request).Result;
|
2013-08-22 14:33:39 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task<BaseItemDto[]> GetAsync(GetSpecialFeatures request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _dtoService.GetItemByDtoId(request.Id, user.Id);
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
// Get everything
|
|
|
|
|
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
|
|
|
|
|
2013-08-30 18:08:32 -07:00
|
|
|
|
var movie = item as Movie;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-30 18:08:32 -07:00
|
|
|
|
// Get them from the db
|
|
|
|
|
if (movie != null)
|
|
|
|
|
{
|
|
|
|
|
// Avoid implicitly captured closure
|
|
|
|
|
var movie1 = movie;
|
|
|
|
|
|
|
|
|
|
var tasks = movie.SpecialFeatureIds
|
|
|
|
|
.Select(_itemRepo.RetrieveItem)
|
|
|
|
|
.OrderBy(i => i.SortName)
|
2013-09-04 10:02:19 -07:00
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, fields, user, movie1));
|
2013-08-30 18:08:32 -07:00
|
|
|
|
|
|
|
|
|
return Task.WhenAll(tasks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var series = item as Series;
|
|
|
|
|
|
|
|
|
|
// Get them from the child tree
|
|
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
var tasks = series
|
|
|
|
|
.RecursiveChildren
|
|
|
|
|
.OfType<Episode>()
|
|
|
|
|
.Where(i => i.ParentIndexNumber.HasValue && i.ParentIndexNumber.Value == 0)
|
2013-08-31 07:55:10 -07:00
|
|
|
|
.OrderBy(i =>
|
|
|
|
|
{
|
|
|
|
|
if (i.PremiereDate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return i.PremiereDate.Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i.ProductionYear.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return new DateTime(i.ProductionYear.Value, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
|
}
|
|
|
|
|
return DateTime.MinValue;
|
|
|
|
|
})
|
|
|
|
|
.ThenBy(i => i.SortName)
|
2013-09-04 10:02:19 -07:00
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, fields, user));
|
2013-08-30 18:08:32 -07:00
|
|
|
|
|
|
|
|
|
return Task.WhenAll(tasks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new ArgumentException("The item does not support special features");
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2013-02-20 18:33:05 -07:00
|
|
|
|
public object Get(GetLocalTrailers request)
|
2013-08-22 14:33:39 -07:00
|
|
|
|
{
|
2013-08-22 14:56:19 -07:00
|
|
|
|
var result = GetAsync(request).Result;
|
2013-08-22 14:33:39 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Task<BaseItemDto[]> GetAsync(GetLocalTrailers request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _dtoService.GetItemByDtoId(request.Id, user.Id);
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
// Get everything
|
|
|
|
|
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
|
|
|
|
|
2013-08-22 14:33:39 -07:00
|
|
|
|
var tasks = item.LocalTrailerIds
|
2013-07-30 07:51:28 -07:00
|
|
|
|
.Select(_itemRepo.RetrieveItem)
|
|
|
|
|
.OrderBy(i => i.SortName)
|
2013-09-04 10:02:19 -07:00
|
|
|
|
.Select(i => _dtoService.GetBaseItemDto(i, fields, user, item));
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-22 14:33:39 -07:00
|
|
|
|
return Task.WhenAll(tasks);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07: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 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _dtoService.GetItemByDtoId(request.Id, user.Id);
|
2013-02-24 14:53:54 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
// Get everything
|
|
|
|
|
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var result = _dtoService.GetBaseItemDto(item, fields, user).Result;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-24 09:37:12 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
2013-03-08 19:34:54 -07:00
|
|
|
|
public object Get(GetRootFolder request)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
|
|
|
|
|
|
|
|
|
var item = user.RootFolder;
|
|
|
|
|
|
|
|
|
|
// Get everything
|
|
|
|
|
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
|
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var result = _dtoService.GetBaseItemDto(item, fields, user).Result;
|
2013-03-08 19:34:54 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
2013-04-24 09:37:12 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
/// <returns>System.Object.</returns>
|
|
|
|
|
public object Get(GetIntros request)
|
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _dtoService.GetItemByDtoId(request.Id, user.Id);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-03-01 19:44:46 -07:00
|
|
|
|
var result = _libraryManager.GetIntros(item, user);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2013-08-22 14:56:19 -07:00
|
|
|
|
public object Post(MarkFavoriteItem request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-08-22 18:36:34 -07:00
|
|
|
|
var dto = MarkFavorite(request.UserId, request.Id, true).Result;
|
2013-08-22 14:56:19 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(dto);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2013-08-22 14:56:19 -07:00
|
|
|
|
public object Delete(UnmarkFavoriteItem request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-08-22 18:36:34 -07:00
|
|
|
|
var dto = MarkFavorite(request.UserId, request.Id, false).Result;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-22 18:36:34 -07:00
|
|
|
|
return ToOptimizedResult(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<UserItemDataDto> MarkFavorite(Guid userId, string itemId, bool isFavorite)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = string.IsNullOrEmpty(itemId) ? user.RootFolder : _dtoService.GetItemByDtoId(itemId, user.Id);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-13 11:02:30 -07:00
|
|
|
|
var key = item.GetUserDataKey();
|
2013-04-24 09:37:12 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
// Get the user data for this item
|
2013-06-17 13:35:43 -07:00
|
|
|
|
var data = _userDataRepository.GetUserData(user.Id, key);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
// Set favorite status
|
2013-08-22 18:36:34 -07:00
|
|
|
|
data.IsFavorite = isFavorite;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-22 18:36:34 -07:00
|
|
|
|
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
|
2013-08-22 14:56:19 -07:00
|
|
|
|
|
|
|
|
|
data = _userDataRepository.GetUserData(user.Id, key);
|
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
return _dtoService.GetUserItemDataDto(data);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2013-08-22 14:56:19 -07:00
|
|
|
|
public object Delete(DeleteUserItemRating request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-08-22 18:36:34 -07:00
|
|
|
|
var dto = UpdateUserItemRating(request.UserId, request.Id, null).Result;
|
2013-08-22 14:56:19 -07:00
|
|
|
|
|
|
|
|
|
return ToOptimizedResult(dto);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2013-08-22 14:56:19 -07:00
|
|
|
|
public object Post(UpdateUserItemRating request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-08-22 18:36:34 -07:00
|
|
|
|
var dto = UpdateUserItemRating(request.UserId, request.Id, request.Likes).Result;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-22 18:36:34 -07:00
|
|
|
|
return ToOptimizedResult(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<UserItemDataDto> UpdateUserItemRating(Guid userId, string itemId, bool? likes)
|
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUserById(userId);
|
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = string.IsNullOrEmpty(itemId) ? user.RootFolder : _dtoService.GetItemByDtoId(itemId, user.Id);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-13 11:02:30 -07:00
|
|
|
|
var key = item.GetUserDataKey();
|
2013-04-24 09:37:12 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
// Get the user data for this item
|
2013-06-17 13:35:43 -07:00
|
|
|
|
var data = _userDataRepository.GetUserData(user.Id, key);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-22 18:36:34 -07:00
|
|
|
|
data.Likes = likes;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-22 18:36:34 -07:00
|
|
|
|
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
|
2013-08-22 14:56:19 -07:00
|
|
|
|
|
|
|
|
|
data = _userDataRepository.GetUserData(user.Id, key);
|
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
return _dtoService.GetUserItemDataDto(data);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
2013-08-30 18:08:32 -07:00
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2013-08-22 14:56:19 -07:00
|
|
|
|
public object Post(MarkPlayedItem request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
var task = UpdatePlayedStatus(user, request.Id, true);
|
|
|
|
|
|
2013-08-22 14:56:19 -07:00
|
|
|
|
return ToOptimizedResult(task.Result);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-09 09:11:16 -07:00
|
|
|
|
private SessionInfo GetSession()
|
|
|
|
|
{
|
|
|
|
|
var auth = RequestFilterAttribute.GetAuthorization(RequestContext);
|
|
|
|
|
|
|
|
|
|
string deviceId;
|
|
|
|
|
string client;
|
|
|
|
|
string version;
|
|
|
|
|
|
|
|
|
|
auth.TryGetValue("DeviceId", out deviceId);
|
|
|
|
|
auth.TryGetValue("Client", out client);
|
|
|
|
|
auth.TryGetValue("Version", out version);
|
|
|
|
|
|
|
|
|
|
return _sessionManager.Sessions.First(i => string.Equals(i.DeviceId, deviceId) &&
|
|
|
|
|
string.Equals(i.Client, client) &&
|
|
|
|
|
string.Equals(i.ApplicationVersion, version));
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-24 19:41:51 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(OnPlaybackStart request)
|
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = _dtoService.GetItemByDtoId(request.Id, user.Id);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
|
2013-07-09 09:11:16 -07:00
|
|
|
|
_sessionManager.OnPlaybackStart(item, GetSession().Id);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
|
|
|
|
public void Post(OnPlaybackProgress request)
|
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = _dtoService.GetItemByDtoId(request.Id, user.Id);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
|
2013-08-29 14:00:27 -07:00
|
|
|
|
var task = _sessionManager.OnPlaybackProgress(item, request.PositionTicks, request.IsPaused, request.IsMuted, GetSession().Id);
|
2013-03-15 22:52:33 -07:00
|
|
|
|
|
2013-07-09 09:11:16 -07:00
|
|
|
|
Task.WaitAll(task);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Posts the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2013-03-17 20:10:21 -07:00
|
|
|
|
public void Delete(OnPlaybackStopped request)
|
2013-02-24 19:41:51 -07:00
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = _dtoService.GetItemByDtoId(request.Id, user.Id);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
|
2013-07-09 09:11:16 -07:00
|
|
|
|
var task = _sessionManager.OnPlaybackStopped(item, request.PositionTicks, GetSession().Id);
|
2013-03-15 22:52:33 -07:00
|
|
|
|
|
2013-07-09 09:11:16 -07:00
|
|
|
|
Task.WaitAll(task);
|
2013-02-24 19:41:51 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deletes the specified request.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request">The request.</param>
|
2013-08-22 14:56:19 -07:00
|
|
|
|
public object Delete(MarkUnplayedItem request)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-02-27 13:25:45 -07:00
|
|
|
|
var user = _userManager.GetUserById(request.UserId);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
var task = UpdatePlayedStatus(user, request.Id, false);
|
|
|
|
|
|
2013-08-22 14:56:19 -07:00
|
|
|
|
return ToOptimizedResult(task.Result);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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>
|
2013-08-22 14:56:19 -07:00
|
|
|
|
private async Task<UserItemDataDto> UpdatePlayedStatus(User user, string itemId, bool wasPlayed)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-09-04 10:02:19 -07:00
|
|
|
|
var item = _dtoService.GetItemByDtoId(itemId, user.Id);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-08-22 14:56:19 -07:00
|
|
|
|
await item.SetPlayedStatus(user, wasPlayed, _userDataRepository).ConfigureAwait(false);
|
|
|
|
|
|
2013-09-04 10:02:19 -07:00
|
|
|
|
return _dtoService.GetUserItemDataDto(_userDataRepository.GetUserData(user.Id, item.GetUserDataKey()));
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|