2017-11-16 02:24:33 +00:00
|
|
|
using System.Collections.Generic;
|
2017-09-04 02:20:56 +00:00
|
|
|
using FluentValidation;
|
|
|
|
using Lidarr.Http;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.Profiles.Qualities;
|
2017-09-04 02:20:56 +00:00
|
|
|
|
2017-10-31 01:28:29 +00:00
|
|
|
namespace Lidarr.Api.V1.Profiles.Quality
|
2017-09-04 02:20:56 +00:00
|
|
|
{
|
|
|
|
public class ProfileModule : LidarrRestModule<QualityProfileResource>
|
|
|
|
{
|
|
|
|
private readonly IProfileService _profileService;
|
|
|
|
|
|
|
|
public ProfileModule(IProfileService profileService)
|
|
|
|
{
|
|
|
|
_profileService = profileService;
|
|
|
|
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
2017-11-16 02:24:33 +00:00
|
|
|
SharedValidator.RuleFor(c => c.Cutoff).ValidCutoff();
|
|
|
|
SharedValidator.RuleFor(c => c.Items).ValidItems();
|
2017-09-04 02:20:56 +00:00
|
|
|
|
|
|
|
GetResourceAll = GetAll;
|
|
|
|
GetResourceById = GetById;
|
|
|
|
UpdateResource = Update;
|
|
|
|
CreateResource = Create;
|
|
|
|
DeleteResource = DeleteProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int Create(QualityProfileResource resource)
|
|
|
|
{
|
|
|
|
var model = resource.ToModel();
|
|
|
|
model = _profileService.Add(model);
|
|
|
|
return model.Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DeleteProfile(int id)
|
|
|
|
{
|
|
|
|
_profileService.Delete(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update(QualityProfileResource resource)
|
|
|
|
{
|
|
|
|
var model = resource.ToModel();
|
|
|
|
|
|
|
|
_profileService.Update(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
private QualityProfileResource GetById(int id)
|
|
|
|
{
|
|
|
|
return _profileService.Get(id).ToResource();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<QualityProfileResource> GetAll()
|
|
|
|
{
|
|
|
|
return _profileService.All().ToResource();
|
|
|
|
}
|
|
|
|
}
|
2017-11-16 02:24:33 +00:00
|
|
|
}
|