2014-06-08 08:22:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using FluentValidation;
|
|
|
|
|
using NzbDrone.Core.Profiles;
|
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Profiles
|
|
|
|
|
{
|
|
|
|
|
public class ProfileModule : NzbDroneRestModule<ProfileResource>
|
|
|
|
|
{
|
|
|
|
|
private readonly IProfileService _profileService;
|
|
|
|
|
|
|
|
|
|
public ProfileModule(IProfileService profileService)
|
|
|
|
|
{
|
|
|
|
|
_profileService = profileService;
|
|
|
|
|
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
|
|
|
|
SharedValidator.RuleFor(c => c.Cutoff).NotNull();
|
|
|
|
|
SharedValidator.RuleFor(c => c.Items).MustHaveAllowedQuality();
|
|
|
|
|
SharedValidator.RuleFor(c => c.Language).ValidLanguage();
|
|
|
|
|
|
|
|
|
|
GetResourceAll = GetAll;
|
|
|
|
|
GetResourceById = GetById;
|
|
|
|
|
UpdateResource = Update;
|
|
|
|
|
CreateResource = Create;
|
|
|
|
|
DeleteResource = DeleteProfile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int Create(ProfileResource resource)
|
|
|
|
|
{
|
2016-03-25 00:56:29 +00:00
|
|
|
|
var model = resource.ToModel();
|
|
|
|
|
|
|
|
|
|
return _profileService.Add(model).Id;
|
2014-06-08 08:22:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteProfile(int id)
|
|
|
|
|
{
|
|
|
|
|
_profileService.Delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update(ProfileResource resource)
|
|
|
|
|
{
|
2016-03-25 00:56:29 +00:00
|
|
|
|
var model = resource.ToModel();
|
2014-06-08 08:22:55 +00:00
|
|
|
|
|
|
|
|
|
_profileService.Update(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ProfileResource GetById(int id)
|
|
|
|
|
{
|
2016-03-25 00:56:29 +00:00
|
|
|
|
return _profileService.Get(id).ToResource();
|
2014-06-08 08:22:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ProfileResource> GetAll()
|
|
|
|
|
{
|
2016-03-25 00:56:29 +00:00
|
|
|
|
return _profileService.All().ToResource();
|
2014-06-08 08:22:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|