jellyfin/MediaBrowser.Api/Movies/CollectionService.cs

97 lines
4.0 KiB
C#
Raw Normal View History

using MediaBrowser.Controller.Collections;
2014-06-03 23:34:36 -04:00
using MediaBrowser.Controller.Dto;
2014-07-02 14:34:08 -04:00
using MediaBrowser.Controller.Net;
2014-08-01 22:34:45 -04:00
using MediaBrowser.Model.Collections;
using System;
2016-10-25 15:02:04 -04:00
using MediaBrowser.Model.Services;
namespace MediaBrowser.Api.Movies
{
2014-03-20 23:31:40 -04:00
[Route("/Collections", "POST", Summary = "Creates a new collection")]
2014-06-03 23:34:36 -04:00
public class CreateCollection : IReturn<CollectionCreationResult>
{
[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")]
2015-05-29 19:51:33 -04:00
public string ParentId { get; set; }
2014-06-03 23:34:36 -04:00
[ApiMember(Name = "Ids", Description = "Item Ids to add to the collection", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST", AllowMultiple = true)]
public string Ids { get; set; }
}
2014-03-20 23:31:40 -04:00
[Route("/Collections/{Id}/Items", "POST", Summary = "Adds items to a collection")]
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")]
2015-05-29 19:51:33 -04:00
public string Id { get; set; }
}
2014-03-20 23:31:40 -04:00
[Route("/Collections/{Id}/Items", "DELETE", Summary = "Removes items from a collection")]
public class RemoveFromCollection : IReturnVoid
{
2018-09-12 13:26:21 -04:00
[ApiMember(Name = "Ids", Description = "Item id, comma delimited", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")]
public string Ids { get; set; }
[ApiMember(Name = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
2015-05-29 19:51:33 -04:00
public string Id { get; set; }
}
2014-07-02 14:34:08 -04:00
[Authenticated]
public class CollectionService : BaseApiService
{
private readonly ICollectionManager _collectionManager;
2014-06-03 23:34:36 -04:00
private readonly IDtoService _dtoService;
2016-11-10 09:41:24 -05:00
private readonly IAuthorizationContext _authContext;
2016-11-10 09:41:24 -05:00
public CollectionService(ICollectionManager collectionManager, IDtoService dtoService, IAuthorizationContext authContext)
{
_collectionManager = collectionManager;
2014-06-03 23:34:36 -04:00
_dtoService = dtoService;
2016-11-10 09:41:24 -05:00
_authContext = authContext;
}
2018-09-12 13:26:21 -04:00
public object Post(CreateCollection request)
{
2016-11-10 09:41:24 -05:00
var userId = _authContext.GetAuthorizationInfo(Request).UserId;
2015-04-26 00:39:40 -04:00
2015-05-29 19:51:33 -04:00
var parentId = string.IsNullOrWhiteSpace(request.ParentId) ? (Guid?)null : new Guid(request.ParentId);
2018-09-12 13:26:21 -04:00
var item = _collectionManager.CreateCollection(new CollectionCreationOptions
{
IsLocked = request.IsLocked,
Name = request.Name,
2015-05-29 19:51:33 -04:00
ParentId = parentId,
2017-08-19 15:43:35 -04:00
ItemIdList = SplitValue(request.Ids, ','),
2018-09-12 13:26:21 -04:00
UserIds = new [] { userId }
2018-09-12 13:26:21 -04:00
});
2014-06-03 23:34:36 -04:00
2016-11-10 09:41:24 -05:00
var dtoOptions = GetDtoOptions(_authContext, request);
2014-12-27 00:08:39 -05:00
var dto = _dtoService.GetBaseItemDto(item, dtoOptions);
2014-06-03 23:34:36 -04:00
2018-09-12 13:26:21 -04:00
return new CollectionCreationResult
2014-06-03 23:34:36 -04:00
{
Id = dto.Id
2018-09-12 13:26:21 -04:00
};
}
public void Post(AddToCollection request)
{
2018-09-12 13:26:21 -04:00
_collectionManager.AddToCollection(new Guid(request.Id), SplitValue(request.Ids, ','));
}
public void Delete(RemoveFromCollection request)
{
2018-09-12 13:26:21 -04:00
_collectionManager.RemoveFromCollection(new Guid(request.Id), SplitValue(request.Ids, ','));
}
}
}