mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-07 05:22:14 -07:00
61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using FluentValidation.Results;
|
|
using NzbDrone.Api.Mapping;
|
|
using NzbDrone.Common.Extensions;
|
|
using NzbDrone.Core.Restrictions;
|
|
|
|
namespace NzbDrone.Api.Restrictions
|
|
{
|
|
public class RestrictionModule : NzbDroneRestModule<RestrictionResource>
|
|
{
|
|
private readonly IRestrictionService _restrictionService;
|
|
|
|
|
|
public RestrictionModule(IRestrictionService restrictionService)
|
|
{
|
|
_restrictionService = restrictionService;
|
|
|
|
GetResourceById = Get;
|
|
GetResourceAll = GetAll;
|
|
CreateResource = Create;
|
|
UpdateResource = Update;
|
|
DeleteResource = Delete;
|
|
|
|
SharedValidator.Custom(restriction =>
|
|
{
|
|
if (restriction.Ignored.IsNullOrWhiteSpace() && restriction.Required.IsNullOrWhiteSpace())
|
|
{
|
|
return new ValidationFailure("", "Either 'Must contaion' or 'Must not contain' is required");
|
|
}
|
|
|
|
return null;
|
|
});
|
|
}
|
|
|
|
private RestrictionResource Get(Int32 id)
|
|
{
|
|
return _restrictionService.Get(id).InjectTo<RestrictionResource>();
|
|
}
|
|
|
|
private List<RestrictionResource> GetAll()
|
|
{
|
|
return ToListResource(_restrictionService.All);
|
|
}
|
|
|
|
private Int32 Create(RestrictionResource resource)
|
|
{
|
|
return _restrictionService.Add(resource.InjectTo<Restriction>()).Id;
|
|
}
|
|
|
|
private void Update(RestrictionResource resource)
|
|
{
|
|
_restrictionService.Update(resource.InjectTo<Restriction>());
|
|
}
|
|
|
|
private void Delete(Int32 id)
|
|
{
|
|
_restrictionService.Delete(id);
|
|
}
|
|
}
|
|
}
|