fixes for new user data responses

This commit is contained in:
Luke Pulverenti 2013-08-22 21:36:34 -04:00
parent 48614c80e6
commit e95d56d2af
3 changed files with 72 additions and 79 deletions

View File

@ -508,25 +508,7 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="request">The request.</param>
public object Post(MarkFavoriteItem request)
{
var user = _userManager.GetUserById(request.UserId);
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
// Get the user data for this item
var key = item.GetUserDataKey();
var data = _userDataRepository.GetUserData(user.Id, key);
// Set favorite status
data.IsFavorite = true;
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
Task.WaitAll(task);
data = _userDataRepository.GetUserData(user.Id, key);
var dto = DtoBuilder.GetUserItemDataDto(data);
var dto = MarkFavorite(request.UserId, request.Id, true).Result;
return ToOptimizedResult(dto);
}
@ -537,9 +519,16 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="request">The request.</param>
public object Delete(UnmarkFavoriteItem request)
{
var user = _userManager.GetUserById(request.UserId);
var dto = MarkFavorite(request.UserId, request.Id, false).Result;
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
return ToOptimizedResult(dto);
}
private async Task<UserItemDataDto> MarkFavorite(Guid userId, string itemId, bool isFavorite)
{
var user = _userManager.GetUserById(userId);
var item = string.IsNullOrEmpty(itemId) ? user.RootFolder : DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id);
var key = item.GetUserDataKey();
@ -547,17 +536,13 @@ namespace MediaBrowser.Api.UserLibrary
var data = _userDataRepository.GetUserData(user.Id, key);
// Set favorite status
data.IsFavorite = false;
data.IsFavorite = isFavorite;
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
Task.WaitAll(task);
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
data = _userDataRepository.GetUserData(user.Id, key);
var dto = DtoBuilder.GetUserItemDataDto(data);
return ToOptimizedResult(dto);
return DtoBuilder.GetUserItemDataDto(data);
}
/// <summary>
@ -566,24 +551,7 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="request">The request.</param>
public object Delete(DeleteUserItemRating request)
{
var user = _userManager.GetUserById(request.UserId);
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
var key = item.GetUserDataKey();
// Get the user data for this item
var data = _userDataRepository.GetUserData(user.Id, key);
data.Rating = null;
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
Task.WaitAll(task);
data = _userDataRepository.GetUserData(user.Id, key);
var dto = DtoBuilder.GetUserItemDataDto(data);
var dto = UpdateUserItemRating(request.UserId, request.Id, null).Result;
return ToOptimizedResult(dto);
}
@ -594,28 +562,31 @@ namespace MediaBrowser.Api.UserLibrary
/// <param name="request">The request.</param>
public object Post(UpdateUserItemRating request)
{
var user = _userManager.GetUserById(request.UserId);
var dto = UpdateUserItemRating(request.UserId, request.Id, request.Likes).Result;
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
return ToOptimizedResult(dto);
}
private async Task<UserItemDataDto> UpdateUserItemRating(Guid userId, string itemId, bool? likes)
{
var user = _userManager.GetUserById(userId);
var item = string.IsNullOrEmpty(itemId) ? user.RootFolder : DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id);
var key = item.GetUserDataKey();
// Get the user data for this item
var data = _userDataRepository.GetUserData(user.Id, key);
data.Likes = request.Likes;
data.Likes = likes;
var task = _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None);
Task.WaitAll(task);
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
data = _userDataRepository.GetUserData(user.Id, key);
var dto = DtoBuilder.GetUserItemDataDto(data);
return ToOptimizedResult(dto);
return DtoBuilder.GetUserItemDataDto(data);
}
/// <summary>
/// Posts the specified request.
/// </summary>

View File

@ -2695,7 +2695,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2721,7 +2722,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2747,7 +2749,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "POST",
url: url
url: url,
dataType: "json"
});
};
@ -2773,7 +2776,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2793,7 +2797,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2813,7 +2818,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2833,7 +2839,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2853,7 +2860,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2873,7 +2881,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: method,
url: url
url: url,
dataType: "json"
});
};
@ -2899,7 +2908,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "POST",
url: url
url: url,
dataType: "json"
});
};
@ -2919,7 +2929,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "POST",
url: url
url: url,
dataType: "json"
});
};
@ -2939,7 +2950,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "POST",
url: url
url: url,
dataType: "json"
});
};
@ -2959,7 +2971,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "POST",
url: url
url: url,
dataType: "json"
});
};
@ -2979,7 +2992,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "POST",
url: url
url: url,
dataType: "json"
});
};
@ -2999,7 +3013,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "POST",
url: url
url: url,
dataType: "json"
});
};
@ -3022,7 +3037,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "DELETE",
url: url
url: url,
dataType: "json"
});
};
@ -3040,7 +3056,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "DELETE",
url: url
url: url,
dataType: "json"
});
};
@ -3058,7 +3075,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "DELETE",
url: url
url: url,
dataType: "json"
});
};
@ -3076,7 +3094,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "DELETE",
url: url
url: url,
dataType: "json"
});
};
@ -3094,7 +3113,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "DELETE",
url: url
url: url,
dataType: "json"
});
};
@ -3112,7 +3132,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "DELETE",
url: url
url: url,
dataType: "json"
});
};
@ -3290,7 +3311,8 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
return self.ajax({
type: "DELETE",
url: url
url: url,
dataType: "json"
});
};

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.160" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.164" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.58" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.58" targetFramework="net45" />
</packages>