post-game info
This commit is contained in:
@@ -7,4 +7,5 @@ urlpatterns = [
|
|||||||
path("session/<str:session_id>/test", views.session, name="session"),
|
path("session/<str:session_id>/test", views.session, name="session"),
|
||||||
path("session/", views.SessionListView.as_view(), name="api-session-list"),
|
path("session/", views.SessionListView.as_view(), name="api-session-list"),
|
||||||
path("session/<str:session_id>/", views.SessionDetailView.as_view(), name="api-session-detail"),
|
path("session/<str:session_id>/", views.SessionDetailView.as_view(), name="api-session-detail"),
|
||||||
|
path("session/<str:session_id>/info", views.SessionInfoView.as_view(), name="api-session-info"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -31,3 +31,10 @@ class SessionDetailView(APIView):
|
|||||||
def get(self, request, session_id):
|
def get(self, request, session_id):
|
||||||
session = Session.objects.get(session_id=session_id)
|
session = Session.objects.get(session_id=session_id)
|
||||||
return Response(SessionSerializer(session).data)
|
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})
|
||||||
|
|||||||
@@ -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() {
|
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 (
|
return (
|
||||||
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
||||||
<h1>Post-game</h1>
|
<h1>Post-game</h1>
|
||||||
<p>Bedankt voor het stemmen!</p>
|
<p>Bedankt voor het stemmen!</p>
|
||||||
<p>;)</p>
|
<p>;)</p>
|
||||||
|
<p>Piemels</p>
|
||||||
|
<p>{trackCount} tracks</p>
|
||||||
|
<p>{voteCount} votes</p>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,10 @@ export const api = {
|
|||||||
},
|
},
|
||||||
sessions: {
|
sessions: {
|
||||||
get: fetcher.path("/voting/session/{session_id}/").method("get").create(),
|
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(),
|
list: fetcher.path("/voting/session/").method("get").create(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user