1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-30 19:45:57 +00:00
Lidarr/NzbDrone.Api/QualityProfiles/QualityProfilesModule.cs

60 lines
1.8 KiB
C#
Raw Normal View History

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