Skip to content

Commit 18cbafa

Browse files
committed
Update AssignmentService.java
1 parent 617668b commit 18cbafa

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

submission-service/src/main/java/com/codecampus/submission/service/AssignmentService.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,37 @@ public List<Assignment> assignExerciseToMany(
167167
}
168168

169169
List<Assignment> assignmentListSaved =
170-
assignmentRepository.saveAll(assignmentList);
170+
assignmentRepository.saveAllAndFlush(assignmentList);
171171

172172
assignmentListSaved.forEach(
173-
assignment -> pushAssignmentToChildService(
174-
exercise, assignment));
173+
assignment -> {
174+
pushAssignmentToChildService(
175+
exercise, assignment);
176+
177+
ExerciseStatusDto exerciseStatusDto = new ExerciseStatusDto(
178+
exerciseId, assignment.getStudentId(),
179+
/* created */ false,
180+
/* completed */ false,
181+
/* completedAt */ null,
182+
/* attempts */ null,
183+
/* bestScore */ null,
184+
/* totalPts */ null);
185+
exerciseStatusEventProducer.publishUpsert(exerciseStatusDto);
186+
187+
NotificationEvent evt = NotificationEvent.builder()
188+
.channel("SOCKET") // hoặc "EMAIL", "PUSH" nếu sau này mở rộng
189+
.recipient(assignment.getStudentId()) // userId đích
190+
.templateCode("ASSIGNMENT_ASSIGNED") // code template
191+
.subject("Bạn được giao bài tập mới")
192+
.body("Bạn vừa được giao bài: " + exercise.getTitle())
193+
.param(Map.of(
194+
"exerciseId", exercise.getId(),
195+
"exerciseTitle", exercise.getTitle(),
196+
"dueAt", assignment.getDueAt()
197+
))
198+
.build();
199+
notificationEventProducer.publish(evt);
200+
});
175201

176202
return assignmentListSaved;
177203
}

0 commit comments

Comments
 (0)