jellyfin/MediaBrowser.Api/HttpHandlers/FavoriteStatusHandler.cs
LukePulverenti Luke Pulverenti luke pulverenti c1c4c85fc2 Added some favorites api calls
2012-09-09 14:32:51 -04:00

44 lines
1.4 KiB
C#

using MediaBrowser.Common.Net.Handlers;
using MediaBrowser.Model.DTO;
using MediaBrowser.Model.Entities;
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))]
public class FavoriteStatus : BaseSerializationHandler<DTOUserItemData>
{
public override bool HandlesRequest(HttpListenerRequest request)
{
return ApiService.IsApiUrlMatch("FavoriteStatus", request);
}
protected override Task<DTOUserItemData> GetObjectToSerialize()
{
// 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);
if (data == null)
{
data = new UserItemData();
item.AddUserData(user, data);
}
// Set favorite status
data.IsFavorite = QueryString["isfavorite"] == "1";
return Task.FromResult<DTOUserItemData>(ApiService.GetDTOUserItemData(data));
}
}
}