1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Api/Qualities/QualitySizeModule.cs

49 lines
1.5 KiB
C#
Raw Normal View History

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