from django.shortcuts import render
from rest_framework.views import APIView
from .serializers import ProfileSerializer
from rest_framework.permissions import IsAuthenticated
from rest_framework import status
from rest_framework.response import Response
class ProfileView(APIView):
    serializer_class = ProfileSerializer
    permission_classes = [IsAuthenticated]
    
    def get(self, request):
        user_ser = self.serializer_class(instance=request.user)
        return Response(user_ser.data, status=status.HTTP_200_OK)


    def patch(self, request):
        user = request.user
        user_ser = self.serializer_class(user, data=request.data, partial=True)
        if user_ser.is_valid():
            user_ser.save()
            return Response(user_ser.data)
        return Response(user_ser.errors, status=status.HTTP_400_BAD_REQUEST)