Skip to content

Commit ac4afde

Browse files
committed
fix form loading previous submission
1 parent fc30012 commit ac4afde

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

backend/GroupAllocator/Controllers/StudentsController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using GroupAllocator.Services;
55
using Microsoft.AspNetCore.Authorization;
66
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.AspNetCore.Mvc.ModelBinding;
78
using Microsoft.EntityFrameworkCore;
89
using Microsoft.IdentityModel.JsonWebTokens;
910

@@ -85,13 +86,14 @@ async Task<List<StudentInfoAndSubmission>> GetStudents(int classId)
8586

8687
[HttpGet("me")]
8788
[Authorize(Policy = "StudentOnly")]
88-
public async Task<ActionResult<StudentSubmissionDto>> Get(int classId)
89+
public async Task<ActionResult<StudentSubmissionDto>> Get([BindRequired] int classId)
8990
{
9091
var userId = int.Parse(User.FindFirst(JwtRegisteredClaimNames.Sub)?.Value ?? throw new InvalidOperationException("No subject claim"));
91-
92+
Console.WriteLine($"userId: {userId}, classId: {classId}");
9293
var student = await db.Students
9394
.Include(s => s.User)
9495
.Include(s => s.Files)
96+
.Include(s => s.Class)
9597
.Include(s => s!.Preferences)
9698
.ThenInclude(p => p.Project)
9799
.Where(s => s.User.Id == userId && s.Class.Id == classId)

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@primeuix/themes": "^1.0.0",
14+
"@primevue/core": "^4.3.7",
1415
"@stripe/stripe-js": "^7.3.1",
1516
"@unocss/reset": "66.1.0-beta.3",
1617
"moment": "^2.30.1",

frontend/src/views/student/FormView.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,28 @@
113113
</template>
114114
</Card>
115115
<LogoutButton />
116+
117+
<!-- Success Dialog -->
118+
<Dialog
119+
v-model:visible="showSuccessDialog"
120+
modal
121+
header="Success"
122+
:closable="true"
123+
:close-on-escape="true"
124+
:style="{ width: '90vw', maxWidth: '500px' }"
125+
>
126+
<p class="text-base mb-2">Your project preferences have been successfully submitted.</p>
127+
<p class="text-base mb-4">You can return to this page anytime to update your preferences.</p>
128+
129+
<div class="flex flex-col sm:flex-row gap-2 justify-center">
130+
<Button
131+
label="Close"
132+
@click="showSuccessDialog = false"
133+
class="flex-1 sm:flex-none"
134+
severity="secondary"
135+
/>
136+
</div>
137+
</Dialog>
116138
</div>
117139
</template>
118140

@@ -135,6 +157,7 @@ import type { FileDetailsDto } from "../../dtos/file-details-dto";
135157
import type { StudentSubmissionDto } from "../../dtos/student-submission-dto";
136158
import { Column, DataTable } from "primevue";
137159
import { useRoute } from 'vue-router';
160+
import Dialog from "primevue/dialog";
138161
139162
const toast = useToast();
140163
const route = useRoute();
@@ -147,6 +170,7 @@ const maxNumberOfPreferences = 10;
147170
const warningMessage = "A maximum of " + maxNumberOfPreferences + " preferences has been selected. Anything more than the top " + maxNumberOfPreferences + " preferences will not be saved";
148171
let exceededPreferenceLimit = false
149172
const loading = ref(false)
173+
const showSuccessDialog = ref(false)
150174
151175
const projectsRaw = ref([] as ProjectDto[]);
152176
const projects = ref([[], []] as ProjectDto[][]);
@@ -166,7 +190,7 @@ onMounted(async () => {
166190
loading.value = true
167191
try{
168192
await loadProjects()
169-
const maybeStudent = await ApiService.get<StudentSubmissionDto | undefined>("/students/me")
193+
const maybeStudent = await ApiService.get<StudentSubmissionDto | undefined>(`/students/me?classId=${classId}`)
170194
if (maybeStudent) {
171195
console.log(maybeStudent)
172196
files.value = maybeStudent.files ?? []
@@ -241,7 +265,7 @@ const submitForm = async () => {
241265
if (result == null) {
242266
toast.add({ severity: 'error', summary: 'Failed', detail: 'Submission failed. If the issue persists contact developers', life: 5000 });
243267
} else {
244-
toast.add({ severity: 'success', summary: 'Success', detail: 'Submitted preferences', life: 5000 });
268+
showSuccessDialog.value = true;
245269
}
246270
};
247271

frontend/src/views/teacher/TeachersAdminPage.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const addTeacher = async () => {
9292
9393
teachers.value.push({ email: newTeacherEmail.value.trim(), isOwner: false })
9494
newTeacherEmail.value = ''
95+
toast.add({ severity: 'success', summary: 'Success', detail: `Teacher ${newTeacherEmail.value.trim()} added successfully`, life: 3000 });
9596
} catch {
9697
toast.add({ severity: 'error', summary: 'Failed', detail: `Failed to add teacher`, life: 3000 });
9798
} finally {
@@ -107,6 +108,7 @@ const deleteTeacher = async (teacherEmail: string) => {
107108
try {
108109
await ApiService.delete(`/class/${classId}/remove-teacher/${encodeURIComponent(teacherEmail)}`)
109110
teachers.value = teachers.value.filter(t => t.email !== teacherEmail)
111+
toast.add({ severity: 'success', summary: 'Success', detail: `Teacher ${teacherEmail} removed successfully`, life: 3000 });
110112
} catch {
111113
toast.add({ severity: 'error', summary: 'Failed', detail: `Failed to remove teacher ${teacherEmail}`, life: 3000 });
112114
} finally {

0 commit comments

Comments
 (0)