SMART-42 implemented retrieve user profile view
This commit is contained in:
parent
4298190701
commit
0b2da88942
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -20,7 +20,7 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = UserProfile
|
||||
fields = ('first_name', 'last_name')
|
||||
fields = ('username', 'first_name', 'last_name')
|
||||
|
||||
|
||||
class UserRegistrationSerializer(serializers.ModelSerializer):
|
||||
@ -39,6 +39,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
|
||||
user = User.objects.create_user(**validated_data)
|
||||
UserProfile.objects.create(
|
||||
user=user,
|
||||
username=profile_data['username'],
|
||||
first_name=profile_data['first_name'],
|
||||
last_name=profile_data['last_name']
|
||||
)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,6 +13,7 @@ class UserProfile(models.Model):
|
||||
"""
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
|
||||
username = models.CharField(max_length=50, unique=True)
|
||||
first_name = models.CharField(max_length=50, unique=False)
|
||||
last_name = models.CharField(max_length=50, unique=False)
|
||||
|
||||
|
@ -1,3 +1,36 @@
|
||||
from django.shortcuts import render
|
||||
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
|
||||
|
||||
# Create your views here.
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user