2020-12-09 19:21:30 +01:00
|
|
|
from rest_framework import status
|
|
|
|
from rest_framework.generics import RetrieveAPIView
|
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
|
2020-11-30 22:42:24 +01:00
|
|
|
|
2020-12-09 19:21:30 +01:00
|
|
|
from smartpicasso.app.user_profile.models import UserProfile
|
|
|
|
|
|
|
|
|
|
|
|
class UserProfileView(RetrieveAPIView):
|
|
|
|
permission_classes = (IsAuthenticated,)
|
|
|
|
authentication_classes = JSONWebTokenAuthentication
|
|
|
|
|
|
|
|
def get(self, request):
|
|
|
|
try:
|
|
|
|
user_profile = UserProfile.objects.get(user=request.user)
|
|
|
|
status_code = status.HTTP_200_OK
|
|
|
|
response = {
|
|
|
|
'success': 'true',
|
|
|
|
'status_code': status_code,
|
|
|
|
'message': 'User profile fetched successfully',
|
|
|
|
'data': {
|
|
|
|
'username': user_profile.username,
|
|
|
|
'first_name': user_profile.first_name,
|
|
|
|
'last_name': user_profile.last_name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
except Exception as e:
|
|
|
|
status_code = status.HTTP_400_BAD_REQUEST
|
|
|
|
response = {
|
|
|
|
'success': 'false',
|
|
|
|
'status_code': status_code,
|
|
|
|
'message': 'User does not exist',
|
|
|
|
'error': str(e)
|
|
|
|
}
|
|
|
|
return Response(response, status=status_code)
|