mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-14 17:13:49 -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
52
NzbDrone.Api/QualityType/QualityTypeModule.cs
Normal file
52
NzbDrone.Api/QualityType/QualityTypeModule.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.Providers;
|
||||
|
||||
namespace NzbDrone.Api.QualityType
|
||||
{
|
||||
public class QualityTypeModule : NancyModule
|
||||
{
|
||||
private readonly QualityTypeProvider _qualityTypeProvider;
|
||||
|
||||
public QualityTypeModule(QualityTypeProvider qualityTypeProvider)
|
||||
{
|
||||
_qualityTypeProvider = qualityTypeProvider;
|
||||
}
|
||||
|
||||
public QualityTypeModule()
|
||||
: base("/QualityTypes")
|
||||
{
|
||||
|
||||
Get["/"] = x => GetQualityType();
|
||||
Get["/{id}"] = x => GetQualityType(x.Id);
|
||||
Put["/"] = x => PutQualityType();
|
||||
}
|
||||
|
||||
private Response PutQualityType()
|
||||
{
|
||||
var model = Request.Body.FromJson<QualityTypeModel>();
|
||||
|
||||
var type = Mapper.Map<QualityTypeModel, Core.Repository.Quality.QualityType>(model);
|
||||
_qualityTypeProvider.Update(type);
|
||||
|
||||
return model.AsResponse();
|
||||
|
||||
}
|
||||
|
||||
private Response GetQualityType(int id)
|
||||
{
|
||||
var type = _qualityTypeProvider.Get(id);
|
||||
return Mapper.Map<Core.Repository.Quality.QualityType, QualityTypeModel>(type).AsResponse();
|
||||
}
|
||||
|
||||
private Response GetQualityType()
|
||||
{
|
||||
var types = _qualityTypeProvider.All().Where(qualityType => qualityType.QualityTypeId != 0 && qualityType.QualityTypeId != 10).ToList();
|
||||
var responseModel = Mapper.Map<List<Core.Repository.Quality.QualityType>, List<QualityTypeModel>>(types);
|
||||
|
||||
return responseModel.AsResponse();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue