✨ Feat: [#41] notification 앱 생성 및 알림 조회 구현
This commit is contained in:
34
notifications/views.py
Normal file
34
notifications/views.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.db import transaction
|
||||
|
||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
|
||||
from .serializers import *
|
||||
from .models import *
|
||||
from .services import *
|
||||
|
||||
from users.services import *
|
||||
|
||||
|
||||
# Create your views here.
|
||||
class NotificationReadViewSet(ReadOnlyModelViewSet):
|
||||
serializer_class = NotificationSerializer
|
||||
|
||||
# 30일 이전 알림만 가져옴
|
||||
def get_queryset(self):
|
||||
qs = UserToNotificationService.get_all_notification(self.request.user)
|
||||
print(qs)
|
||||
return qs.select_related(
|
||||
'project_invitation__project',
|
||||
'project_invitation__from_user',
|
||||
)
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
instance = self.get_object()
|
||||
instance.is_read = True
|
||||
instance.save()
|
||||
serializer = self.get_serializer(instance)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
Reference in New Issue
Block a user