forked from SMU-LIKELION-11TH/Eeum_backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
31 lines (27 loc) · 1.19 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from rest_framework.decorators import permission_classes, authentication_classes
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.views import APIView
from rest_framework_simplejwt.authentication import JWTAuthentication
from account.models import User
from .models import Message
from rest_framework.response import Response
from .serializers import MessageSerializer
@permission_classes((IsAuthenticated,))
@authentication_classes([JWTAuthentication])
class MessageList(APIView):
def get(self,request):
user = request.user
messages = Message.objects.filter(user = user).order_by("-created_at")
response = MessageSerializer(messages,many = True).data
return Response(response)
def post(self,request):
message = Message.objects.get(id = request.data["id"])
message.delete()
return Response(status = 200,data ={"message":"success"})
def delete(self,request):
user = request.user
# user = User.objects.get(id = 1)
messages = Message.objects.filter(user = user,id__in = request.data["id"])
for message in messages:
message.delete()
return Response(status=200)