Skip to content

Commit

Permalink
Clean coding in the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
warrenshiv committed Dec 3, 2023
1 parent 423d6c7 commit 2f808c4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
Binary file modified backend/artistsmgmt/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified backend/artistsmgmt/__pycache__/views.cpython-310.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions backend/artistsmgmt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ def create(self, validated_data):


class ArtistSerializer(serializers.ModelSerializer):
artist_name = serializers.SerializerMethodField()
class Meta:
model = Artist
fields = '__all__'
extra_kwargs = {'user': {'read_only': True}}

def get_artist_name(self, obj):
return f"{obj.user.first_name} {obj.user.last_name}"


# Portfolio
Expand Down
26 changes: 9 additions & 17 deletions backend/artistsmgmt/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,19 @@ def post(self, request, format=None):
request.user.auth_token.delete()
return Response("Successfully signed out", status=status.HTTP_200_OK)

# class ArtistOnlyView(generics.RetrieveAPIView):
# permission_classes = [permissions.IsAuthenticated, IsArtist]
# serializer_class = UserSerializer

# def get_object(self):
# return self.request.user
class ArtistOnlyView(APIView):
permission_classes = [IsAuthenticated]

def get(self, request, format=None):
# Retrieve the authenticated artist
artist = Artist.objects.get(user=request.user)

# class ArtistOnlyView(APIView):
# permission_classes = [IsAuthenticated, IsArtist]
# serializer_class = UserSerializer
# Serialize all fields and their values for the artist
serializer = ArtistSerializer(artist)

# def get(self, request, format=None):
# return Response(data={"message": "You are an artist"}, status=status.HTTP_200_OK)

class ArtistOnlyView(generics.RetrieveAPIView):
permission_classes = [IsAuthenticated, IsArtist]
serializer_class = UserSerializer

def get_object(self):
return self.request.user
# Return serialized data
return Response(serializer.data, status=status.HTTP_200_OK)


class ArtistCreateView(generics.ListCreateAPIView):
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const SignUpForm = () => {

<div className="d-flex align-items-center justify-content-center pb-4">
<p className="mb-0 me-2">Already have an account?</p>
<a href="/signup" className="btn btn-outline-danger">
<a href="/login" className="btn btn-outline-danger">
Log In
</a>
</div>
Expand Down

0 comments on commit 2f808c4

Please sign in to comment.