1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 08:22:35 +01:00
Sonarr/NzbDrone.Api/Qualities/QualityProfilesModule.cs

60 lines
1.8 KiB
C#
Raw Normal View History

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-05-20 02:30:02 +02:00
namespace NzbDrone.Api.Qualities
{
2013-01-20 02:37:48 +01:00
public class QualityProfilesModule : NzbDroneApiModule
{
2013-02-27 04:19:22 +01:00
private readonly QualityProfileService _qualityProvider;
2013-02-27 04:19:22 +01:00
public QualityProfilesModule(QualityProfileService qualityProvider)
2013-01-20 02:37:48 +01:00
: base("/QualityProfiles")
{
_qualityProvider = qualityProvider;
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();
}
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();
}
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;
return request.AsResponse();
}
//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);
_qualityProvider.Update(profile);
return request.AsResponse();
}
private Response OnDelete(int id)
{
_qualityProvider.Delete(id);
return new Response();
}
}
}