sonarr-repo-only/NzbDrone.Api/QualityType/QualityTypeModule.cs

51 lines
1.5 KiB
C#
Raw Normal View History

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