From 317586c1023fbbf75840cbca29960ec4f0d2e376 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 26 Aug 2013 00:14:46 -0700 Subject: [PATCH] added missing GetResourceById methods. --- NzbDrone.Api/Indexers/IndexerModule.cs | 8 ++++++++ NzbDrone.Api/Notifications/NotificationModule.cs | 12 +++++++++--- NzbDrone.Api/REST/RestModule.cs | 10 ++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Api/Indexers/IndexerModule.cs b/NzbDrone.Api/Indexers/IndexerModule.cs index 387b481b7..8a4439b87 100644 --- a/NzbDrone.Api/Indexers/IndexerModule.cs +++ b/NzbDrone.Api/Indexers/IndexerModule.cs @@ -6,6 +6,8 @@ using NzbDrone.Api.REST; using NzbDrone.Core.Indexers; using Omu.ValueInjecter; using FluentValidation; +using NzbDrone.Api.Extensions; +using NzbDrone.Api.Mapping; namespace NzbDrone.Api.Indexers { @@ -17,6 +19,7 @@ namespace NzbDrone.Api.Indexers { _indexerService = indexerService; GetResourceAll = GetAll; + GetResourceById = GetIndexer; CreateResource = CreateIndexer; UpdateResource = UpdateIndexer; DeleteResource = DeleteIndexer; @@ -28,6 +31,11 @@ namespace NzbDrone.Api.Indexers PostValidator.RuleFor(c => c.Fields).NotEmpty(); } + private IndexerResource GetIndexer(int id) + { + return _indexerService.Get(id).InjectTo(); + } + private List GetAll() { var indexers = _indexerService.All(); diff --git a/NzbDrone.Api/Notifications/NotificationModule.cs b/NzbDrone.Api/Notifications/NotificationModule.cs index 58ba9ed3e..bc7ca8aac 100644 --- a/NzbDrone.Api/Notifications/NotificationModule.cs +++ b/NzbDrone.Api/Notifications/NotificationModule.cs @@ -18,11 +18,17 @@ namespace NzbDrone.Api.Notifications _notificationService = notificationService; GetResourceAll = GetAll; + GetResourceById = GetNotification; CreateResource = Create; UpdateResource = Update; DeleteResource = DeleteNotification; } + private NotificationResource GetNotification(int id) + { + return _notificationService.Get(id).InjectTo(); + } + private List GetAll() { var notifications = _notificationService.All(); @@ -44,13 +50,13 @@ namespace NzbDrone.Api.Notifications private int Create(NotificationResource notificationResource) { - var notification = GetNotification(notificationResource); + var notification = ConvertToNotification(notificationResource); return _notificationService.Create(notification).Id; } private void Update(NotificationResource notificationResource) { - var notification = GetNotification(notificationResource); + var notification = ConvertToNotification(notificationResource); notification.Id = notificationResource.Id; _notificationService.Update(notification); } @@ -60,7 +66,7 @@ namespace NzbDrone.Api.Notifications _notificationService.Delete(id); } - private Notification GetNotification(NotificationResource notificationResource) + private Notification ConvertToNotification(NotificationResource notificationResource) { var notification = _notificationService.Schema() .SingleOrDefault(i => diff --git a/NzbDrone.Api/REST/RestModule.cs b/NzbDrone.Api/REST/RestModule.cs index f232e40d6..2b19bcc17 100644 --- a/NzbDrone.Api/REST/RestModule.cs +++ b/NzbDrone.Api/REST/RestModule.cs @@ -137,6 +137,7 @@ namespace NzbDrone.Api.REST private get { return _createResource; } set { + EnsureGetByIdRoute(); _createResource = value; Post[ROOT_ROUTE] = options => { @@ -147,6 +148,15 @@ namespace NzbDrone.Api.REST } } + private void EnsureGetByIdRoute() + { + if (GetResourceById == null) + { + throw new InvalidOperationException( + "GetResourceById route must be defined before defining Create/Update routes."); + } + } + protected Action UpdateResource { private get { return _updateResource; }