2013-01-19 01:27:30 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
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;
|
2013-01-19 01:27:30 +00:00
|
|
|
|
|
2013-05-20 00:30:02 +00:00
|
|
|
|
namespace NzbDrone.Api.Qualities
|
2013-01-19 01:27:30 +00:00
|
|
|
|
{
|
2013-03-07 08:01:18 +00:00
|
|
|
|
public class QualitySizeModule : NzbDroneApiModule
|
2013-01-19 01:27:30 +00:00
|
|
|
|
{
|
2013-02-27 03:19:22 +00:00
|
|
|
|
private readonly QualitySizeService _qualityTypeProvider;
|
2013-01-19 01:27:30 +00:00
|
|
|
|
|
2013-03-07 08:01:18 +00:00
|
|
|
|
public QualitySizeModule(QualitySizeService qualityTypeProvider)
|
|
|
|
|
: base("/qualitysizes")
|
2013-01-19 01:27:30 +00:00
|
|
|
|
{
|
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()
|
|
|
|
|
{
|
2013-03-07 08:01:18 +00:00
|
|
|
|
var model = Request.Body.FromJson<QualitySizeResource>();
|
2013-01-19 01:27:30 +00:00
|
|
|
|
|
2013-03-07 08:01:18 +00:00
|
|
|
|
var type = Mapper.Map<QualitySizeResource, QualitySize>(model);
|
2013-01-19 01:27:30 +00:00
|
|
|
|
_qualityTypeProvider.Update(type);
|
|
|
|
|
|
|
|
|
|
return model.AsResponse();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetQualityType(int id)
|
|
|
|
|
{
|
|
|
|
|
var type = _qualityTypeProvider.Get(id);
|
2013-03-07 08:01:18 +00:00
|
|
|
|
return Mapper.Map<QualitySize, QualitySizeResource>(type).AsResponse();
|
2013-01-19 01:27:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetQualityType()
|
|
|
|
|
{
|
2013-02-27 03:19:22 +00:00
|
|
|
|
var types = _qualityTypeProvider.All().Where(qualityType => qualityType.QualityId != 0 && qualityType.QualityId != 10).ToList();
|
2013-03-07 08:01:18 +00:00
|
|
|
|
var responseModel = Mapper.Map<List<QualitySize>, List<QualitySizeResource>>(types);
|
2013-01-19 01:27:30 +00:00
|
|
|
|
|
|
|
|
|
return responseModel.AsResponse();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|