✨ Added delete-quiz
This commit is contained in:
@@ -90,3 +90,15 @@ async def update_quiz(quiz_id: str, quiz_input: QuizInput, user: User = Depends(
|
|||||||
@router.post("/import/{quiz_id}")
|
@router.post("/import/{quiz_id}")
|
||||||
async def import_quiz_route(quiz_id: str, user: User = Depends(get_current_user)):
|
async def import_quiz_route(quiz_id: str, user: User = Depends(get_current_user)):
|
||||||
return await import_quiz(quiz_id, 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()
|
||||||
@@ -42,6 +42,13 @@
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
window.location.replace(`/admin?token=${data.game_id}&pin=${data.game_pin}&connect=1`);
|
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>
|
</script>
|
||||||
|
|
||||||
{#await getData()}
|
{#await getData()}
|
||||||
@@ -109,6 +116,12 @@
|
|||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</th>
|
</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
|
<th
|
||||||
scope="col"
|
scope="col"
|
||||||
class="py-3 px-6 text-xs font-medium tracking-wider text-left text-gray-700 uppercase dark:text-gray-400"
|
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>
|
<a href="/edit?quiz_id={quiz.id}">Edit</a>
|
||||||
</td>
|
</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
|
<td
|
||||||
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
|
class="py-4 px-6 text-sm text-gray-500 whitespace-nowrap dark:text-gray-400"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user