2013-01-19 02:27:30 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Nancy;
|
2013-02-23 21:35:26 +01:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-02-27 04:19:22 +01:00
|
|
|
|
using NzbDrone.Core.Qualities;
|
2013-01-19 02:27:30 +01:00
|
|
|
|
|
2013-05-20 02:30:02 +02:00
|
|
|
|
namespace NzbDrone.Api.Qualities
|
2013-01-19 02:27:30 +01:00
|
|
|
|
{
|
2013-01-20 02:37:48 +01:00
|
|
|
|
public class QualityProfilesModule : NzbDroneApiModule
|
2013-01-19 02:27:30 +01:00
|
|
|
|
{
|
2013-02-27 04:19:22 +01:00
|
|
|
|
private readonly QualityProfileService _qualityProvider;
|
2013-01-19 02:27:30 +01:00
|
|
|
|
|
2013-02-27 04:19:22 +01:00
|
|
|
|
public QualityProfilesModule(QualityProfileService qualityProvider)
|
2013-01-20 02:37:48 +01:00
|
|
|
|
: base("/QualityProfiles")
|
2013-01-19 02:27:30 +01:00
|
|
|
|
{
|
2013-01-20 01:19:27 +01:00
|
|
|
|
_qualityProvider = qualityProvider;
|
2013-01-19 02:27:30 +01: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();
|
2013-05-20 02:30:02 +02:00
|
|
|
|
return Mapper.Map<List<QualityProfile>, List<QualityProfileResource>>(profiles).AsResponse();
|
2013-01-19 02:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response OnGet(int id)
|
|
|
|
|
{
|
|
|
|
|
var profile = _qualityProvider.Get(id);
|
2013-05-20 02:30:02 +02:00
|
|
|
|
return Mapper.Map<QualityProfile, QualityProfileResource>(profile).AsResponse();
|
2013-01-19 02:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response OnPost()
|
|
|
|
|
{
|
2013-05-20 02:30:02 +02:00
|
|
|
|
var request = Request.Body.FromJson<QualityProfileResource>();
|
|
|
|
|
var profile = Mapper.Map<QualityProfileResource, QualityProfile>(request);
|
2013-02-27 04:19:22 +01:00
|
|
|
|
request.Id = _qualityProvider.Add(profile).Id;
|
2013-01-19 02:27:30 +01:00
|
|
|
|
|
2013-01-20 01:19:27 +01:00
|
|
|
|
return request.AsResponse();
|
2013-01-19 02:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Update
|
|
|
|
|
private Response OnPut()
|
|
|
|
|
{
|
2013-05-20 02:30:02 +02:00
|
|
|
|
var request = Request.Body.FromJson<QualityProfileResource>();
|
|
|
|
|
var profile = Mapper.Map<QualityProfileResource, QualityProfile>(request);
|
2013-01-19 02:27:30 +01:00
|
|
|
|
_qualityProvider.Update(profile);
|
|
|
|
|
|
2013-01-20 01:19:27 +01:00
|
|
|
|
return request.AsResponse();
|
2013-01-19 02:27:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response OnDelete(int id)
|
|
|
|
|
{
|
|
|
|
|
_qualityProvider.Delete(id);
|
|
|
|
|
return new Response();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|