Lidarr/src/Lidarr.Api.V1/RootFolders/RootFolderModule.cs

65 lines
2.4 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2017-09-04 02:20:56 +00:00
using FluentValidation;
using Lidarr.Http;
2017-09-04 02:20:56 +00:00
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.SignalR;
2017-10-31 01:28:29 +00:00
namespace Lidarr.Api.V1.RootFolders
2017-09-04 02:20:56 +00:00
{
public class RootFolderModule : LidarrRestModuleWithSignalR<RootFolderResource, RootFolder>
{
private readonly IRootFolderService _rootFolderService;
public RootFolderModule(IRootFolderService rootFolderService,
IBroadcastSignalRMessage signalRBroadcaster,
RootFolderValidator rootFolderValidator,
PathExistsValidator pathExistsValidator,
MappedNetworkDriveValidator mappedNetworkDriveValidator,
StartupFolderValidator startupFolderValidator,
SystemFolderValidator systemFolderValidator,
FolderWritableValidator folderWritableValidator)
2017-09-04 02:20:56 +00:00
: base(signalRBroadcaster)
{
_rootFolderService = rootFolderService;
GetResourceAll = GetRootFolders;
GetResourceById = GetRootFolder;
CreateResource = CreateRootFolder;
DeleteResource = DeleteFolder;
SharedValidator.RuleFor(c => c.Path)
.Cascade(CascadeMode.StopOnFirstFailure)
.IsValidPath()
.SetValidator(rootFolderValidator)
.SetValidator(mappedNetworkDriveValidator)
.SetValidator(startupFolderValidator)
.SetValidator(pathExistsValidator)
.SetValidator(systemFolderValidator)
.SetValidator(folderWritableValidator);
2017-09-04 02:20:56 +00:00
}
private RootFolderResource GetRootFolder(int id)
{
return _rootFolderService.Get(id).ToResource();
}
private int CreateRootFolder(RootFolderResource rootFolderResource)
{
var model = rootFolderResource.ToModel();
return _rootFolderService.Add(model).Id;
}
private List<RootFolderResource> GetRootFolders()
{
return _rootFolderService.AllWithUnmappedFolders().ToResource();
}
private void DeleteFolder(int id)
{
_rootFolderService.Remove(id);
}
}
}