From c21c98f6c47fcb7634f258a33cf35483219b8b5f Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 3 Aug 2025 10:50:49 +0200 Subject: [PATCH] nu met de juiste files toegevoegd --- backend/playlist/serializers/user.py | 12 +----------- backend/playlist/urls.py | 6 +----- backend/playlist/views/api/profile.py | 26 +++----------------------- backend/playlist/views/api/track.py | 12 +++++++++++- frontend/src/app/layout.tsx | 19 +++++++++++++++++-- frontend/src/data/fetcher.ts | 12 ++---------- 6 files changed, 35 insertions(+), 52 deletions(-) diff --git a/backend/playlist/serializers/user.py b/backend/playlist/serializers/user.py index c7d7bcb..80121e0 100644 --- a/backend/playlist/serializers/user.py +++ b/backend/playlist/serializers/user.py @@ -2,16 +2,6 @@ from django.contrib.auth.models import User from rest_framework import serializers class UserSerializer(serializers.HyperlinkedModelSerializer): - # Add explicit reverse lookup to profile - profile = serializers.HyperlinkedRelatedField( - view_name='api-profile', - lookup_field='id', - read_only=True - ) - class Meta: model = User - fields = ['url', 'id', 'username', 'email', 'profile'] - extra_kwargs = { - 'url': {'view_name': 'api-user', 'lookup_field': 'id'} - } + fields = ['id', 'username', 'email'] diff --git a/backend/playlist/urls.py b/backend/playlist/urls.py index 6a3589c..56974ce 100644 --- a/backend/playlist/urls.py +++ b/backend/playlist/urls.py @@ -19,11 +19,7 @@ urlpatterns = [ path('api/vote/', views.VoteListView.as_view(), name="api-votes"), path('api/vote/', views.VoteDetailView.as_view(), name="api-vote"), path('api/user/', views.UserListView.as_view(), name="api-users"), - path('api/user/', views.UserDetailView.as_view(), name="api-user"), - path('api/user//votes', views.VoteListView.as_view(), name="api-user-votes"), - path('api/profile/', views.ProfileDetailView.as_view(), name="api-profile"), - path('api/profile/background', views.BackgroundListView.as_view(), name="api-backgrounds"), - path('api/profile/background/', views.BackgroundDetailView.as_view(), name="api-background"), + path('api/profile/me', views.ProfileMeView.as_view(), name="api-profile-me"), ### Classic path('track/', views.NominateView.as_view(), name="nominate"), diff --git a/backend/playlist/views/api/profile.py b/backend/playlist/views/api/profile.py index 5238958..d027d9b 100644 --- a/backend/playlist/views/api/profile.py +++ b/backend/playlist/views/api/profile.py @@ -5,28 +5,8 @@ from rest_framework.response import Response from playlist.serializers import ProfileSerializer, ProfileUpdateSerializer, BackgroundSerializer from playlist.models import Profile, Background -class ProfileDetailView(APIView): - def get(self, request, id): - profile = Profile.objects.get(pk=id) +class ProfileMeView(APIView): + def get(self, request): + profile = request.user.profile serializer = ProfileSerializer(profile) return Response(serializer.data) - - def put(self, request, id): - profile = Profile.objects.get(pk=id) - serializer = ProfileUpdateSerializer(profile, data=request.data) - serializer.is_valid() - serializer.save() - return Response(serializer.data) - #return Response() - -class BackgroundListView(APIView): - def get(self, request): - backgrounds = Background.objects.all() - serializer = BackgroundSerializer(backgrounds, many=True) - return Response(serializer.data) - -class BackgroundDetailView(APIView): - def get(self, request, id): - background = Background.objects.get(pk=id) - serializer = BackgroundSerializer(background) - return Response(serializer.data) diff --git a/backend/playlist/views/api/track.py b/backend/playlist/views/api/track.py index 40d22c6..aadbdff 100644 --- a/backend/playlist/views/api/track.py +++ b/backend/playlist/views/api/track.py @@ -1,3 +1,4 @@ +from json.decoder import JSONDecodeError from rest_framework.views import APIView from rest_framework.response import Response from playlist.models import Track, Profile @@ -74,7 +75,16 @@ class TrackVoteView(APIView): ) def get(self, request): # TODO implement a session-based vote tracking system. Random return for now. - random_pk = choice(Track.objects.values_list('pk', flat=True)) + track_pks = Track.objects.values_list('pk', flat=True) + if not track_pks: + dummy = { + "name": "Dummy", + "artist": "Dummy", + "album_cover": "/meowl.png" + } + return Response(dummy) + + random_pk = choice(track_pks) track = Track.objects.get(pk=random_pk) serializer = TrackSerializer(track, context={'request': request}) return Response(serializer.data) diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index f34332c..6695f55 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -6,6 +6,7 @@ import { oidcConfig, userManager } from "muzak/config/auth"; import { Source_Sans_3, Nunito } from "next/font/google"; import AuthStatus from "muzak/components/AuthStatus"; import NavigationBar from "muzak/components/NavigationBar"; +import Quota from "muzak/components/Quota"; const sourceSans = Source_Sans_3({ weight: ["400"], @@ -16,12 +17,21 @@ const nunito = Nunito({ subsets: ["latin"], }); -function LayoutContent({ children }: { children: React.ReactNode }) { +function LayoutContent({ + children, + quota, + setQuota, +}: { + children: React.ReactNode; + quota: number | null; + setQuota: React.Dispatch>; +}) { return ( <> {children} + ); } @@ -32,6 +42,7 @@ export default function RootLayout({ children: React.ReactNode; }) { const [isAnimate, setIsAnimate] = useState(false); + const [quota, setQuota] = useState(null); const toggleAnimation = () => { setIsAnimate(!isAnimate); @@ -41,7 +52,11 @@ export default function RootLayout({ - {children} +