def get(self, request): try: queryset = Profile.objects.get(id=self.request.user.id) serializer = ProfileSerializer(queryset) return Response(prepare_success_response(serializer.data), status=status.HTTP_200_OK) except Exception as e: print(e) queryset = User.objects.get(id=self.request.user.id) serializer = UserSerializer(queryset) return Response(prepare_success_response(serializer.data), status=status.HTTP_200_OK)
def get(self, request, pk): order_item = self.get_object(pk) serializer = OrderItemSerializer(order_item) if serializer is not None: return Response(prepare_success_response(serializer.data), status=status.HTTP_200_OK) return Response(prepare_error_response("Content Not found"), status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk): shop = self.get_object(pk) serializer = ShopSerializer(shop, data=request.data) if serializer.is_valid(raise_exception=True): serializer.save(owner=self.request.user) return Response(prepare_success_response(serializer.data), status=status.HTTP_201_CREATED) return Response(prepare_error_response(serializer.errors), status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk): if request.user.role == ROLE.ADMIN or request.user.role == ROLE.MANAGER or request.user.role == ROLE.SHOPKEEPER: item = self.get_object(pk) if item is not None: item.delete() return Response(prepare_success_response("Data deleted successfully"), status=status.HTTP_200_OK) else: return Response(prepare_error_response("Content Not found"), status=status.HTTP_400_BAD_REQUEST) return Response(prepare_error_response('You have no permission'), status=status.HTTP_401_UNAUTHORIZED)
def get(self, request): try: complete_task = Task.objects.filter(status=Evolution.DONE) serializer = TaskSerializer(complete_task, many=True) return Response(prepare_success_response(serializer.data), status=status.HTTP_200_OK) except Exception as e: return Response(prepare_error_response(e), status=status.HTTP_400_BAD_REQUEST)
def list(self, request, *args, **kwargs): order_item = OrderItem.objects.all() serializer = OrderItemSerializer(order_item, many=True) calculation_order = OrderItemCalculation(serializer.data) response = { 'data': calculation_order.serializer, 'price_model': calculation_order.calculation_price() } return Response(prepare_success_response(response), status=status.HTTP_200_OK)
def delete(self, request, pk): shop = self.get_object(pk) if shop is not None: shop.delete() return Response( prepare_success_response("Data deleted successfully"), status=status.HTTP_200_OK) else: return Response(prepare_error_response("Content Not found"), status=status.HTTP_400_BAD_REQUEST)
def get(self, request): if request.user.is_superuser: order = Order.objects.all() else: order = Order.objects.filter(user=self.request.user) if order is not None: serializer = OrderSerializer(order, many=True) return Response(prepare_success_response(serializer.data), status=status.HTTP_200_OK) else: return Response(prepare_error_response("Content Not found"), status=status.HTTP_400_BAD_REQUEST)
def post(self, request): try: serializer = ShopSerializer(data=request.data) if serializer.is_valid(): serializer.save(owner=self.request.user) return Response(prepare_success_response(serializer.data), status=status.HTTP_201_CREATED) return Response(prepare_error_response(serializer.errors), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(prepare_error_response(str(e)), status=status.HTTP_404_NOT_FOUND)
def get(self, request): try: order_item = OrderItem.objects.filter(status=0, customer=self.request.user) serializer = OrderItemSerializer(order_item, many=True) calculation_order = OrderItemCalculation(serializer.data) response = { 'data': calculation_order.serializer, 'price_model': calculation_order.calculation_price() } return Response(prepare_success_response(response), status=status.HTTP_200_OK) except Exception as e: return Response(prepare_error_response(str(e)), status=status.HTTP_400_BAD_REQUEST)
def get(self, request): request.user.auth_token.delete() return Response(prepare_success_response("Logout"), status=status.HTTP_200_OK)
def get(self, request): shop = Shop.objects.filter(owner=self.request.user) serializer = ShopSerializer(shop, many=True) return Response(prepare_success_response(serializer.data), status=status.HTTP_200_OK)
def get(self, request): item = Item.objects.all() serializer = ItemSerializer(item, many=True) return Response(prepare_success_response(serializer.data), status=status.HTTP_200_OK)
def post(self, request): logout(request) return Response(prepare_success_response('user has been logout'), status=status.HTTP_200_OK)