This commit is contained in:
27942
2026-01-28 16:00:56 +08:00
parent 03117098c7
commit 6262a67f46
116 changed files with 7821 additions and 5657 deletions

View File

@@ -11,7 +11,8 @@ from django.shortcuts import get_object_or_404
from django.http import HttpResponse
from django.utils import timezone
from .models import Notification, NotificationPreference
from .models import Notification
from .utils import get_notification_preference
from .schemas import (
NotificationOut,
UnreadCountOut,
@@ -63,7 +64,7 @@ def list_notifications(
@router.get("/preferences/", response=NotificationPreferenceOut, auth=JWTAuth())
def get_preferences(request):
"""Get current user's notification preferences."""
preference, _ = NotificationPreference.objects.get_or_create(user=request.auth)
preference = get_notification_preference(request.auth)
return NotificationPreferenceOut(
user_id=preference.user_id,
enable_bounty=preference.enable_bounty,
@@ -76,7 +77,7 @@ def get_preferences(request):
@router.patch("/preferences/", response=NotificationPreferenceOut, auth=JWTAuth())
def update_preferences(request, data: NotificationPreferenceIn):
"""Update notification preferences."""
preference, _ = NotificationPreference.objects.get_or_create(user=request.auth)
preference = get_notification_preference(request.auth)
update_data = data.dict(exclude_unset=True)
for key, value in update_data.items():
setattr(preference, key, value)