2012-09-09 19:00:19 +00:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-09-11 01:34:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2012-09-09 19:00:19 +00:00
|
|
|
|
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 a user's rating for an item
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Export(typeof(BaseHandler))]
|
|
|
|
|
public class UserItemRatingHandler : BaseSerializationHandler<DTOUserItemData>
|
|
|
|
|
{
|
|
|
|
|
public override bool HandlesRequest(HttpListenerRequest request)
|
|
|
|
|
{
|
|
|
|
|
return ApiService.IsApiUrlMatch("UserItemRating", 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
|
2012-09-10 02:30:34 +00:00
|
|
|
|
UserItemData data = item.GetUserData(user, true);
|
2012-09-09 19:00:19 +00:00
|
|
|
|
|
|
|
|
|
// If clearing the rating, set it to null
|
|
|
|
|
if (QueryString["clear"] == "1")
|
|
|
|
|
{
|
|
|
|
|
data.Rating = null;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-09 19:06:56 +00:00
|
|
|
|
else
|
2012-09-09 19:00:19 +00:00
|
|
|
|
{
|
|
|
|
|
data.Likes = QueryString["likes"] == "1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Task.FromResult<DTOUserItemData>(ApiService.GetDTOUserItemData(data));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|