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