backend #5

Merged
s460930 merged 5 commits from backend into develop 2020-12-09 20:59:40 +01:00
19 changed files with 38 additions and 3 deletions
Showing only changes of commit 0b2da88942 - Show all commits

Binary file not shown.

View File

@ -20,7 +20,7 @@ class UserSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = UserProfile model = UserProfile
fields = ('first_name', 'last_name') fields = ('username', 'first_name', 'last_name')
class UserRegistrationSerializer(serializers.ModelSerializer): class UserRegistrationSerializer(serializers.ModelSerializer):
@ -39,6 +39,7 @@ class UserRegistrationSerializer(serializers.ModelSerializer):
user = User.objects.create_user(**validated_data) user = User.objects.create_user(**validated_data)
UserProfile.objects.create( UserProfile.objects.create(
user=user, user=user,
username=profile_data['username'],
first_name=profile_data['first_name'], first_name=profile_data['first_name'],
last_name=profile_data['last_name'] last_name=profile_data['last_name']
) )

View File

@ -13,6 +13,7 @@ class UserProfile(models.Model):
""" """
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile') 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) first_name = models.CharField(max_length=50, unique=False)
last_name = models.CharField(max_length=50, unique=False) last_name = models.CharField(max_length=50, unique=False)

View File

@ -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)