added missing GetResourceById methods.

pull/3113/head
kay.one 11 years ago
parent 0fa4934358
commit 317586c102

@ -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<IndexerResource>();
}
private List<IndexerResource> GetAll()
{
var indexers = _indexerService.All();

@ -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<NotificationResource>();
}
private List<NotificationResource> 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 =>

@ -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<TResource> UpdateResource
{
private get { return _updateResource; }

Loading…
Cancel
Save