mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 01:23:53 -07:00
replaced most of ServiceStack with nancy.
This commit is contained in:
parent
936886f213
commit
acef97b79f
22 changed files with 15057 additions and 334 deletions
66
NzbDrone.Api/QualityProfiles/QualityProfileModule.cs
Normal file
66
NzbDrone.Api/QualityProfiles/QualityProfileModule.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.Providers;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Api.QualityType;
|
||||
|
||||
namespace NzbDrone.Api.QualityProfiles
|
||||
{
|
||||
public class QualityProfileModule : NancyModule
|
||||
{
|
||||
private readonly QualityProvider _qualityProvider;
|
||||
|
||||
public QualityProfileModule(QualityProvider qualityProvider)
|
||||
{
|
||||
_qualityProvider = qualityProvider;
|
||||
}
|
||||
|
||||
public QualityProfileModule()
|
||||
: base("/QualityProfile")
|
||||
{
|
||||
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);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue