diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 0aeefde..3841dcd 100644 Binary files a/rest-app/db.sqlite3 and b/rest-app/db.sqlite3 differ diff --git a/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc index f266be5..5271ef2 100644 Binary files a/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc and b/rest-app/smartpicasso/__pycache__/__init__.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc index 5b58650..8f74e30 100644 Binary files a/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc and b/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index 74b3fd5..a7c2f9b 100644 Binary files a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc and b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc index 269351c..624cd2c 100644 Binary files a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc and b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc index 7a008fc..72eb12b 100644 Binary files a/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc and b/rest-app/smartpicasso/app/user/__pycache__/__init__.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc index 01cd263..dc5c258 100644 Binary files a/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc and b/rest-app/smartpicasso/app/user/__pycache__/admin.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc index af42249..66e537e 100644 Binary files a/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc and b/rest-app/smartpicasso/app/user/__pycache__/models.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc index fccce74..f707b2c 100644 Binary files a/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc and b/rest-app/smartpicasso/app/user/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc index 34c4c8a..00ad2b8 100644 Binary files a/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc and b/rest-app/smartpicasso/app/user/migrations/__pycache__/0002_auto_20201130_2119.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc index 62d8e5b..310f28a 100644 Binary files a/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc and b/rest-app/smartpicasso/app/user/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user/serializers.py b/rest-app/smartpicasso/app/user/serializers.py index cb69e9d..8ea3aaf 100644 --- a/rest-app/smartpicasso/app/user/serializers.py +++ b/rest-app/smartpicasso/app/user/serializers.py @@ -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'] ) diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc index 6b25f62..f69046b 100644 Binary files a/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc and b/rest-app/smartpicasso/app/user_profile/__pycache__/__init__.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc index 08118cc..9753296 100644 Binary files a/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc and b/rest-app/smartpicasso/app/user_profile/__pycache__/admin.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc index 1aa4d72..bd1d7a1 100644 Binary files a/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc and b/rest-app/smartpicasso/app/user_profile/__pycache__/models.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc index 94e7772..a792bc3 100644 Binary files a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc and b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc index 48eab08..0b6cc2b 100644 Binary files a/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc and b/rest-app/smartpicasso/app/user_profile/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/rest-app/smartpicasso/app/user_profile/models.py b/rest-app/smartpicasso/app/user_profile/models.py index 4da1ccf..01908c7 100644 --- a/rest-app/smartpicasso/app/user_profile/models.py +++ b/rest-app/smartpicasso/app/user_profile/models.py @@ -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) diff --git a/rest-app/smartpicasso/app/user_profile/views.py b/rest-app/smartpicasso/app/user_profile/views.py index 91ea44a..9835f6c 100644 --- a/rest-app/smartpicasso/app/user_profile/views.py +++ b/rest-app/smartpicasso/app/user_profile/views.py @@ -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)