2013-01-19 01:27:30 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
using Nancy;
|
2013-01-20 00:19:27 +00:00
|
|
|
|
using NzbDrone.Api.QualityProfiles;
|
2013-01-19 01:27:30 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.QualityType
|
|
|
|
|
{
|
2013-01-20 00:19:27 +00:00
|
|
|
|
public class QualityTypeModule : NzbDroneApiModule
|
2013-01-19 01:27:30 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly QualityTypeProvider _qualityTypeProvider;
|
|
|
|
|
|
|
|
|
|
public QualityTypeModule(QualityTypeProvider qualityTypeProvider)
|
|
|
|
|
: base("/QualityTypes")
|
|
|
|
|
{
|
2013-01-20 00:19:27 +00:00
|
|
|
|
_qualityTypeProvider = qualityTypeProvider;
|
2013-01-19 01:27:30 +00:00
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|