-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathviews.py
More file actions
35 lines (29 loc) · 1.23 KB
/
views.py
File metadata and controls
35 lines (29 loc) · 1.23 KB
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
32
33
34
35
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from drf_spectacular.utils import extend_schema
from .models import AI_PromptStorage
from .serializers import AI_PromptStorageSerializer
@extend_schema(request=AI_PromptStorageSerializer, responses={201: AI_PromptStorageSerializer})
@api_view(['POST'])
# @permission_classes([IsAuthenticated])
def store_prompt(request):
print(request.user)
data = request.data.copy() # noqa: F841
print(request.user)
serializer = AI_PromptStorageSerializer(
data=request.data, context={'request': request})
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@extend_schema(responses={200: AI_PromptStorageSerializer(many=True)})
@api_view(['GET'])
def get_all_prompts(request):
"""
A view to get all prompts stored in the database.
"""
if request.method == 'GET':
prompts = AI_PromptStorage.objects.all()
serializer = AI_PromptStorageSerializer(prompts, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)