2013-01-29 01:59:18 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Nancy;
|
2013-01-25 19:03:28 +00:00
|
|
|
|
using NzbDrone.Api.Extentions;
|
2013-01-24 20:48:44 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
2013-02-04 04:18:59 +00:00
|
|
|
|
using NzbDrone.Core.RootFolders;
|
2013-01-24 20:48:44 +00:00
|
|
|
|
|
2013-01-29 01:59:18 +00:00
|
|
|
|
namespace NzbDrone.Api.RootFolders
|
2013-01-24 20:48:44 +00:00
|
|
|
|
{
|
2013-01-25 00:02:53 +00:00
|
|
|
|
public class RootDirModule : NzbDroneApiModule
|
2013-01-24 20:48:44 +00:00
|
|
|
|
{
|
2013-02-04 04:18:59 +00:00
|
|
|
|
private readonly RootFolderService _rootFolderService;
|
2013-01-24 20:48:44 +00:00
|
|
|
|
|
2013-02-04 04:18:59 +00:00
|
|
|
|
public RootDirModule(RootFolderService rootFolderService)
|
2013-01-25 00:02:53 +00:00
|
|
|
|
: base("//rootdir")
|
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
|
|
|
|
|
|
|
|
|
Get["/"] = x => GetRootFolders();
|
|
|
|
|
Post["/"] = x => AddRootFolder();
|
2013-02-08 08:05:43 +00:00
|
|
|
|
Delete["/{id}"] = x => DeleteRootFolder((long)x.id);
|
2013-01-24 20:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response AddRootFolder()
|
|
|
|
|
{
|
2013-02-05 04:07:07 +00:00
|
|
|
|
var dir = _rootFolderService.Add(Request.Body.FromJson<RootFolder>());
|
2013-01-25 01:22:14 +00:00
|
|
|
|
return dir.AsResponse(HttpStatusCode.Created);
|
2013-01-24 20:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetRootFolders()
|
|
|
|
|
{
|
2013-02-04 04:18:59 +00:00
|
|
|
|
return _rootFolderService.All().AsResponse();
|
2013-01-24 20:48:44 +00:00
|
|
|
|
}
|
2013-01-25 01:22:14 +00:00
|
|
|
|
|
2013-02-08 08:05:43 +00:00
|
|
|
|
private Response DeleteRootFolder(long folderId)
|
2013-01-25 01:22:14 +00:00
|
|
|
|
{
|
2013-02-04 04:18:59 +00:00
|
|
|
|
_rootFolderService.Remove(folderId);
|
2013-01-25 01:22:14 +00:00
|
|
|
|
return new Response { StatusCode = HttpStatusCode.OK };
|
|
|
|
|
}
|
2013-01-24 20:48:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|