mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
added missing GetResourceById methods.
This commit is contained in:
parent
0fa4934358
commit
317586c102
@ -6,6 +6,8 @@
|
||||
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 @@ public IndexerModule(IIndexerService indexerService)
|
||||
{
|
||||
_indexerService = indexerService;
|
||||
GetResourceAll = GetAll;
|
||||
GetResourceById = GetIndexer;
|
||||
CreateResource = CreateIndexer;
|
||||
UpdateResource = UpdateIndexer;
|
||||
DeleteResource = DeleteIndexer;
|
||||
@ -28,6 +31,11 @@ public IndexerModule(IIndexerService indexerService)
|
||||
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 @@ public NotificationModule(INotificationService notificationService)
|
||||
_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 @@ private List<NotificationResource> GetAll()
|
||||
|
||||
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 @@ private void DeleteNotification(int id)
|
||||
_notificationService.Delete(id);
|
||||
}
|
||||
|
||||
private Notification GetNotification(NotificationResource notificationResource)
|
||||
private Notification ConvertToNotification(NotificationResource notificationResource)
|
||||
{
|
||||
var notification = _notificationService.Schema()
|
||||
.SingleOrDefault(i =>
|
||||
|
@ -137,6 +137,7 @@ protected Func<TResource, int> CreateResource
|
||||
private get { return _createResource; }
|
||||
set
|
||||
{
|
||||
EnsureGetByIdRoute();
|
||||
_createResource = value;
|
||||
Post[ROOT_ROUTE] = options =>
|
||||
{
|
||||
@ -147,6 +148,15 @@ protected Func<TResource, int> CreateResource
|
||||
}
|
||||
}
|
||||
|
||||
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…
Reference in New Issue
Block a user