mirror of
https://github.com/jcreek/AutomatedAssessmentFeedbackAgent.git
synced 2026-07-12 18:43: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 = '';
|
||||
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">
|
||||
|
||||
Reference in New Issue
Block a user