Added delete-quiz

This commit is contained in:
Mawoka
2022-03-09 18:26:33 +01:00
parent 4f4b38d8b0
commit a69922b8ab
2 changed files with 37 additions and 0 deletions
+12
View File
@@ -90,3 +90,15 @@ async def update_quiz(quiz_id: str, quiz_input: QuizInput, user: User = Depends(
@router.post("/import/{quiz_id}")
async def import_quiz_route(quiz_id: str, user: User = Depends(get_current_user)):
return await import_quiz(quiz_id, user)
@router.delete("/delete/{quiz_id}")
async def delete_quiz(quiz_id: str, user: User = Depends(get_current_user)):
try:
quiz_id = uuid.UUID(quiz_id)
except ValueError:
raise HTTPException(status_code=400, detail="badly formed quiz id")
quiz = await Quiz.objects.get_or_none(id=quiz_id, user_id=user.id)
if quiz is None:
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
else:
return await quiz.delete()
+25
View File
@@ -42,6 +42,13 @@
const data = await res.json();
window.location.replace(`/admin?token=${data.game_id}&pin=${data.game_pin}&connect=1`);
};
const deleteQuiz = async (to_delete: string) => {
const res = await fetch(`/api/v1/quiz/delete/${to_delete}`, {
method: 'DELETE'
});
window.location.reload()
}
</script>
{#await getData()}
@@ -109,6 +116,12 @@
>
Edit
</th>
<th
scope="col"
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
>
Delete
</th>
<th
scope="col"
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
@@ -153,6 +166,18 @@
>
<a href="/edit?quiz_id={quiz.id}">Edit</a>
</td>
<td
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
>
<button
on:click={() => {
deleteQuiz(quiz.id);
}}
class="border border-green-600"
>
Delete
</button>
</td>
<td
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
>