|
|
|
@ -5,14 +5,21 @@ using FluentValidation.Results;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
|
using NzbDrone.Common.Serializer;
|
|
|
|
|
using NzbDrone.Core.Datastore.Events;
|
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
|
|
|
|
using NzbDrone.Core.ThingiProvider.Events;
|
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
|
using NzbDrone.SignalR;
|
|
|
|
|
using Radarr.Http.REST;
|
|
|
|
|
using Radarr.Http.REST.Attributes;
|
|
|
|
|
|
|
|
|
|
namespace Radarr.Api.V3
|
|
|
|
|
{
|
|
|
|
|
public abstract class ProviderControllerBase<TProviderResource, TBulkProviderResource, TProvider, TProviderDefinition> : RestController<TProviderResource>
|
|
|
|
|
public abstract class ProviderControllerBase<TProviderResource, TBulkProviderResource, TProvider, TProviderDefinition> : RestControllerWithSignalR<TProviderResource, TProviderDefinition>,
|
|
|
|
|
IHandle<ProviderAddedEvent<TProvider>>,
|
|
|
|
|
IHandle<ProviderUpdatedEvent<TProvider>>,
|
|
|
|
|
IHandle<ProviderDeletedEvent<TProvider>>
|
|
|
|
|
where TProviderDefinition : ProviderDefinition, new()
|
|
|
|
|
where TProvider : IProvider
|
|
|
|
|
where TProviderResource : ProviderResource<TProviderResource>, new()
|
|
|
|
@ -22,11 +29,13 @@ namespace Radarr.Api.V3
|
|
|
|
|
private readonly ProviderResourceMapper<TProviderResource, TProviderDefinition> _resourceMapper;
|
|
|
|
|
private readonly ProviderBulkResourceMapper<TBulkProviderResource, TProviderDefinition> _bulkResourceMapper;
|
|
|
|
|
|
|
|
|
|
protected ProviderControllerBase(IProviderFactory<TProvider,
|
|
|
|
|
protected ProviderControllerBase(IBroadcastSignalRMessage signalRBroadcaster,
|
|
|
|
|
IProviderFactory<TProvider,
|
|
|
|
|
TProviderDefinition> providerFactory,
|
|
|
|
|
string resource,
|
|
|
|
|
ProviderResourceMapper<TProviderResource, TProviderDefinition> resourceMapper,
|
|
|
|
|
ProviderBulkResourceMapper<TBulkProviderResource, TProviderDefinition> bulkResourceMapper)
|
|
|
|
|
: base(signalRBroadcaster)
|
|
|
|
|
{
|
|
|
|
|
_providerFactory = providerFactory;
|
|
|
|
|
_resourceMapper = resourceMapper;
|
|
|
|
@ -263,6 +272,24 @@ namespace Radarr.Api.V3
|
|
|
|
|
return Content(data.ToJson(), "application/json");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
public virtual void Handle(ProviderAddedEvent<TProvider> message)
|
|
|
|
|
{
|
|
|
|
|
BroadcastResourceChange(ModelAction.Created, message.Definition.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
public virtual void Handle(ProviderUpdatedEvent<TProvider> message)
|
|
|
|
|
{
|
|
|
|
|
BroadcastResourceChange(ModelAction.Updated, message.Definition.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
public virtual void Handle(ProviderDeletedEvent<TProvider> message)
|
|
|
|
|
{
|
|
|
|
|
BroadcastResourceChange(ModelAction.Deleted, message.ProviderId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Validate(TProviderDefinition definition, bool includeWarnings)
|
|
|
|
|
{
|
|
|
|
|
var validationResult = definition.Settings.Validate();
|
|
|
|
|