예제 #1
0
    def update(self, request, *args, **kwargs):
        if self.request.user.role != 'ADMIN' and self.request.user.role != 'MANAGER':
            error = {"detail": ERROR_API['117'][1]}
            error_codes = [ERROR_API['117'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)

        serializer_class = self.get_serializer_class()

        object = self.get_object()

        if object != None:
            serializer = serializer_class(instance=object,data=request.data,partial=True,context={"request": request})
            if serializer.is_valid():
                serializer.save()
                error = {"detail": ERROR_API['200'][1]}
                error_codes = [ERROR_API['200'][0]]
                return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_200_OK)
            else:
                error = {"detail": ERROR_API['400'][1]}
                error_codes = [ERROR_API['400'][0]]
                return Response(custom_api_response(errors=error, error_codes=error_codes),
                                status=status.HTTP_400_BAD_REQUEST)

        else:
            error = {"detail": ERROR_API['125'][1]}
            error_codes = [ERROR_API['125'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)
예제 #2
0
    def create(self, request, *args, **kwargs):
        if self.request.user.role != 'ADMIN' and self.request.user.role != 'MANAGER':
            error = {"detail": ERROR_API['117'][1]}
            error_codes = [ERROR_API['117'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)


        serializer_class = self.get_serializer_class()
        serializer = serializer_class(data=request.data)
        if serializer.is_valid():
            serializer.save()
            error = {"detail": ERROR_API['200'][1]}
            error_codes = [ERROR_API['200'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_200_OK)



        else:

            error = {"detail": ERROR_API['400'][1]}
            error_codes = [ERROR_API['400'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)
예제 #3
0
    def list(self, request, *args, **kwargs):
        if self.request.user.role != "DOCTOR":
            error = {"detail": ERROR_API['117'][1]}
            error_codes = [ERROR_API['117'][0]]
            return Response(custom_api_response(errors=error,
                                                error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)

        current_call = VoipCall.objects.filter(
            doctor=self.request.user,
            status='STARTED').order_by('call_start_time').first()

        if current_call != None:

            ser_class = DoctorCallHistorySerializer

            ser = DoctorCallHistorySerializer(current_call,
                                              context={"request": request})

            return Response(custom_api_response(ser),
                            status=status.HTTP_200_OK)

        else:
            error = {"detail": ERROR_API['125'][1]}
            error_codes = [ERROR_API['125'][0]]
            return Response(custom_api_response(errors=error,
                                                error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)
예제 #4
0
 def create(self, request, *args, **kwargs):
     ser = self.get_serializer_class()
     ser = ser(data=self.request.data,context={'request':self.request})
     if ser.is_valid():
         instance = ser.save()
         return Response(custom_api_response(ser),status=status.HTTP_200_OK)
     else:
         error = {"detail": ERROR_API['400'][1]}
         error_codes = [ERROR_API['400'][0]]
         return Response(custom_api_response(errors=error, error_codes=error_codes),
                         status=status.HTTP_400_BAD_REQUEST)
예제 #5
0
 def list(self, request, *args, **kwargs):
     qs = self.get_queryset()
     if qs:
         ser =self.get_serializer_class()
         ser = ser(qs,many=True)
         return Response(custom_api_response(ser),status=status.HTTP_200_OK)
     else:
         error = {"detail": ERROR_API['125'][1]}
         error_codes = [ERROR_API['125'][0]]
         return Response(custom_api_response(errors=error, error_codes=error_codes),
                         status=status.HTTP_400_BAD_REQUEST)
예제 #6
0
    def retrieve(self, request, *args, **kwargs):
        object = self.get_object()
        serializer_class = self.get_serializer_class()

        if object != None:
            serializer = serializer_class(instance=object,context={"request": request})
            return Response(custom_api_response(serializer), status=status.HTTP_200_OK)

        else:
            error = {"detail": ERROR_API['125'][1]}
            error_codes = [ERROR_API['125'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)
예제 #7
0
    def list(self, request, *args, **kwargs):
        queryset = self.get_queryset()

        queryset = self.filter_queryset(queryset)

        if queryset.exists():
            serializer_class = self.get_serializer_class()
            serializer = serializer_class(queryset,many=True,context={"request": request})
            return Response(custom_api_response(serializer), status=status.HTTP_200_OK)

        else:
            error = {"detail": ERROR_API['125'][1]}
            error_codes = [ERROR_API['125'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)
예제 #8
0
    def delete(self, request, *args, **kwargs):
        if self.request.user.role != 'ADMIN' and self.request.user.role != 'MANAGER':
            error = {"detail": ERROR_API['117'][1]}
            error_codes = [ERROR_API['117'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)

        object = self.get_object()
        if object != None:
            object.delete()
            error = {"detail": ERROR_API['200'][1]}
            error_codes = [ERROR_API['200'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_200_OK)

        else:
            error = {"detail": ERROR_API['125'][1]}
            error_codes = [ERROR_API['125'][0]]
            return Response(custom_api_response(errors=error, error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)
예제 #9
0
    def list(self, request, *args, **kwargs):
        queryset = self.get_queryset()

        if queryset.exists():
            paginate = prepare_paginated_response(self, request, queryset)
            if paginate:
                return Response(custom_api_response(
                    content=paginate.content, metadata=paginate.metadata),
                                status=status.HTTP_200_OK)

            ser_class = self.get_serializer_class()

            ser = ser_class(queryset, many=True, context={"request": request})
        else:
            error = {"detail": ERROR_API['125'][1]}
            error_codes = [ERROR_API['125'][0]]
            return Response(custom_api_response(errors=error,
                                                error_codes=error_codes),
                            status=status.HTTP_400_BAD_REQUEST)

        return Response(custom_api_response(ser), status=status.HTTP_200_OK)