You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
7 years ago
|
using System.Collections.Generic;
|
||
|
using FluentValidation;
|
||
|
using NzbDrone.Core.Profiles.Metadata;
|
||
|
using Lidarr.Http;
|
||
|
|
||
|
namespace Lidarr.Api.V1.Profiles.Metadata
|
||
|
{
|
||
|
public class MetadataProfileModule : LidarrRestModule<MetadataProfileResource>
|
||
|
{
|
||
|
private readonly IMetadataProfileService _profileService;
|
||
|
|
||
|
public MetadataProfileModule(IMetadataProfileService profileService)
|
||
|
{
|
||
|
_profileService = profileService;
|
||
|
SharedValidator.RuleFor(c => c.Name).NotEmpty();
|
||
|
SharedValidator.RuleFor(c => c.PrimaryAlbumTypes).MustHaveAllowedPrimaryType();
|
||
|
SharedValidator.RuleFor(c => c.SecondaryAlbumTypes).MustHaveAllowedSecondaryType();
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|