2017-11-26 03:51:37 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using FluentValidation;
|
|
|
|
using Lidarr.Http;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.Profiles.Metadata;
|
2017-11-26 03:51:37 +00:00
|
|
|
|
|
|
|
namespace Lidarr.Api.V1.Profiles.Metadata
|
|
|
|
{
|
|
|
|
public class MetadataProfileModule : LidarrRestModule<MetadataProfileResource>
|
|
|
|
{
|
|
|
|
private readonly IMetadataProfileService _profileService;
|
|
|
|
|
|
|
|
public MetadataProfileModule(IMetadataProfileService profileService)
|
|
|
|
{
|
|
|
|
_profileService = profileService;
|
2019-12-16 21:21:32 +00:00
|
|
|
SharedValidator.RuleFor(c => c.Name).NotEqual("None").WithMessage("'None' is a reserved profile name").NotEmpty();
|
2017-11-26 03:51:37 +00:00
|
|
|
SharedValidator.RuleFor(c => c.PrimaryAlbumTypes).MustHaveAllowedPrimaryType();
|
|
|
|
SharedValidator.RuleFor(c => c.SecondaryAlbumTypes).MustHaveAllowedSecondaryType();
|
2018-03-22 00:43:10 +00:00
|
|
|
SharedValidator.RuleFor(c => c.ReleaseStatuses).MustHaveAllowedReleaseStatus();
|
2017-11-26 03:51:37 +00:00
|
|
|
|
|
|
|
GetResourceAll = GetAll;
|
|
|
|
GetResourceById = GetById;
|
|
|
|
UpdateResource = Update;
|
|
|
|
CreateResource = Create;
|
|
|
|
DeleteResource = DeleteProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int Create(MetadataProfileResource resource)
|
|
|
|
{
|
|
|
|
var model = resource.ToModel();
|
|
|
|
model = _profileService.Add(model);
|
|
|
|
return model.Id;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void DeleteProfile(int id)
|
|
|
|
{
|
|
|
|
_profileService.Delete(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update(MetadataProfileResource resource)
|
|
|
|
{
|
|
|
|
var model = resource.ToModel();
|
|
|
|
|
|
|
|
_profileService.Update(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
private MetadataProfileResource GetById(int id)
|
|
|
|
{
|
|
|
|
return _profileService.Get(id).ToResource();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<MetadataProfileResource> GetAll()
|
|
|
|
{
|
|
|
|
var profiles = _profileService.All().ToResource();
|
|
|
|
|
|
|
|
return profiles;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|