Skip to content

Commit

Permalink
fix: adding alert DELETE endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed Nov 8, 2023
1 parent 87a0d76 commit f158d9a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/api_app/monitoring/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def call_smart_contract_function(self, monitoring_task_id):
def send_webhook(self, notification_id):
notification = Notification.objects.filter(id=notification_id).first()

if not notification:
error_msg = f"Notification with id {notification_id} not found"
if (not notification) and (notification.alert.active is False):
error_msg = f"Active notification with id {notification_id} not found"
logger.error(error_msg)
raise Exception(error_msg)

Expand Down
2 changes: 2 additions & 0 deletions backend/api_app/monitoring/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
AlertCreateAPIView,
AlertRetrieveAPIView,
AlertUpdateAPIView,
AlertDeleteAPIView,
NotificationListViewSet,
OrganizationAlertListViewSet,
OverviewDataAPIView,
Expand All @@ -19,6 +20,7 @@
path("alerts/<int:pk>", AlertRetrieveAPIView.as_view(), name="alert-retrieve"),
path("alerts", AlertCreateAPIView.as_view(), name="alert-create"),
path("alerts/update/<int:pk>", AlertUpdateAPIView.as_view(), name="alert-update"),
path("alerts/delete/<int:pk>", AlertDeleteAPIView.as_view(), name="alert-delete"),
path("notifications", NotificationListViewSet.as_view(), name="notification-list"),
path("pre-written-alerts", get_pre_written_alerts, name="pre-written-alerts"),
path(
Expand Down
9 changes: 9 additions & 0 deletions backend/api_app/monitoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ def post(self, request, *args, **kwargs):
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)

class AlertDeleteAPIView(DestroyAPIView):
queryset = Alerts.objects.all()
permission_classes = [AlertCanBeAccessedPermissions]

def destroy(self, request, *args, **kwargs):
instance = self.get_object()
self.perform_destroy(instance)
return Response(status=status.HTTP_204_NO_CONTENT)

class AlertUpdateAPIView(UpdateAPIView):
serializer_class = AlertUpdateSerializer
permission_classes = [AlertCanBeAccessedPermissions]
Expand Down

0 comments on commit f158d9a

Please sign in to comment.