preference api

This commit is contained in:
rizwanisready
2024-03-11 15:30:28 +05:30
parent 97255b2a60
commit 30eb42baca
2 changed files with 27 additions and 0 deletions

View File

@@ -97,4 +97,10 @@ urlpatterns = [
views.EventReviewCreateAPIView.as_view(),
name="event-review-create",
),
# Cheking Principal Preference
path(
"check_principal_preference/",
views.CheckPrincipalPreference.as_view(),
name="check_principal_preference",
),
]

View File

@@ -683,3 +683,24 @@ class EventReviewCreateAPIView(mixins.CreateModelMixin, generics.GenericAPIView)
errors=serializer.errors,
status=status.HTTP_400_BAD_REQUEST,
)
class CheckPrincipalPreference(APIView):
authentication_classes = [JWTAuthentication]
permission_classes = [IsAuthenticated]
def get(self, request, *args, **kwargs):
try:
principal = request.user
exists = PrincipalPreference.objects.filter(principal=principal).exists()
return ApiResponse.success(
message=constants.SUCCESS,
data=exists,
status=status.HTTP_200_OK,
)
except Exception as e:
return ApiResponse.error(
message=constants.FAILURE,
errors=str(e),
status=status.HTTP_400_BAD_REQUEST,
)