1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-01 00:12:30 +01:00
Sonarr/NzbDrone.Api/RootFolders/RootFolderModule.cs
2013-02-15 16:52:48 -08:00

41 lines
1.1 KiB
C#

using System.Linq;
using Nancy;
using NzbDrone.Api.Extentions;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.RootFolders;
namespace NzbDrone.Api.RootFolders
{
public class RootDirModule : NzbDroneApiModule
{
private readonly RootFolderService _rootFolderService;
public RootDirModule(RootFolderService rootFolderService)
: base("//rootdir")
{
_rootFolderService = rootFolderService;
Get["/"] = x => GetRootFolders();
Post["/"] = x => AddRootFolder();
Delete["/{id}"] = x => DeleteRootFolder((int)x.id);
}
private Response AddRootFolder()
{
var dir = _rootFolderService.Add(Request.Body.FromJson<RootDir>());
return dir.AsResponse(HttpStatusCode.Created);
}
private Response GetRootFolders()
{
return _rootFolderService.All().AsResponse();
}
private Response DeleteRootFolder(int folderId)
{
_rootFolderService.Remove(folderId);
return new Response { StatusCode = HttpStatusCode.OK };
}
}
}