jellyfin/MediaBrowser.Api/Sync/SyncService.cs

103 lines
3.5 KiB
C#
Raw Normal View History

2014-07-17 22:21:35 +00:00
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Querying;
using MediaBrowser.Model.Sync;
using ServiceStack;
2014-07-22 16:36:34 +00:00
using System.Collections.Generic;
2014-07-17 22:21:35 +00:00
using System.Threading.Tasks;
namespace MediaBrowser.Api.Sync
{
[Route("/Sync/Jobs/{Id}", "DELETE", Summary = "Cancels a sync job.")]
public class CancelSyncJob : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}
[Route("/Sync/Jobs/{Id}", "GET", Summary = "Gets a sync job.")]
public class GetSyncJob : IReturn<SyncJob>
{
[ApiMember(Name = "Id", Description = "Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string Id { get; set; }
}
[Route("/Sync/Jobs", "GET", Summary = "Gets sync jobs.")]
public class GetSyncJobs : IReturn<QueryResult<SyncJob>>
{
2014-07-26 17:30:15 +00:00
/// <summary>
/// Skips over a given number of items within the results. Use for paging.
/// </summary>
/// <value>The start index.</value>
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
/// <summary>
/// The maximum number of items to return
/// </summary>
/// <value>The limit.</value>
[ApiMember(Name = "Limit", Description = "Optional. The maximum number of records to return", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? Limit { get; set; }
2014-07-17 22:21:35 +00:00
}
[Route("/Sync/Jobs", "POST", Summary = "Gets sync jobs.")]
2014-07-26 17:30:15 +00:00
public class CreateSyncJob : SyncJobRequest, IReturn<SyncJobCreationResult>
{
}
2014-07-22 16:36:34 +00:00
[Route("/Sync/Targets", "GET", Summary = "Gets a list of available sync targets.")]
public class GetSyncTarget : IReturn<List<SyncTarget>>
{
2014-07-22 16:36:34 +00:00
[ApiMember(Name = "UserId", Description = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string UserId { get; set; }
}
2014-07-17 22:21:35 +00:00
[Authenticated]
public class SyncService : BaseApiService
{
private readonly ISyncManager _syncManager;
public SyncService(ISyncManager syncManager)
{
_syncManager = syncManager;
}
2014-07-22 16:36:34 +00:00
public object Get(GetSyncTarget request)
{
var result = _syncManager.GetSyncTargets(request.UserId);
return ToOptimizedResult(result);
}
2014-07-17 22:21:35 +00:00
public object Get(GetSyncJobs request)
{
var result = _syncManager.GetJobs(new SyncJobQuery
{
2014-07-26 17:30:15 +00:00
StartIndex = request.StartIndex,
Limit = request.Limit
2014-07-17 22:21:35 +00:00
});
return ToOptimizedResult(result);
}
public object Get(GetSyncJob request)
{
var result = _syncManager.GetJob(request.Id);
return ToOptimizedResult(result);
}
2014-08-17 05:38:13 +00:00
public Task Delete(CancelSyncJob request)
2014-07-17 22:21:35 +00:00
{
2014-08-17 05:38:13 +00:00
return _syncManager.CancelJob(request.Id);
2014-07-17 22:21:35 +00:00
}
2014-08-17 05:38:13 +00:00
public async Task<object> Post(CreateSyncJob request)
2014-07-17 22:21:35 +00:00
{
2014-08-17 05:38:13 +00:00
var result = await _syncManager.CreateJob(request).ConfigureAwait(false);
2014-07-17 22:21:35 +00:00
2014-07-26 17:30:15 +00:00
return ToOptimizedResult(result);
}
2014-07-17 22:21:35 +00:00
}
}