<reponame>linux-machine/linuxmachinebeta
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import AllowAny

from linuxmachinebeta.view.api.serializers import ServiceViewSerializer
from linuxmachinebeta.utils.helpers import get_user_ip


class ServiceViewAPIView(APIView):
    permission_classes = [AllowAny, ]

    def post(self, request):
        user_ip = get_user_ip(request)
        serializer = ServiceViewSerializer(data=request.data, context={'user_ip': user_ip})

        if serializer.is_valid():
            serializer.save(user_ip=user_ip)
            return Response(status=200)
        return Response({'error_msg': serializer.errors}, status=200)


service_view_api_view = ServiceViewAPIView.as_view()

from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import AllowAny

from linuxmachinebeta.view.api.serializers import ServiceViewSerializer
from linuxmachinebeta.utils.helpers import get_user_ip


class ServiceViewAPIView(APIView):
    permission_classes = [AllowAny, ]

    def post(self, request):
        user_ip = get_user_ip(request)
        serializer = ServiceViewSerializer(data=request.data, context={'user_ip': user_ip})

        if serializer.is_valid():
            serializer.save(user_ip=user_ip)
            return Response(status=200)
        return Response({'error_msg': serializer.errors}, status=200)


service_view_api_view = ServiceViewAPIView.as_view()