2014-03-07 15:53:23 +00:00
using MediaBrowser.Controller.Collections ;
using ServiceStack ;
using System ;
using System.Linq ;
using System.Threading.Tasks ;
namespace MediaBrowser.Api.Movies
{
2014-03-21 03:31:40 +00:00
[Route("/Collections", "POST", Summary = "Creates a new collection")]
2014-03-07 15:53:23 +00:00
public class CreateCollection : IReturnVoid
{
[ApiMember(Name = "IsLocked", Description = "Whether or not to lock the new collection.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "POST")]
public bool IsLocked { get ; set ; }
[ApiMember(Name = "Name", Description = "The name of the new collection.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Name { get ; set ; }
[ApiMember(Name = "ParentId", Description = "Optional - create the collection within a specific folder", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
public Guid ? ParentId { get ; set ; }
}
2014-03-21 03:31:40 +00:00
[Route("/Collections/{Id}/Items", "POST", Summary = "Adds items to a collection")]
2014-03-07 15:53:23 +00:00
public class AddToCollection : IReturnVoid
{
[ApiMember(Name = "Ids", Description = "Item id, comma delimited", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Ids { get ; set ; }
[ApiMember(Name = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public Guid Id { get ; set ; }
}
2014-03-21 03:31:40 +00:00
[Route("/Collections/{Id}/Items", "DELETE", Summary = "Removes items from a collection")]
2014-03-07 15:53:23 +00:00
public class RemoveFromCollection : IReturnVoid
{
[ApiMember(Name = "Ids", Description = "Item id, comma delimited", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
public string Ids { get ; set ; }
[ApiMember(Name = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
public Guid Id { get ; set ; }
}
public class CollectionService : BaseApiService
{
private readonly ICollectionManager _collectionManager ;
public CollectionService ( ICollectionManager collectionManager )
{
_collectionManager = collectionManager ;
}
public void Post ( CreateCollection request )
{
var task = _collectionManager . CreateCollection ( new CollectionCreationOptions
{
IsLocked = request . IsLocked ,
Name = request . Name ,
ParentId = request . ParentId
} ) ;
Task . WaitAll ( task ) ;
}
public void Post ( AddToCollection request )
{
var task = _collectionManager . AddToCollection ( request . Id , request . Ids . Split ( ',' ) . Select ( i = > new Guid ( i ) ) ) ;
Task . WaitAll ( task ) ;
}
public void Delete ( RemoveFromCollection request )
{
var task = _collectionManager . RemoveFromCollection ( request . Id , request . Ids . Split ( ',' ) . Select ( i = > new Guid ( i ) ) ) ;
Task . WaitAll ( task ) ;
}
}
}