diff --git a/pydis_site/apps/api/viewsets/bot/reminder.py b/pydis_site/apps/api/viewsets/bot/reminder.py index 5f9970529d..cbce697a01 100644 --- a/pydis_site/apps/api/viewsets/bot/reminder.py +++ b/pydis_site/apps/api/viewsets/bot/reminder.py @@ -1,4 +1,5 @@ from django_filters.rest_framework import DjangoFilterBackend +from rest_framework.request import Request from rest_framework.filters import SearchFilter from rest_framework.mixins import ( CreateModelMixin, @@ -113,6 +114,7 @@ class ReminderViewSet( ### DELETE /bot/reminders/ Delete the reminder with the given `id`. + This is a soft-delete by setting `active` to False. #### Status codes - 204: returned on success @@ -123,6 +125,20 @@ class ReminderViewSet( """ serializer_class = ReminderSerializer - queryset = Reminder.objects.prefetch_related('author') filter_backends = (DjangoFilterBackend, SearchFilter) filterset_fields = ('active', 'author__id') + + def perform_destroy(self, instance: Reminder) -> None: + """Soft-delete reminders when DELETE is called.""" + instance.active = False + instance.save() + + def get_query_set(self) -> list[Reminder]: + """Filter out soft-deleted reminders by default.""" + queryset = Reminder.objects.prefetch_related('author') + + request: Request = self.request + only_active = bool(request.query_params.get("active", True)) + if only_active: + queryset = queryset.filter(active=True) + return queryset