added missing GetResourceById methods.

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

@ -6,6 +6,8 @@ using NzbDrone.Api.REST;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using Omu.ValueInjecter; using Omu.ValueInjecter;
using FluentValidation; using FluentValidation;
using NzbDrone.Api.Extensions;
using NzbDrone.Api.Mapping;
namespace NzbDrone.Api.Indexers namespace NzbDrone.Api.Indexers
{ {
@ -17,6 +19,7 @@ namespace NzbDrone.Api.Indexers
{ {
_indexerService = indexerService; _indexerService = indexerService;
GetResourceAll = GetAll; GetResourceAll = GetAll;
GetResourceById = GetIndexer;
CreateResource = CreateIndexer; CreateResource = CreateIndexer;
UpdateResource = UpdateIndexer; UpdateResource = UpdateIndexer;
DeleteResource = DeleteIndexer; DeleteResource = DeleteIndexer;
@ -28,6 +31,11 @@ namespace NzbDrone.Api.Indexers
PostValidator.RuleFor(c => c.Fields).NotEmpty(); PostValidator.RuleFor(c => c.Fields).NotEmpty();
} }
private IndexerResource GetIndexer(int id)
{
return _indexerService.Get(id).InjectTo<IndexerResource>();
}
private List<IndexerResource> GetAll() private List<IndexerResource> GetAll()
{ {
var indexers = _indexerService.All(); var indexers = _indexerService.All();

@ -18,11 +18,17 @@ namespace NzbDrone.Api.Notifications
_notificationService = notificationService; _notificationService = notificationService;
GetResourceAll = GetAll; GetResourceAll = GetAll;
GetResourceById = GetNotification;
CreateResource = Create; CreateResource = Create;
UpdateResource = Update; UpdateResource = Update;
DeleteResource = DeleteNotification; DeleteResource = DeleteNotification;
} }
private NotificationResource GetNotification(int id)
{
return _notificationService.Get(id).InjectTo<NotificationResource>();
}
private List<NotificationResource> GetAll() private List<NotificationResource> GetAll()
{ {
var notifications = _notificationService.All(); var notifications = _notificationService.All();
@ -44,13 +50,13 @@ namespace NzbDrone.Api.Notifications
private int Create(NotificationResource notificationResource) private int Create(NotificationResource notificationResource)
{ {
var notification = GetNotification(notificationResource); var notification = ConvertToNotification(notificationResource);
return _notificationService.Create(notification).Id; return _notificationService.Create(notification).Id;
} }
private void Update(NotificationResource notificationResource) private void Update(NotificationResource notificationResource)
{ {
var notification = GetNotification(notificationResource); var notification = ConvertToNotification(notificationResource);
notification.Id = notificationResource.Id; notification.Id = notificationResource.Id;
_notificationService.Update(notification); _notificationService.Update(notification);
} }
@ -60,7 +66,7 @@ namespace NzbDrone.Api.Notifications
_notificationService.Delete(id); _notificationService.Delete(id);
} }
private Notification GetNotification(NotificationResource notificationResource) private Notification ConvertToNotification(NotificationResource notificationResource)
{ {
var notification = _notificationService.Schema() var notification = _notificationService.Schema()
.SingleOrDefault(i => .SingleOrDefault(i =>

@ -137,6 +137,7 @@ namespace NzbDrone.Api.REST
private get { return _createResource; } private get { return _createResource; }
set set
{ {
EnsureGetByIdRoute();
_createResource = value; _createResource = value;
Post[ROOT_ROUTE] = options => 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 protected Action<TResource> UpdateResource
{ {
private get { return _updateResource; } private get { return _updateResource; }

Loading…
Cancel
Save