return newly updated user data after modifications
This commit is contained in:
parent
87a41bba76
commit
9427eb083f
|
@ -1,5 +1,7 @@
|
|||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using ServiceStack.ServiceHost;
|
||||
using ServiceStack.Text.Controller;
|
||||
using System;
|
||||
|
@ -18,7 +20,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
[Route("/Users/{UserId}/Favorites/MusicGenres/{Name}", "POST")]
|
||||
[Route("/Users/{UserId}/Favorites/GameGenres/{Name}", "POST")]
|
||||
[Api(Description = "Marks something as a favorite")]
|
||||
public class MarkItemByNameFavorite : IReturnVoid
|
||||
public class MarkItemByNameFavorite : IReturn<UserItemDataDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
|
@ -45,7 +47,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
[Route("/Users/{UserId}/Favorites/MusicGenres/{Name}", "DELETE")]
|
||||
[Route("/Users/{UserId}/Favorites/GameGenres/{Name}", "DELETE")]
|
||||
[Api(Description = "Unmarks something as a favorite")]
|
||||
public class UnmarkItemByNameFavorite : IReturnVoid
|
||||
public class UnmarkItemByNameFavorite : IReturn<UserItemDataDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
|
@ -71,7 +73,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
[Route("/Users/{UserId}/Ratings/Genres/{Name}", "POST")]
|
||||
[Route("/Users/{UserId}/Ratings/MusicGenres/{Name}", "POST")]
|
||||
[Api(Description = "Updates a user's rating for an item")]
|
||||
public class UpdateItemByNameRating : IReturnVoid
|
||||
public class UpdateItemByNameRating : IReturn<UserItemDataDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
|
@ -105,7 +107,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
[Route("/Users/{UserId}/Ratings/MusicGenres/{Name}", "DELETE")]
|
||||
[Route("/Users/{UserId}/Ratings/GameGenres/{Name}", "DELETE")]
|
||||
[Api(Description = "Deletes a user's saved personal rating for an item")]
|
||||
public class DeleteItemByNameRating : IReturnVoid
|
||||
public class DeleteItemByNameRating : IReturn<UserItemDataDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
|
@ -152,56 +154,56 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(MarkItemByNameFavorite request)
|
||||
public object Post(MarkItemByNameFavorite request)
|
||||
{
|
||||
var pathInfo = PathInfo.Parse(RequestContext.PathInfo);
|
||||
var type = pathInfo.GetArgumentValue<string>(3);
|
||||
|
||||
var task = MarkFavorite(request.UserId, type, request.Name, true);
|
||||
|
||||
Task.WaitAll(task);
|
||||
return ToOptimizedResult(task.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(UpdateItemByNameRating request)
|
||||
public object Post(UpdateItemByNameRating request)
|
||||
{
|
||||
var pathInfo = PathInfo.Parse(RequestContext.PathInfo);
|
||||
var type = pathInfo.GetArgumentValue<string>(3);
|
||||
|
||||
var task = MarkLike(request.UserId, type, request.Name, request.Likes);
|
||||
|
||||
Task.WaitAll(task);
|
||||
return ToOptimizedResult(task.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(UnmarkItemByNameFavorite request)
|
||||
public object Delete(UnmarkItemByNameFavorite request)
|
||||
{
|
||||
var pathInfo = PathInfo.Parse(RequestContext.PathInfo);
|
||||
var type = pathInfo.GetArgumentValue<string>(3);
|
||||
|
||||
var task = MarkFavorite(request.UserId, type, request.Name, false);
|
||||
|
||||
Task.WaitAll(task);
|
||||
return ToOptimizedResult(task.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(DeleteItemByNameRating request)
|
||||
public object Delete(DeleteItemByNameRating request)
|
||||
{
|
||||
var pathInfo = PathInfo.Parse(RequestContext.PathInfo);
|
||||
var type = pathInfo.GetArgumentValue<string>(3);
|
||||
|
||||
var task = MarkLike(request.UserId, type, request.Name, null);
|
||||
|
||||
Task.WaitAll(task);
|
||||
return ToOptimizedResult(task.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -212,7 +214,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// <param name="name">The name.</param>
|
||||
/// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected async Task MarkFavorite(Guid userId, string type, string name, bool isFavorite)
|
||||
protected async Task<UserItemDataDto> MarkFavorite(Guid userId, string type, string name, bool isFavorite)
|
||||
{
|
||||
var item = await GetItemByName(name, type, LibraryManager).ConfigureAwait(false);
|
||||
|
||||
|
@ -225,6 +227,10 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
data.IsFavorite = isFavorite;
|
||||
|
||||
await UserDataRepository.SaveUserData(userId, key, data, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
data = UserDataRepository.GetUserData(userId, key);
|
||||
|
||||
return DtoBuilder.GetUserItemDataDto(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -235,7 +241,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// <param name="name">The name.</param>
|
||||
/// <param name="likes">if set to <c>true</c> [likes].</param>
|
||||
/// <returns>Task.</returns>
|
||||
protected async Task MarkLike(Guid userId, string type, string name, bool? likes)
|
||||
protected async Task<UserItemDataDto> MarkLike(Guid userId, string type, string name, bool? likes)
|
||||
{
|
||||
var item = await GetItemByName(name, type, LibraryManager).ConfigureAwait(false);
|
||||
|
||||
|
@ -247,6 +253,10 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
data.Likes = likes;
|
||||
|
||||
await UserDataRepository.SaveUserData(userId, key, data, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
data = UserDataRepository.GetUserData(userId, key);
|
||||
|
||||
return DtoBuilder.GetUserItemDataDto(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetSpecialFeatures request)
|
||||
{
|
||||
var result = GetAsync(request);
|
||||
var result = GetAsync(request).Result;
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetLocalTrailers request)
|
||||
{
|
||||
var result = GetAsync(request);
|
||||
var result = GetAsync(request).Result;
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
@ -506,7 +506,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(MarkFavoriteItem request)
|
||||
public object Post(MarkFavoriteItem request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
|
@ -523,13 +523,19 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
|
||||
|
||||
Task.WaitAll(task);
|
||||
|
||||
data = _userDataRepository.GetUserData(user.Id, key);
|
||||
|
||||
var dto = DtoBuilder.GetUserItemDataDto(data);
|
||||
|
||||
return ToOptimizedResult(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(UnmarkFavoriteItem request)
|
||||
public object Delete(UnmarkFavoriteItem request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
|
@ -546,13 +552,19 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
|
||||
|
||||
Task.WaitAll(task);
|
||||
|
||||
data = _userDataRepository.GetUserData(user.Id, key);
|
||||
|
||||
var dto = DtoBuilder.GetUserItemDataDto(data);
|
||||
|
||||
return ToOptimizedResult(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(DeleteUserItemRating request)
|
||||
public object Delete(DeleteUserItemRating request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
|
@ -568,13 +580,19 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
|
||||
|
||||
Task.WaitAll(task);
|
||||
|
||||
data = _userDataRepository.GetUserData(user.Id, key);
|
||||
|
||||
var dto = DtoBuilder.GetUserItemDataDto(data);
|
||||
|
||||
return ToOptimizedResult(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(UpdateUserItemRating request)
|
||||
public object Post(UpdateUserItemRating request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
|
@ -590,19 +608,25 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
|
||||
|
||||
Task.WaitAll(task);
|
||||
|
||||
data = _userDataRepository.GetUserData(user.Id, key);
|
||||
|
||||
var dto = DtoBuilder.GetUserItemDataDto(data);
|
||||
|
||||
return ToOptimizedResult(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Posts the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Post(MarkPlayedItem request)
|
||||
public object Post(MarkPlayedItem request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
var task = UpdatePlayedStatus(user, request.Id, true);
|
||||
|
||||
Task.WaitAll(task);
|
||||
return ToOptimizedResult(task.Result);
|
||||
}
|
||||
|
||||
private SessionInfo GetSession()
|
||||
|
@ -669,13 +693,13 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// Deletes the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
public void Delete(MarkUnplayedItem request)
|
||||
public object Delete(MarkUnplayedItem request)
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
|
||||
var task = UpdatePlayedStatus(user, request.Id, false);
|
||||
|
||||
Task.WaitAll(task);
|
||||
return ToOptimizedResult(task.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -685,11 +709,13 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
/// <param name="itemId">The item id.</param>
|
||||
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
||||
/// <returns>Task.</returns>
|
||||
private Task UpdatePlayedStatus(User user, string itemId, bool wasPlayed)
|
||||
private async Task<UserItemDataDto> UpdatePlayedStatus(User user, string itemId, bool wasPlayed)
|
||||
{
|
||||
var item = DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id);
|
||||
|
||||
return item.SetPlayedStatus(user, wasPlayed, _userDataRepository);
|
||||
await item.SetPlayedStatus(user, wasPlayed, _userDataRepository).ConfigureAwait(false);
|
||||
|
||||
return DtoBuilder.GetUserItemDataDto(_userDataRepository.GetUserData(user.Id, item.GetUserDataKey()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ namespace MediaBrowser.Model.ApiClient
|
|||
/// <param name="wasPlayed">if set to <c>true</c> [was played].</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="ArgumentNullException">itemId</exception>
|
||||
Task UpdatePlayedStatusAsync(string itemId, string userId, bool wasPlayed);
|
||||
Task<UserItemDataDto> UpdatePlayedStatusAsync(string itemId, string userId, bool wasPlayed);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the favorite status async.
|
||||
|
@ -447,7 +447,7 @@ namespace MediaBrowser.Model.ApiClient
|
|||
/// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="ArgumentNullException">itemId</exception>
|
||||
Task UpdateFavoriteStatusAsync(string itemId, string userId, bool isFavorite);
|
||||
Task<UserItemDataDto> UpdateFavoriteStatusAsync(string itemId, string userId, bool isFavorite);
|
||||
|
||||
/// <summary>
|
||||
/// Reports to the server that the user has begun playing an item
|
||||
|
@ -518,7 +518,7 @@ namespace MediaBrowser.Model.ApiClient
|
|||
/// <param name="userId">The user id.</param>
|
||||
/// <returns>Task{UserItemDataDto}.</returns>
|
||||
/// <exception cref="ArgumentNullException">itemId</exception>
|
||||
Task ClearUserItemRatingAsync(string itemId, string userId);
|
||||
Task<UserItemDataDto> ClearUserItemRatingAsync(string itemId, string userId);
|
||||
|
||||
/// <summary>
|
||||
/// Updates a user's rating for an item, based on likes or dislikes
|
||||
|
@ -528,7 +528,7 @@ namespace MediaBrowser.Model.ApiClient
|
|||
/// <param name="likes">if set to <c>true</c> [likes].</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="ArgumentNullException">itemId</exception>
|
||||
Task UpdateUserItemRatingAsync(string itemId, string userId, bool likes);
|
||||
Task<UserItemDataDto> UpdateUserItemRatingAsync(string itemId, string userId, bool likes);
|
||||
|
||||
/// <summary>
|
||||
/// Authenticates a user and returns the result
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common.Internal</id>
|
||||
<version>3.0.183</version>
|
||||
<version>3.0.184</version>
|
||||
<title>MediaBrowser.Common.Internal</title>
|
||||
<authors>Luke</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.183" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.184" />
|
||||
<dependency id="NLog" version="2.0.1.2" />
|
||||
<dependency id="ServiceStack.Text" version="3.9.55" />
|
||||
<dependency id="SimpleInjector" version="2.3.0" />
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common</id>
|
||||
<version>3.0.183</version>
|
||||
<version>3.0.184</version>
|
||||
<title>MediaBrowser.Common</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Server.Core</id>
|
||||
<version>3.0.183</version>
|
||||
<version>3.0.184</version>
|
||||
<title>Media Browser.Server.Core</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains core components required to build plugins for Media Browser Server.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.183" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.184" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
|
Loading…
Reference in New Issue
Block a user