2013-01-19 04:27:30 +03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using AutoMapper;
|
|
|
|
using Nancy;
|
2013-02-23 23:35:26 +03:00
|
|
|
using NzbDrone.Api.Extensions;
|
2013-02-27 06:19:22 +03:00
|
|
|
using NzbDrone.Core.Qualities;
|
2013-01-19 04:27:30 +03:00
|
|
|
|
2013-05-20 03:30:02 +03:00
|
|
|
namespace NzbDrone.Api.Qualities
|
2013-01-19 04:27:30 +03:00
|
|
|
{
|
2013-03-07 11:01:18 +03:00
|
|
|
public class QualitySizeModule : NzbDroneApiModule
|
2013-01-19 04:27:30 +03:00
|
|
|
{
|
2013-02-27 06:19:22 +03:00
|
|
|
private readonly QualitySizeService _qualityTypeProvider;
|
2013-01-19 04:27:30 +03:00
|
|
|
|
2013-03-07 11:01:18 +03:00
|
|
|
public QualitySizeModule(QualitySizeService qualityTypeProvider)
|
|
|
|
: base("/qualitysizes")
|
2013-01-19 04:27:30 +03:00
|
|
|
{
|
2013-01-20 03:19:27 +03:00
|
|
|
_qualityTypeProvider = qualityTypeProvider;
|
2013-01-19 04:27:30 +03:00
|
|
|
|
|
|
|
Get["/"] = x => GetQualityType();
|
|
|
|
Get["/{id}"] = x => GetQualityType(x.Id);
|
|
|
|
Put["/"] = x => PutQualityType();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Response PutQualityType()
|
|
|
|
{
|
2013-03-07 11:01:18 +03:00
|
|
|
var model = Request.Body.FromJson<QualitySizeResource>();
|
2013-01-19 04:27:30 +03:00
|
|
|
|
2013-03-07 11:01:18 +03:00
|
|
|
var type = Mapper.Map<QualitySizeResource, QualitySize>(model);
|
2013-01-19 04:27:30 +03:00
|
|
|
_qualityTypeProvider.Update(type);
|
|
|
|
|
|
|
|
return model.AsResponse();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private Response GetQualityType(int id)
|
|
|
|
{
|
|
|
|
var type = _qualityTypeProvider.Get(id);
|
2013-03-07 11:01:18 +03:00
|
|
|
return Mapper.Map<QualitySize, QualitySizeResource>(type).AsResponse();
|
2013-01-19 04:27:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private Response GetQualityType()
|
|
|
|
{
|
2013-02-27 06:19:22 +03:00
|
|
|
var types = _qualityTypeProvider.All().Where(qualityType => qualityType.QualityId != 0 && qualityType.QualityId != 10).ToList();
|
2013-03-07 11:01:18 +03:00
|
|
|
var responseModel = Mapper.Map<List<QualitySize>, List<QualitySizeResource>>(types);
|
2013-01-19 04:27:30 +03:00
|
|
|
|
|
|
|
return responseModel.AsResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|