support saving ibn items

This commit is contained in:
Luke Pulverenti 2013-06-24 10:53:49 -04:00
parent d828e07be0
commit 73f1b34cce
3 changed files with 214 additions and 7 deletions

View File

@ -131,9 +131,50 @@ namespace MediaBrowser.Api
[Api(("Updates an item"))]
public class UpdateItem : BaseItemDto, IReturnVoid
{
[ApiMember(Name = "ItemId", Description = "The id of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string ItemId { get; set; }
}
[Route("/Artists/{ArtistName}", "POST")]
[Api(("Updates an artist"))]
public class UpdateArtist : BaseItemDto, IReturnVoid
{
[ApiMember(Name = "ArtistName", Description = "The name of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string ArtistName { get; set; }
}
[Route("/Studios/{StudioName}", "POST")]
[Api(("Updates a studio"))]
public class UpdateStudio : BaseItemDto, IReturnVoid
{
[ApiMember(Name = "StudioName", Description = "The name of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string StudioName { get; set; }
}
[Route("/Persons/{PersonName}", "POST")]
[Api(("Updates a person"))]
public class UpdatePerson : BaseItemDto, IReturnVoid
{
[ApiMember(Name = "PersonName", Description = "The name of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string PersonName { get; set; }
}
[Route("/MusicGenres/{GenreName}", "POST")]
[Api(("Updates a music genre"))]
public class UpdateMusicGenre : BaseItemDto, IReturnVoid
{
[ApiMember(Name = "GenreName", Description = "The name of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string GenreName { get; set; }
}
[Route("/Genres/{GenreName}", "POST")]
[Api(("Updates a genre"))]
public class UpdateGenre : BaseItemDto, IReturnVoid
{
[ApiMember(Name = "GenreName", Description = "The name of the item", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "POST")]
public string GenreName { get; set; }
}
/// <summary>
/// Class LibraryService
/// </summary>
@ -241,6 +282,93 @@ namespace MediaBrowser.Api
{
var item = DtoBuilder.GetItemByClientId(request.ItemId, _userManager, _libraryManager);
UpdateItem(request, item);
return _libraryManager.UpdateItem(item, CancellationToken.None);
}
public void Post(UpdatePerson request)
{
var task = UpdateItem(request);
Task.WaitAll(task);
}
private async Task UpdateItem(UpdatePerson request)
{
var item = await _libraryManager.GetPerson(request.PersonName).ConfigureAwait(false);
UpdateItem(request, item);
await _libraryManager.UpdateItem(item, CancellationToken.None).ConfigureAwait(false);
}
public void Post(UpdateArtist request)
{
var task = UpdateItem(request);
Task.WaitAll(task);
}
private async Task UpdateItem(UpdateArtist request)
{
var item = await _libraryManager.GetArtist(request.ArtistName).ConfigureAwait(false);
UpdateItem(request, item);
await _libraryManager.UpdateItem(item, CancellationToken.None).ConfigureAwait(false);
}
public void Post(UpdateStudio request)
{
var task = UpdateItem(request);
Task.WaitAll(task);
}
private async Task UpdateItem(UpdateStudio request)
{
var item = await _libraryManager.GetStudio(request.StudioName).ConfigureAwait(false);
UpdateItem(request, item);
await _libraryManager.UpdateItem(item, CancellationToken.None).ConfigureAwait(false);
}
public void Post(UpdateMusicGenre request)
{
var task = UpdateItem(request);
Task.WaitAll(task);
}
private async Task UpdateItem(UpdateMusicGenre request)
{
var item = await _libraryManager.GetMusicGenre(request.GenreName).ConfigureAwait(false);
UpdateItem(request, item);
await _libraryManager.UpdateItem(item, CancellationToken.None).ConfigureAwait(false);
}
public void Post(UpdateGenre request)
{
var task = UpdateItem(request);
Task.WaitAll(task);
}
private async Task UpdateItem(UpdateGenre request)
{
var item = await _libraryManager.GetGenre(request.GenreName).ConfigureAwait(false);
UpdateItem(request, item);
await _libraryManager.UpdateItem(item, CancellationToken.None).ConfigureAwait(false);
}
private void UpdateItem(BaseItemDto request, BaseItem item)
{
item.Name = request.Name;
item.ForcedSortName = request.SortName;
item.DisplayMediaType = request.DisplayMediaType;
@ -255,11 +383,11 @@ namespace MediaBrowser.Api
item.Overview = request.Overview;
item.Genres = request.Genres;
item.Tags = request.Tags;
item.Studios = request.Studios.Select(x=>x.Name).ToList();
item.People = request.People.Select(x=> new PersonInfo{Name = x.Name,Role = x.Role,Type = x.Type}).ToList();
item.Studios = request.Studios.Select(x => x.Name).ToList();
item.People = request.People.Select(x => new PersonInfo { Name = x.Name, Role = x.Role, Type = x.Type }).ToList();
item.EndDate = request.EndDate != default(DateTime) ? request.EndDate : null;
item.PremiereDate = request.PremiereDate != default(DateTime)? request.PremiereDate : null;
item.PremiereDate = request.PremiereDate != default(DateTime) ? request.PremiereDate : null;
item.ProductionYear = request.ProductionYear;
item.AspectRatio = request.AspectRatio;
item.Language = request.Language;
@ -315,7 +443,6 @@ namespace MediaBrowser.Api
series.AirDays = request.AirDays;
series.AirTime = request.AirTime;
}
return _libraryManager.UpdateItem(item, CancellationToken.None);
}
/// <summary>

View File

@ -1768,6 +1768,86 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
self.updateArtist = function (item) {
if (!item) {
throw new Error("null item");
}
var url = self.getUrl("Artists/" + self.encodeName(item.Name));
return self.ajax({
type: "POST",
url: url,
data: JSON.stringify(item),
contentType: "application/json"
});
};
self.updatePerson = function (item) {
if (!item) {
throw new Error("null item");
}
var url = self.getUrl("Persons/" + self.encodeName(item.Name));
return self.ajax({
type: "POST",
url: url,
data: JSON.stringify(item),
contentType: "application/json"
});
};
self.updateStudio = function (item) {
if (!item) {
throw new Error("null item");
}
var url = self.getUrl("Studios/" + self.encodeName(item.Name));
return self.ajax({
type: "POST",
url: url,
data: JSON.stringify(item),
contentType: "application/json"
});
};
self.updateGenre = function (item) {
if (!item) {
throw new Error("null item");
}
var url = self.getUrl("Genres/" + self.encodeName(item.Name));
return self.ajax({
type: "POST",
url: url,
data: JSON.stringify(item),
contentType: "application/json"
});
};
self.updateMusicGenres = function (item) {
if (!item) {
throw new Error("null item");
}
var url = self.getUrl("MusicGenres/" + self.encodeName(item.Name));
return self.ajax({
type: "POST",
url: url,
data: JSON.stringify(item),
contentType: "application/json"
});
};
/**
* Updates plugin security info
*/

View File

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