2012-07-16 16:50:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
using System.Linq;
|
2012-08-15 13:20:29 +00:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-08-17 16:47:35 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2012-08-17 13:16:50 +00:00
|
|
|
|
using MediaBrowser.Model.DTO;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
2012-08-17 17:37:26 +00:00
|
|
|
|
using MediaBrowser.Model.Users;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.HttpHandlers
|
|
|
|
|
{
|
2012-08-17 16:47:35 +00:00
|
|
|
|
public class ItemListHandler : BaseJsonHandler<IEnumerable<BaseItemContainer<BaseItem>>>
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-08-17 16:47:35 +00:00
|
|
|
|
protected override IEnumerable<BaseItemContainer<BaseItem>> GetObjectToSerialize()
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-08-15 13:20:29 +00:00
|
|
|
|
return ItemsToSerialize.Select(i =>
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-08-15 13:20:29 +00:00
|
|
|
|
return ApiService.GetSerializationObject(i, false, UserId);
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-08-15 13:20:29 +00:00
|
|
|
|
});
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-17 16:47:35 +00:00
|
|
|
|
protected IEnumerable<BaseItem> ItemsToSerialize
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-08-17 16:47:35 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
Folder parent = ApiService.GetItemById(ItemId) as Folder;
|
2012-08-17 17:37:26 +00:00
|
|
|
|
|
|
|
|
|
User user = Kernel.Instance.Users.First(u => u.Id == UserId);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
|
|
|
|
|
if (ListType.Equals("inprogressitems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-17 17:37:26 +00:00
|
|
|
|
return parent.GetInProgressItems(user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("recentlyaddeditems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-17 17:37:26 +00:00
|
|
|
|
return parent.GetRecentlyAddedItems(user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("recentlyaddedunplayeditems", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-17 17:37:26 +00:00
|
|
|
|
return parent.GetRecentlyAddedUnplayedItems(user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("itemswithgenre", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-17 17:37:26 +00:00
|
|
|
|
return parent.GetItemsWithGenre(QueryString["name"], user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("itemswithyear", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-17 17:37:26 +00:00
|
|
|
|
return parent.GetItemsWithYear(int.Parse(QueryString["year"]), user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("itemswithstudio", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-17 17:37:26 +00:00
|
|
|
|
return parent.GetItemsWithStudio(QueryString["name"], user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
else if (ListType.Equals("itemswithperson", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
2012-08-17 17:37:26 +00:00
|
|
|
|
return parent.GetItemsWithPerson(QueryString["name"], null, user);
|
2012-08-17 16:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new InvalidOperationException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string ItemId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return QueryString["id"];
|
|
|
|
|
}
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
2012-07-16 16:50:44 +00:00
|
|
|
|
|
|
|
|
|
protected Guid UserId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Guid.Parse(QueryString["userid"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|