jellyfin-server/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs

38 lines
1.2 KiB
C#
Raw Normal View History

2012-09-09 18:32:51 +00:00
using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Controller.Entities;
2012-09-09 18:32:51 +00:00
using MediaBrowser.Model.DTO;
using System.ComponentModel.Composition;
using System.Net;
using System.Threading.Tasks;
namespace MediaBrowser.Api.HttpHandlers
{
/// <summary>
/// Provides a handler to set user favorite status for an item
/// </summary>
[Export(typeof(BaseHandler))]
2012-09-11 18:20:12 +00:00
public class FavoriteStatusHandler : BaseSerializationHandler<DtoUserItemData>
2012-09-09 18:32:51 +00:00
{
public override bool HandlesRequest(HttpListenerRequest request)
{
return ApiService.IsApiUrlMatch("FavoriteStatus", request);
}
2012-09-11 18:20:12 +00:00
protected override Task<DtoUserItemData> GetObjectToSerialize()
2012-09-09 18:32:51 +00:00
{
// Get the item
BaseItem item = ApiService.GetItemById(QueryString["id"]);
// Get the user
User user = ApiService.GetUserById(QueryString["userid"], true);
// Get the user data for this item
UserItemData data = item.GetUserData(user, true);
2012-09-09 18:32:51 +00:00
// Set favorite status
data.IsFavorite = QueryString["isfavorite"] == "1";
2012-09-11 18:20:12 +00:00
return Task.FromResult(ApiService.GetDtoUserItemData(data));
2012-09-09 18:32:51 +00:00
}
}
}