2012-11-04 01:39:29 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoMapper;
|
2012-11-03 18:23:47 +00:00
|
|
|
|
using Ninject;
|
2012-11-02 07:35:49 +00:00
|
|
|
|
using NzbDrone.Api.Filters;
|
2012-11-03 18:23:47 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-11-04 01:39:29 +00:00
|
|
|
|
using NzbDrone.Core.Repository.Quality;
|
2012-11-02 07:35:49 +00:00
|
|
|
|
using ServiceStack.ServiceInterface;
|
|
|
|
|
|
2012-11-03 18:23:47 +00:00
|
|
|
|
namespace NzbDrone.Api.QualityProfiles
|
2012-11-02 07:35:49 +00:00
|
|
|
|
{
|
|
|
|
|
[ValidApiRequest]
|
2012-11-04 01:39:29 +00:00
|
|
|
|
public class QualityProfileService : RestServiceBase<QualityProfileModel>
|
2012-11-02 07:35:49 +00:00
|
|
|
|
{
|
2012-11-03 18:23:47 +00:00
|
|
|
|
private readonly QualityProvider _qualityProvider;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public QualityProfileService(QualityProvider qualityProvider)
|
|
|
|
|
{
|
|
|
|
|
_qualityProvider = qualityProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public QualityProfileService()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-04 01:39:29 +00:00
|
|
|
|
public override object OnGet(QualityProfileModel request)
|
2012-11-02 07:35:49 +00:00
|
|
|
|
{
|
2012-11-03 18:23:47 +00:00
|
|
|
|
if (request.Id == 0)
|
|
|
|
|
{
|
|
|
|
|
var profiles = _qualityProvider.All();
|
2012-12-03 03:08:26 +00:00
|
|
|
|
return Mapper.Map<List<QualityProfile>, List<QualityProfileModel>>(profiles);
|
2012-11-03 18:23:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var profile = _qualityProvider.Get(request.Id);
|
2012-12-03 03:08:26 +00:00
|
|
|
|
return Mapper.Map<QualityProfile, QualityProfileModel>(profile);
|
2012-11-02 07:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-05 16:34:43 +00:00
|
|
|
|
//Create
|
|
|
|
|
public override object OnPost(QualityProfileModel request)
|
2012-11-04 01:39:29 +00:00
|
|
|
|
{
|
2012-12-05 16:34:43 +00:00
|
|
|
|
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
|
2012-12-11 04:39:35 +00:00
|
|
|
|
request.Id = _qualityProvider.Add(profile);
|
|
|
|
|
|
2012-12-05 16:34:43 +00:00
|
|
|
|
return request;
|
2012-11-04 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-05 16:34:43 +00:00
|
|
|
|
//Update
|
|
|
|
|
public override object OnPut(QualityProfileModel request)
|
2012-11-04 01:39:29 +00:00
|
|
|
|
{
|
2012-12-05 16:34:43 +00:00
|
|
|
|
var profile = Mapper.Map<QualityProfileModel, QualityProfile>(request);
|
2012-12-03 03:08:26 +00:00
|
|
|
|
_qualityProvider.Update(profile);
|
2012-11-04 01:39:29 +00:00
|
|
|
|
|
2012-12-05 16:34:43 +00:00
|
|
|
|
return request;
|
2012-11-04 01:39:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-05 16:34:43 +00:00
|
|
|
|
public override object OnDelete(QualityProfileModel request)
|
2012-11-04 01:39:29 +00:00
|
|
|
|
{
|
2012-12-05 16:34:43 +00:00
|
|
|
|
_qualityProvider.Delete(request.Id);
|
2012-11-04 01:39:29 +00:00
|
|
|
|
|
2012-12-05 16:34:43 +00:00
|
|
|
|
return request.Id.ToString();
|
2012-11-04 01:39:29 +00:00
|
|
|
|
}
|
2012-11-02 07:35:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|