From 0b2da889427244966994e06f127ac25ee3cb260b Mon Sep 17 00:00:00 2001 From: s460930 Date: Wed, 9 Dec 2020 19:21:30 +0100 Subject: [PATCH] SMART-42 implemented retrieve user profile view --- rest-app/db.sqlite3 | Bin 167936 -> 167936 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 167 -> 167 bytes .../__pycache__/settings.cpython-38.pyc | Bin 3500 -> 3500 bytes .../__pycache__/urls.cpython-38.pyc | Bin 1015 -> 1015 bytes .../__pycache__/wsgi.cpython-38.pyc | Bin 580 -> 580 bytes .../user/__pycache__/__init__.cpython-38.pyc | Bin 176 -> 176 bytes .../app/user/__pycache__/admin.cpython-38.pyc | Bin 217 -> 217 bytes .../user/__pycache__/models.cpython-38.pyc | Bin 2416 -> 2416 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1028 -> 1028 bytes .../0002_auto_20201130_2119.cpython-38.pyc | Bin 545 -> 545 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 187 -> 187 bytes rest-app/smartpicasso/app/user/serializers.py | 3 +- .../__pycache__/__init__.cpython-38.pyc | Bin 184 -> 184 bytes .../__pycache__/admin.cpython-38.pyc | Bin 225 -> 225 bytes .../__pycache__/models.cpython-38.pyc | Bin 1060 -> 1060 bytes .../__pycache__/0001_initial.cpython-38.pyc | Bin 1055 -> 1055 bytes .../__pycache__/__init__.cpython-38.pyc | Bin 195 -> 195 bytes .../smartpicasso/app/user_profile/models.py | 1 + .../smartpicasso/app/user_profile/views.py | 37 +++++++++++++++++- 19 files changed, 38 insertions(+), 3 deletions(-) diff --git a/rest-app/db.sqlite3 b/rest-app/db.sqlite3 index 0aeefde76f76489d795545caff8a5e92ce52c00a..3841dcd432ea01b0a42fbe197540b9d975e33331 100644 GIT binary patch delta 108 zcmV-y0F(cKpbCJX3XmHCFOeKW0WX1IwO|3E{|^qu00a!d01sCT!44S>ZLxu|30{|$|1gQW3 delta 19 ZcmZ3^xSWwYl$V!_0SG4a9Gl2J2LLKa1n&R< diff --git a/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/settings.cpython-38.pyc index 5b5865037fe9425e9bf83e0e5d76b99d6948d776..8f74e3094d892ecb8ae9f48b7dc1ce49287c9758 100644 GIT binary patch delta 20 acmZ1@y+)cll$V!_0SM~-&u!#h$O`~6cLf;$ delta 20 acmZ1@y+)cll$V!_0SG4a9NWmfkQV?nGzDJ( diff --git a/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/urls.cpython-38.pyc index 74b3fd52bd0832a495c073c74b9c2eb2b89b19cf..a7c2f9b2241829ed7dbf70406c61415ca40844da 100644 GIT binary patch delta 20 acmey){+*pWl$V!_0SM~-&u!#>!wdjBRRzcZ delta 20 acmey){+*pWl$V!_0SG4a9NWnKh8X}o5(W+c diff --git a/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc b/rest-app/smartpicasso/__pycache__/wsgi.cpython-38.pyc index 269351cdcfc2ff197e546f0837801c5067288685..624cd2cd49421e1ae7d3ab06f995aea75f1d8b2e 100644 GIT binary patch delta 20 acmX@Ya)gCDl$V!_0SM~-&u!$kWC8#&@C2v; delta 20 acmX@Ya)gCDl$V!_0SG4a9NWlk$pip1tpx4> 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 7a008fc13de5ed1c5ad00761da70068fc00e5ca8..72eb12b4eafa74b963799d6effcf364e0bf4a65b 100644 GIT binary patch delta 19 ZcmdnMxPg&7l$V!_0SM~-&rRfB3IHk|1jGOU delta 19 ZcmdnMxPg&7l$V!_0SG4a9Gl3!6aXug1quKF 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 01cd26348969e76516a1d59a4483c163e0a13e48..dc5c2583a881bfa98316680e6b51aa8d967169e6 100644 GIT binary patch delta 19 Zcmcb~c$1Mkl$V!_0SM~-&rRe$2LLb&1wQ}) delta 19 Zcmcb~c$1Mkl$V!_0SG4a9Gl2}4gfKN1%&_r 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 af422490e0d4d204c91c7a4ea15cb87dc094f022..66e537eb877091ef17f6feffde1897331eb846e8 100644 GIT binary patch delta 20 acmew$^g)O_l$V!_0SM~-&u!#RlpK0D^k|a~rvTG6MiAfdugY delta 20 acmZqSXyM=v<>lpK0D`@nk8R}s$qWE4V+D%< 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 34c4c8a626f4a77737187501670febe8e5d44858..00ad2b87204a0b20afd7f5b1091671b6db95a57d 100644 GIT binary patch delta 20 acmZ3;vXF&4l$V!_0SM~-&u!!uV*&sycmzKH delta 20 acmZ3;vXF&4l$V!_0SNYPKDLotj0pfRS_Ihu 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 62d8e5b70e88d3ed03a0201522c41878e50f7972..310f28ac9dd9255d172748e897fb136402d09c0e 100644 GIT binary patch delta 19 ZcmdnZxSNqXl$V!_0SM~-&rRgs001ks1myq# delta 19 ZcmdnZxSNqXl$V!_0SG4a9Gl3!0RSy51uFmm 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 6b25f622f576112f60d3465b4d8354ac09c3b4a4..f69046bef81ca4411b010344ca131db4652ee03d 100644 GIT binary patch delta 19 ZcmdnNxPy^9l$V!_0SM~-&rRfB3jixd1l#}s delta 19 ZcmdnNxPy^9l$V!_0SG4a9Gl3!762^01tI_d 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 08118cc5d5a0f51ce01cebee94ac4fc8b24ff034..975329643db64764625b762b10864b6cafc07357 100644 GIT binary patch delta 19 ZcmaFJ_>hr1l$V!_0SM~-&rRgM1^_WL1y=w7 delta 19 ZcmaFJ_>hr1l$V!_0SG4a9Gl2}4FEE#1)Tr@ 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 1aa4d7255859d909c737419499fb3717e8bdf01b..bd1d7a14781d8050cba52cfe539a8ac9f71b0c50 100644 GIT binary patch delta 20 acmZ3&v4n#=l$V!_0SM~-&u!$EWB~vzf&@|k delta 20 acmZ3&v4n#=l$V!_0SMZ6AKS<+$pQc{8U(%o 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 94e7772ebae22bca859d004989044af2256d95ce..a792bc3bae0aa9f90a8e42d68858ab984c49fadf 100644 GIT binary patch delta 20 acmbQwF`t7wl$V!_0SM~-&u!!uVF3Uvx&%W2 delta 20 acmbQwF`t7wl$V!_0SG4a9NWk(!U6y;cLa$5 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 48eab08fa8b1530035b9522ce27a0f16441013b1..0b6cc2bcbff79dfefbeeb1cbf6e4c5aede37a43c 100644 GIT binary patch delta 19 ZcmX@ic$kqpl$V!_0SM~-&rRgs0RSxB1pNR2 delta 19 ZcmX@ic$kqpl$V!_0SG4a9Gl3!0{|{m1w#M; 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)