mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-22 22:16:13 -04:00
Converted notifications to thingi provider
Fixed: Issues creating and saving Connects
This commit is contained in:
@@ -10,82 +10,17 @@ using Omu.ValueInjecter;
|
||||
|
||||
namespace NzbDrone.Api.Notifications
|
||||
{
|
||||
public class NotificationModule : NzbDroneRestModule<NotificationResource>
|
||||
public class IndexerModule : ProviderModuleBase<NotificationResource, INotification, NotificationDefinition>
|
||||
{
|
||||
private readonly INotificationService _notificationService;
|
||||
|
||||
public NotificationModule(INotificationService notificationService)
|
||||
public IndexerModule(NotificationFactory notificationrFactory)
|
||||
: base(notificationrFactory, "notification")
|
||||
{
|
||||
_notificationService = notificationService;
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
GetResourceById = GetNotification;
|
||||
CreateResource = Create;
|
||||
UpdateResource = Update;
|
||||
DeleteResource = DeleteNotification;
|
||||
}
|
||||
|
||||
private NotificationResource GetNotification(int id)
|
||||
protected override void Validate(NotificationDefinition definition)
|
||||
{
|
||||
return _notificationService.Get(id).InjectTo<NotificationResource>();
|
||||
}
|
||||
|
||||
private List<NotificationResource> GetAll()
|
||||
{
|
||||
var notifications = _notificationService.All();
|
||||
|
||||
var result = new List<NotificationResource>(notifications.Count);
|
||||
|
||||
foreach (var notification in notifications)
|
||||
{
|
||||
var notificationResource = new NotificationResource();
|
||||
notificationResource.InjectFrom(notification);
|
||||
notificationResource.Fields = SchemaBuilder.ToSchema(notification.Settings);
|
||||
notificationResource.TestCommand = String.Format("test{0}", notification.Implementation.ToLowerInvariant());
|
||||
|
||||
result.Add(notificationResource);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private int Create(NotificationResource notificationResource)
|
||||
{
|
||||
var notification = ConvertToNotification(notificationResource);
|
||||
return _notificationService.Create(notification).Id;
|
||||
}
|
||||
|
||||
private void Update(NotificationResource notificationResource)
|
||||
{
|
||||
var notification = ConvertToNotification(notificationResource);
|
||||
notification.Id = notificationResource.Id;
|
||||
_notificationService.Update(notification);
|
||||
}
|
||||
|
||||
private void DeleteNotification(int id)
|
||||
{
|
||||
_notificationService.Delete(id);
|
||||
}
|
||||
|
||||
private Notification ConvertToNotification(NotificationResource notificationResource)
|
||||
{
|
||||
var notification = _notificationService.Schema()
|
||||
.SingleOrDefault(i =>
|
||||
i.Implementation.Equals(notificationResource.Implementation,
|
||||
StringComparison.InvariantCultureIgnoreCase));
|
||||
|
||||
if (notification == null)
|
||||
{
|
||||
throw new BadRequestException("Invalid Notification Implementation");
|
||||
}
|
||||
|
||||
notification.InjectFrom(notificationResource);
|
||||
|
||||
//var configType = ReflectionExtensions.CoreAssembly.FindTypeByName(notification)
|
||||
|
||||
//notification.Settings = SchemaBuilder.ReadFormSchema(notification.Settings, notificationResource.Fields);
|
||||
|
||||
return notification;
|
||||
if (!definition.OnGrab && !definition.OnDownload) return;
|
||||
base.Validate(definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user