You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readarr/NzbDrone.Api/QualityProfiles/QualityProfileService.cs

62 lines
1.7 KiB

using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using NzbDrone.Api.Filters;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository.Quality;
using ServiceStack.ServiceInterface;
namespace NzbDrone.Api.QualityProfiles
{
[ValidApiRequest]
public class QualityProfileService : RestServiceBase<QualityProfileModel>
{
private readonly QualityProvider _qualityProvider;
public QualityProfileService(QualityProvider qualityProvider)
{
_qualityProvider = qualityProvider;
}
public QualityProfileService()
{
}
public override object OnGet(QualityProfileModel request)
{
if (request.Id == 0)
{
var profiles = _qualityProvider.All();
return Mapper.Map<List<QualityProfile>, List<QualityProfileModel>>(profiles);
}
var profile = _qualityProvider.Get(request.Id);
return Mapper.Map<QualityProfile, QualityProfileModel>(profile);
}
//Create
public override object OnPost(QualityProfileModel request)
{
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
request.Id = _qualityProvider.Add(profile);
return request;
}
//Update
public override object OnPut(QualityProfileModel request)
{
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
_qualityProvider.Update(profile);
return request;
}
public override object OnDelete(QualityProfileModel request)
{
_qualityProvider.Delete(request.Id);
return request.Id.ToString();
}
}
}