Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CRUD (Create, Read, Update, Delete) functionalities to the artist API endpoints #36

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ venv/

# Environment Variables
.env

db.sqlite3
Binary file modified backend/artistsmgmt/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file modified backend/artistsmgmt/api/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file modified backend/artistsmgmt/api/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file modified backend/artistsmgmt/api/__pycache__/views.cpython-310.pyc
Binary file not shown.
8 changes: 7 additions & 1 deletion backend/artistsmgmt/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ def create(self, validated_data):
validated_data['email'],
validated_data['password']
)
return user
return user

class ArtistSerializer(serializers.ModelSerializer):
class Meta:
model = Artist
fields = '__all__'
extra_kwargs = {'user': {'read_only':True}}
7 changes: 5 additions & 2 deletions backend/artistsmgmt/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.urls import path
from .views import ArtistSignUpView, CustomAuthToken, LogoutView, ArtistOnlyView
from .views import ArtistSignUpView, CustomAuthToken, LogoutView, ArtistOnlyView, ArtistCreateView, ArtistRetrieveUpdateDestroyView, ArtistUpdateView

urlpatterns = [
path('signup', ArtistSignUpView.as_view(), name='signup'),
path('login', CustomAuthToken.as_view(), name='login'),
path('logout', LogoutView.as_view(), name='logout'),
path('artist/dashboard', ArtistOnlyView.as_view(), name='artist_dashboard'),
]
path('artist/', ArtistCreateView.as_view(), name='artist-create'),
path('artist/update/', ArtistUpdateView.as_view(), name='artist-update'),
path('artists/<int:pk>/', ArtistRetrieveUpdateDestroyView.as_view(), name='artist-retrieve-update-destroy'),
]
23 changes: 21 additions & 2 deletions backend/artistsmgmt/api/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@

from rest_framework import generics, status, permissions
from rest_framework.generics import RetrieveUpdateAPIView
from rest_framework.response import Response
from .serializers import UserSerializer, ArtistSignUpSerializer
from .serializers import UserSerializer, ArtistSignUpSerializer, ArtistSerializer
from rest_framework.authtoken.models import Token
from rest_framework.authtoken.views import ObtainAuthToken
from rest_framework.views import APIView
from .permissions import IsArtist
from rest_framework.response import Response
from .serializers import UserSerializer
from rest_framework.views import APIView
from ..models import Artist, User
from rest_framework.permissions import IsAuthenticated

class ArtistSignUpView(generics.CreateAPIView):
serializer_class = ArtistSignUpSerializer
Expand Down Expand Up @@ -56,3 +58,20 @@ class ArtistOnlyView(APIView):

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

class ArtistCreateView(generics.ListCreateAPIView):
queryset = Artist.objects.all()
serializer_class = ArtistSerializer

class ArtistRetrieveUpdateDestroyView(generics.RetrieveUpdateDestroyAPIView):
queryset = Artist.objects.all()
serializer_class = ArtistSerializer

class ArtistUpdateView(RetrieveUpdateAPIView):
queryset = Artist.objects.all()
serializer_class = ArtistSerializer
# permission_classes = [IsAuthenticated] # Adjust permissions as needed

def get_object(self):
user = self.request.user
return Artist.objects.get(user=user)
2 changes: 1 addition & 1 deletion backend/artistsmgmt/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.7 on 2023-11-19 12:03
# Generated by Django 4.2.7 on 2023-11-20 12:00

from django.conf import settings
import django.contrib.auth.models
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions backend/artistsmgmt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def __str__(self):
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)

@receiver(post_save, sender=User)
def create_user_artist(sender, instance, created, **kwargs):
if created:
Artist.objects.create(user=instance, type='default', description='default', skills='default')


class Artist(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="artist")
Expand Down
Binary file modified backend/db.sqlite3
Binary file not shown.
Binary file added backend/images/aaronwanje_copy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/coding.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/coding_4g9OqFZ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/coding_8I1tsW6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/coding_FnV0xjq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/coding_SBwK07t.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/coding_UILPe9u.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/images/j.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading