2012-09-07 16:17:39 +00:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
|
|
|
|
using MediaBrowser.Model.DTO;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
2012-07-16 16:50:44 +00:00
|
|
|
|
using System.Collections.Generic;
|
2012-09-08 14:52:13 +00:00
|
|
|
|
using System.ComponentModel.Composition;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
using System.Linq;
|
2012-09-08 14:52:13 +00:00
|
|
|
|
using System.Net;
|
2012-08-19 20:38:31 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.HttpHandlers
|
|
|
|
|
{
|
2012-09-08 14:52:13 +00:00
|
|
|
|
[Export(typeof(BaseHandler))]
|
2012-09-02 05:30:25 +00:00
|
|
|
|
public class ItemListHandler : BaseSerializationHandler<DTOBaseItem[]>
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-09-08 14:52:13 +00:00
|
|
|
|
public override bool HandlesRequest(HttpListenerRequest request)
|
|
|
|
|
{
|
|
|
|
|
return ApiService.IsApiUrlMatch("itemlist", request);
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 02:50:59 +00:00
|
|
|
|
protected override Task<DTOBaseItem[]> GetObjectToSerialize()
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-09-07 16:17:39 +00:00
|
|
|
|
User user = ApiService.GetUserById(QueryString["userid"], true);
|
2012-08-18 08:22:54 +00:00
|
|
|
|
|
2012-09-07 16:17:39 +00:00
|
|
|
|
return Task.WhenAll<DTOBaseItem>(GetItemsToSerialize(user).Select(i =>
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-08-18 08:22:54 +00:00
|
|
|
|
return ApiService.GetDTOBaseItem(i, user, includeChildren: false, includePeople: false);
|
2012-08-19 20:38:31 +00:00
|
|
|
|
}));
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 16:17:39 +00:00
|
|
|
|
private IEnumerable<BaseItem> GetItemsToSerialize(User user)
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-09-07 16:17:39 +00:00
|
|
|
|
Folder parent = ApiService.GetItemById(ItemId) as Folder;
|
2012-08-18 08:22:54 +00:00
|
|
|
|
|
2012-09-07 16:17:39 +00:00
|
|
|
|
if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return parent.GetInProgressItems(user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
2012-09-07 16:17:39 +00:00
|
|
|
|
else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
|
2012-08-17 16:47:35 +00:00
|
|
|
|
{
|
2012-09-07 16:17:39 +00:00
|
|
|
|
return parent.GetRecentlyAddedItems(user);
|
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return parent.GetRecentlyAddedUnplayedItems(user);
|
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return parent.GetItemsWithGenre(QueryString["name"], user);
|
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return parent.GetItemsWithYear(int.Parse(QueryString["year"]), user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
2012-09-07 16:17:39 +00:00
|
|
|
|
else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return parent.GetItemsWithStudio(QueryString["name"], user);
|
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
return parent.GetItemsWithPerson(QueryString["name"], null, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new InvalidOperationException();
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
2012-07-16 16:50:44 +00:00
|
|
|
|
|
2012-09-07 16:17:39 +00:00
|
|
|
|
protected string ItemId
|
2012-07-16 16:50:44 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-09-07 16:17:39 +00:00
|
|
|
|
return QueryString["id"];
|
2012-07-16 16:50:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-18 08:22:54 +00:00
|
|
|
|
|
2012-08-17 16:47:35 +00:00
|
|
|
|
private string ListType
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return QueryString["listtype"] ?? string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|