feat(*): Add mocked grading process

This commit is contained in:
Josh Creek
2025-04-16 22:52:41 +01:00
parent eba66d5a99
commit 6fb6b04432
2 changed files with 50 additions and 7 deletions
+25
View File
@@ -0,0 +1,25 @@
import type { RequestHandler } from '@sveltejs/kit';
import type { RequestEvent } from '@sveltejs/kit';
// TODO - don't just mock the grading logic
export const POST: RequestHandler = async (event: RequestEvent) => {
const data = await event.request.formData();
const file = data.get('file');
const text = data.get('text');
// Simulation of grading and feedback
let feedback = '';
if (file) {
feedback = 'Received file: ' + (file as File).name + '. [AI feedback coming soon]';
} else if (typeof text === 'string' && text.trim().length > 0) {
feedback = 'Received text submission. [AI feedback coming soon]';
} else {
return new Response(JSON.stringify({ error: 'No valid input provided.' }), { status: 400 });
}
// Return mock feedback for now
return new Response(JSON.stringify({ success: true, feedback }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
};
+25 -7
View File
@@ -33,15 +33,33 @@ async function handleSubmit(event: Event) {
successMsg = '';
errorMsg = '';
// TODO - Actually do an upload, remove simulation of a successful upload
await new Promise((resolve) => setTimeout(resolve, 800));
if (file || textInput.trim().length > 0) {
successMsg = 'Submission received! AI assessment coming soon.';
} else {
errorMsg = 'Please provide a file or enter text.';
const formData = new FormData();
if (file) {
formData.append('file', file);
} else if (textInput.trim().length > 0) {
formData.append('text', textInput.trim());
}
try {
const response = await fetch('/api/grade', {
method: 'POST',
body: formData
});
const result = await response.json();
if (response.ok && result.success) {
successMsg = result.feedback;
file = null;
textInput = '';
} else {
errorMsg = result.error || 'An error occurred.';
}
} catch (err) {
errorMsg = 'Network or server error.';
} finally {
submitting = false;
}
submitting = false;
}
</script>
<section class="max-w-xl mx-auto py-12">