2013-01-29 02:59:18 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Nancy;
|
2013-02-23 21:35:26 +01:00
|
|
|
|
using NzbDrone.Api.Extensions;
|
2013-01-24 21:48:44 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2013-03-07 02:51:47 +01:00
|
|
|
|
|
2013-02-04 05:18:59 +01:00
|
|
|
|
using NzbDrone.Core.RootFolders;
|
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-02-18 02:45:14 +01:00
|
|
|
|
public class RootFolderModule : NzbDroneApiModule
|
2013-01-24 21:48:44 +01:00
|
|
|
|
{
|
2013-02-04 05:18:59 +01:00
|
|
|
|
private readonly RootFolderService _rootFolderService;
|
2013-01-24 21:48:44 +01:00
|
|
|
|
|
2013-02-18 02:45:14 +01:00
|
|
|
|
public RootFolderModule(RootFolderService rootFolderService)
|
|
|
|
|
: base("/rootfolder")
|
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
|
|
|
|
|
|
|
|
|
Get["/"] = x => GetRootFolders();
|
|
|
|
|
Post["/"] = x => AddRootFolder();
|
2013-02-16 04:50:22 +01:00
|
|
|
|
Delete["/{id}"] = x => DeleteRootFolder((int)x.id);
|
2013-01-24 21:48:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response AddRootFolder()
|
|
|
|
|
{
|
2013-02-05 05:07:07 +01:00
|
|
|
|
var dir = _rootFolderService.Add(Request.Body.FromJson<RootFolder>());
|
2013-01-25 02:22:14 +01:00
|
|
|
|
return dir.AsResponse(HttpStatusCode.Created);
|
2013-01-24 21:48:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Response GetRootFolders()
|
|
|
|
|
{
|
2013-02-04 05:18:59 +01:00
|
|
|
|
return _rootFolderService.All().AsResponse();
|
2013-01-24 21:48:44 +01:00
|
|
|
|
}
|
2013-01-25 02:22:14 +01:00
|
|
|
|
|
2013-02-16 04:50:22 +01:00
|
|
|
|
private Response DeleteRootFolder(int folderId)
|
2013-01-25 02:22:14 +01:00
|
|
|
|
{
|
2013-02-04 05:18:59 +01:00
|
|
|
|
_rootFolderService.Remove(folderId);
|
2013-01-25 02:22:14 +01:00
|
|
|
|
return new Response { StatusCode = HttpStatusCode.OK };
|
|
|
|
|
}
|
2013-01-24 21:48:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|