1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 08:22:35 +01:00
Sonarr/NzbDrone.Api/Qualities/QualityProfilesModule.cs

58 lines
1.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2013-02-27 04:19:22 +01:00
using NzbDrone.Core.Qualities;
2013-05-31 02:12:20 +02:00
using NzbDrone.Api.Mapping;
2013-05-20 02:30:02 +02:00
namespace NzbDrone.Api.Qualities
{
2013-05-31 02:12:20 +02:00
public class QualityProfilesModule : NzbDroneRestModule<QualityProfileResource>
{
2013-02-27 04:19:22 +01:00
private readonly QualityProfileService _qualityProvider;
2013-02-27 04:19:22 +01:00
public QualityProfilesModule(QualityProfileService qualityProvider)
2013-05-31 02:12:20 +02:00
: base("/qualityProfiles")
{
_qualityProvider = qualityProvider;
2013-05-31 02:12:20 +02:00
GetResourceAll = GetAll;
GetResourceById = GetById;
UpdateResource = Update;
CreateResource = Create;
DeleteResource = DeleteProfile;
}
2013-05-31 02:12:20 +02:00
private QualityProfileResource Create(QualityProfileResource resource)
{
2013-05-31 02:12:20 +02:00
var model = resource.InjectTo<QualityProfile>();
model = _qualityProvider.Add(model);
return GetById(model.Id);
}
2013-05-31 02:12:20 +02:00
private void DeleteProfile(int id)
{
2013-05-31 02:12:20 +02:00
_qualityProvider.Delete(id);
}
2013-05-31 02:12:20 +02:00
private QualityProfileResource Update(QualityProfileResource resource)
{
2013-05-31 02:12:20 +02:00
var model = resource.InjectTo<QualityProfile>();
_qualityProvider.Update(model);
return GetById(resource.Id);
}
2013-05-31 02:12:20 +02:00
private QualityProfileResource GetById(int id)
{
2013-05-31 02:12:20 +02:00
return ToResource(() => _qualityProvider.Get(id));
}
2013-05-31 02:12:20 +02:00
private List<QualityProfileResource> GetAll()
{
2013-05-31 02:12:20 +02:00
return ToListResource(_qualityProvider.All);
}
2013-05-31 02:12:20 +02:00
}
}