first commit
This commit is contained in:
13
module_support/api/serializers.py
Normal file
13
module_support/api/serializers.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from rest_framework import serializers
|
||||
from module_support.models import ContactUs, Feedback
|
||||
|
||||
class ContactUsSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ContactUs
|
||||
fields = ["email_address", "subject", "message"]
|
||||
|
||||
|
||||
class FeedbackSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Feedback
|
||||
fields = ["feedback_reaction", "comment"]
|
||||
7
module_support/api/urls.py
Normal file
7
module_support/api/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("contact-us/", views.ContactusAPIView.as_view()),
|
||||
path("feedback/", views.FeedbackAPIView.as_view()),
|
||||
]
|
||||
41
module_support/api/views.py
Normal file
41
module_support/api/views.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework_simplejwt.authentication import JWTAuthentication
|
||||
from module_project import constants
|
||||
from module_project.utils import ApiResponse
|
||||
from .serializers import ContactUsSerializer, FeedbackSerializer
|
||||
from ..models import ContactUs, Feedback
|
||||
|
||||
|
||||
class ContactusAPIView(APIView):
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = ContactUsSerializer
|
||||
model = ContactUs
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if not serializer.is_valid():
|
||||
return ApiResponse.error(message=constants.FAILURE, errors=serializer.errors)
|
||||
try:
|
||||
serializer.save()
|
||||
except Exception as e:
|
||||
return ApiResponse.error(message=constants.FAILURE, errors=str(e))
|
||||
return ApiResponse.success(message=constants.SUCCESS, data=serializer.data)
|
||||
|
||||
|
||||
class FeedbackAPIView(APIView):
|
||||
authentication_classes = [JWTAuthentication]
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = FeedbackSerializer
|
||||
model = Feedback
|
||||
|
||||
def post(self, request):
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
if not serializer.is_valid():
|
||||
return ApiResponse.error(message=constants.FAILURE, errors=serializer.errors)
|
||||
try:
|
||||
serializer.save(principal=request.user)
|
||||
except Exception as e:
|
||||
return ApiResponse.error(message=constants.FAILURE, errors=str(e))
|
||||
return ApiResponse.success(message=constants.SUCCESS, data=serializer.data)
|
||||
Reference in New Issue
Block a user