2013-01-19 01:27:30 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Nancy;
|
2013-02-23 20:35:26 +00:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-01-19 01:27:30 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
|
|
|
|
using NzbDrone.Api.QualityType;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.QualityProfiles
|
|
|
|
|
{
|
2013-01-20 01:37:48 +00:00
|
|
|
|
public class QualityProfilesModule : NzbDroneApiModule
|
2013-01-19 01:27:30 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly QualityProvider _qualityProvider;
|
|
|
|
|
|
2013-01-20 01:37:48 +00:00
|
|
|
|
public QualityProfilesModule(QualityProvider qualityProvider)
|
|
|
|
|
: base("/QualityProfiles")
|
2013-01-19 01:27:30 +00:00
|
|
|
|
{
|
2013-01-20 00:19:27 +00:00
|
|
|
|
_qualityProvider = qualityProvider;
|
2013-01-19 01:27:30 +00:00
|
|
|
|
Get["/"] = x => OnGet();
|
|
|
|
|
Get["/{Id}"] = x => OnGet((int)x.Id);
|
|
|
|
|
Put["/"] = x => OnPut();
|
|
|
|
|
Delete["/{Id}"] = x => OnDelete((int)x.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response OnGet()
|
|
|
|
|
{
|
|
|
|
|
var profiles = _qualityProvider.All();
|
|
|
|
|
return Mapper.Map<List<QualityProfile>, List<QualityProfileModel>>(profiles).AsResponse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response OnGet(int id)
|
|
|
|
|
{
|
|
|
|
|
var profile = _qualityProvider.Get(id);
|
|
|
|
|
return Mapper.Map<QualityProfile, QualityProfileModel>(profile).AsResponse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response OnPost()
|
|
|
|
|
{
|
|
|
|
|
var request = Request.Body.FromJson<QualityProfileModel>();
|
|
|
|
|
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
|
|
|
|
|
request.Id = _qualityProvider.Add(profile);
|
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
return request.AsResponse();
|
2013-01-19 01:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Update
|
|
|
|
|
private Response OnPut()
|
|
|
|
|
{
|
|
|
|
|
var request = Request.Body.FromJson<QualityProfileModel>();
|
|
|
|
|
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
|
|
|
|
|
_qualityProvider.Update(profile);
|
|
|
|
|
|
2013-01-20 00:19:27 +00:00
|
|
|
|
return request.AsResponse();
|
2013-01-19 01:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response OnDelete(int id)
|
|
|
|
|
{
|
|
|
|
|
_qualityProvider.Delete(id);
|
|
|
|
|
return new Response();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|