haha
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user