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