1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2025-01-17 10:45:49 +02:00
Sonarr/NzbDrone.Api/RootFolders/RootFolderModule.cs

41 lines
1.1 KiB
C#
Raw Normal View History

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