@@ -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