1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 10:32:35 +01:00
Radarr/NzbDrone.Api/RootFolders/RootFolderModule.cs
2013-09-12 15:42:01 -07:00

44 lines
1.3 KiB
C#

using System.Collections.Generic;
using NzbDrone.Core.RootFolders;
using NzbDrone.Api.Mapping;
using NzbDrone.Api.Validation;
namespace NzbDrone.Api.RootFolders
{
public class RootFolderModule : NzbDroneRestModule<RootFolderResource>
{
private readonly IRootFolderService _rootFolderService;
public RootFolderModule(IRootFolderService rootFolderService)
{
_rootFolderService = rootFolderService;
GetResourceAll = GetRootFolders;
GetResourceById = GetRootFolder;
CreateResource = CreateRootFolder;
DeleteResource = DeleteFolder;
SharedValidator.RuleFor(c=>c.Path).IsValidPath();
}
private RootFolderResource GetRootFolder(int id)
{
return _rootFolderService.Get(id).InjectTo<RootFolderResource>();
}
private int CreateRootFolder(RootFolderResource rootFolderResource)
{
return GetNewId<RootFolder>(_rootFolderService.Add, rootFolderResource);
}
private List<RootFolderResource> GetRootFolders()
{
return ToListResource(_rootFolderService.AllWithUnmappedFolders);
}
private void DeleteFolder(int id)
{
_rootFolderService.Remove(id);
}
}
}