Sonarr/NzbDrone.Api/RootFolders/RootFolderModule.cs

45 lines
1.3 KiB
C#
Raw Normal View History

2013-08-26 05:25:56 +00:00
using System;
using System.Collections.Generic;
2013-02-04 04:18:59 +00:00
using NzbDrone.Core.RootFolders;
2013-08-26 05:25:56 +00:00
using NzbDrone.Api.Mapping;
using NzbDrone.Api.Validation;
2013-01-24 20:48:44 +00:00
namespace NzbDrone.Api.RootFolders
2013-01-24 20:48:44 +00:00
{
public class RootFolderModule : NzbDroneRestModule<RootFolderResource>
2013-01-24 20:48:44 +00:00
{
2013-08-21 01:17:06 +00:00
private readonly IRootFolderService _rootFolderService;
2013-01-24 20:48:44 +00:00
2013-08-21 01:17:06 +00:00
public RootFolderModule(IRootFolderService rootFolderService)
2013-01-24 20:48:44 +00:00
{
2013-02-04 04:18:59 +00:00
_rootFolderService = rootFolderService;
2013-01-24 20:48:44 +00:00
GetResourceAll = GetRootFolders;
2013-08-26 05:25:56 +00:00
GetResourceById = GetRootFolder;
CreateResource = CreateRootFolder;
DeleteResource = DeleteFolder;
SharedValidator.RuleFor(c=>c.Path).IsValidPath();
2013-01-24 20:48:44 +00:00
}
2013-08-26 05:25:56 +00:00
private RootFolderResource GetRootFolder(int id)
{
return _rootFolderService.Get(id).InjectTo<RootFolderResource>();
}
private int CreateRootFolder(RootFolderResource rootFolderResource)
2013-01-24 20:48:44 +00:00
{
return GetNewId<RootFolder>(_rootFolderService.Add, rootFolderResource);
2013-01-24 20:48:44 +00:00
}
private List<RootFolderResource> GetRootFolders()
2013-01-24 20:48:44 +00:00
{
2013-05-31 00:12:20 +00:00
return ToListResource(_rootFolderService.AllWithUnmappedFolders);
2013-01-24 20:48:44 +00:00
}
private void DeleteFolder(int id)
{
_rootFolderService.Remove(id);
}
2013-01-24 20:48:44 +00:00
}
}