diff --git a/backend/voting/urls.py b/backend/voting/urls.py index a3ec181..1e6a453 100644 --- a/backend/voting/urls.py +++ b/backend/voting/urls.py @@ -7,4 +7,5 @@ urlpatterns = [ path("session//test", views.session, name="session"), path("session/", views.SessionListView.as_view(), name="api-session-list"), path("session//", views.SessionDetailView.as_view(), name="api-session-detail"), + path("session//info", views.SessionInfoView.as_view(), name="api-session-info"), ] diff --git a/backend/voting/views.py b/backend/voting/views.py index 4b8619a..b1d2c31 100644 --- a/backend/voting/views.py +++ b/backend/voting/views.py @@ -31,3 +31,10 @@ class SessionDetailView(APIView): def get(self, request, session_id): session = Session.objects.get(session_id=session_id) return Response(SessionSerializer(session).data) + + +class SessionInfoView(APIView): + def get(self, request, session_id): + track_count = len(Track.objects.all()) + vote_count = len(Vote.objects.all()) + return Response({'track_count': track_count, 'vote_count': vote_count}) diff --git a/frontend/src/app/post-game/page.tsx b/frontend/src/app/post-game/page.tsx index 9f9dbec..0b30bbb 100644 --- a/frontend/src/app/post-game/page.tsx +++ b/frontend/src/app/post-game/page.tsx @@ -1,9 +1,31 @@ +"use client"; +import { useEffect, useState } from "react"; +import { api } from "muzak/data/fetcher"; +import { useSession } from "muzak/contexts/SessionContext"; + export default function PostGame() { + const { sessionId, setSessionId } = useSession(); + const [trackCount, setTrackCount] = useState(0); + const [voteCount, setVoteCount] = useState(0); + + async function getInfo() { + const { data: info } = await api.sessions.info({ session_id: sessionId }); + console.log(info); + setTrackCount(info["track_count"]); + setVoteCount(info["vote_count"]); + } + useEffect(() => { + getInfo(); + }, []); + return (

Post-game

Bedankt voor het stemmen!

;)

+

Piemels

+

{trackCount} tracks

+

{voteCount} votes

); } diff --git a/frontend/src/data/fetcher.ts b/frontend/src/data/fetcher.ts index 07532a2..d0e5c3f 100644 --- a/frontend/src/data/fetcher.ts +++ b/frontend/src/data/fetcher.ts @@ -87,6 +87,10 @@ export const api = { }, sessions: { get: fetcher.path("/voting/session/{session_id}/").method("get").create(), + info: fetcher + .path("/voting/session/{session_id}/info") + .method("get") + .create(), list: fetcher.path("/voting/session/").method("get").create(), }, };