mirror of
https://github.com/jcreek/AutomatedAssessmentFeedbackAgent.git
synced 2026-07-13 02:53:49 +00:00
feat(*): Add mocked grading process
This commit is contained in:
@@ -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' }
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -33,15 +33,33 @@ async function handleSubmit(event: Event) {
|
|||||||
successMsg = '';
|
successMsg = '';
|
||||||
errorMsg = '';
|
errorMsg = '';
|
||||||
|
|
||||||
// TODO - Actually do an upload, remove simulation of a successful upload
|
const formData = new FormData();
|
||||||
await new Promise((resolve) => setTimeout(resolve, 800));
|
if (file) {
|
||||||
if (file || textInput.trim().length > 0) {
|
formData.append('file', file);
|
||||||
successMsg = 'Submission received! AI assessment coming soon.';
|
} else if (textInput.trim().length > 0) {
|
||||||
} else {
|
formData.append('text', textInput.trim());
|
||||||
errorMsg = 'Please provide a file or enter text.';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
</script>
|
||||||
|
|
||||||
<section class="max-w-xl mx-auto py-12">
|
<section class="max-w-xl mx-auto py-12">
|
||||||
|
|||||||
Reference in New Issue
Block a user