@@ -49,6 +49,12 @@ public class EmailMappingService {
4949 // Email mapping operations
5050 // ================================================================
5151
52+ /**
53+ * Returns all email mappings for the given exercise.
54+ *
55+ * @param exerciseId the exercise ID
56+ * @return list of email mapping DTOs
57+ */
5258 public List <EmailMappingDTO > getAllMappings (Long exerciseId ) {
5359 return emailMappingRepository .findAllByExerciseId (exerciseId )
5460 .stream ()
@@ -58,6 +64,17 @@ public List<EmailMappingDTO> getAllMappings(Long exerciseId) {
5864 .toList ();
5965 }
6066
67+ /**
68+ * Creates a new email-to-student mapping. Resolves the student ID by name,
69+ * re-assigns matching orphan chunks to the student, updates commit/line stats,
70+ * and recalculates the CQI.
71+ *
72+ * @param exerciseId the exercise ID
73+ * @param request the mapping request with git email, student info and participation ID
74+ * @return updated client response DTO
75+ * @throws IllegalArgumentException if participation not found or student ID is invalid
76+ * @throws EmailMappingConflictException if a mapping for the email already exists
77+ */
6178 @ Transactional
6279 public ClientResponseDTO createMapping (Long exerciseId , CreateEmailMappingRequestDTO request ) {
6380 // 1. Find the team participation
@@ -117,6 +134,16 @@ public ClientResponseDTO createMapping(Long exerciseId, CreateEmailMappingReques
117134 return buildResponse (participation );
118135 }
119136
137+ /**
138+ * Dismisses an orphan email without assigning it to a student.
139+ * Chunks are NOT mutated; the dismissed mapping is used by clients
140+ * to filter them into a separate section.
141+ *
142+ * @param exerciseId the exercise ID
143+ * @param request the dismiss request with git email and participation ID
144+ * @return updated client response, or empty if participation not found
145+ * @throws EmailMappingConflictException if a mapping for the email already exists
146+ */
120147 @ Transactional
121148 public Optional <ClientResponseDTO > dismissEmail (Long exerciseId , DismissEmailRequestDTO request ) {
122149 // 1. Normalize and check for duplicates
@@ -143,6 +170,15 @@ public Optional<ClientResponseDTO> dismissEmail(Long exerciseId, DismissEmailReq
143170 return Optional .empty ();
144171 }
145172
173+ /**
174+ * Deletes an email mapping and reverts affected chunks back to external/orphan status.
175+ * Subtracts the chunk stats from the previously assigned student and recalculates CQI.
176+ *
177+ * @param exerciseId the exercise ID
178+ * @param mappingId the mapping ID to delete
179+ * @return updated client response for the last affected team, or empty if no chunks changed
180+ * @throws IllegalArgumentException if mapping not found or does not belong to the exercise
181+ */
146182 @ Transactional
147183 public Optional <ClientResponseDTO > deleteMapping (Long exerciseId , UUID mappingId ) {
148184 ExerciseEmailMapping mapping = emailMappingRepository .findById (mappingId )
@@ -196,13 +232,28 @@ public Optional<ClientResponseDTO> deleteMapping(Long exerciseId, UUID mappingId
196232 // Template author operations
197233 // ================================================================
198234
235+ /**
236+ * Returns all configured template authors for the given exercise.
237+ *
238+ * @param exerciseId the exercise ID
239+ * @return list of template author DTOs
240+ */
199241 public List <TemplateAuthorDTO > getTemplateAuthors (Long exerciseId ) {
200242 return templateAuthorRepository .findByExerciseId (exerciseId )
201243 .stream ()
202244 .map (ta -> new TemplateAuthorDTO (ta .getTemplateEmail (), ta .getAutoDetected ()))
203245 .toList ();
204246 }
205247
248+ /**
249+ * Replaces all template authors for an exercise. Chunks from removed template emails
250+ * become regular orphans if not known via students or mappings. Chunks matching new
251+ * template emails are marked as external. CQI is recalculated for all teams.
252+ *
253+ * @param exerciseId the exercise ID
254+ * @param request list of template author DTOs with emails
255+ * @return list of updated client response DTOs for all teams
256+ */
206257 @ Transactional
207258 public List <ClientResponseDTO > setTemplateAuthors (Long exerciseId , List <TemplateAuthorDTO > request ) {
208259 // Collect old emails
@@ -261,6 +312,14 @@ public List<ClientResponseDTO> setTemplateAuthors(Long exerciseId, List<Template
261312 return responses ;
262313 }
263314
315+ /**
316+ * Removes all template author configurations for an exercise.
317+ * Chunks from old template authors that match a known student or mapping
318+ * are unmarked as external. CQI is recalculated for all teams.
319+ *
320+ * @param exerciseId the exercise ID
321+ * @return list of updated client response DTOs, or empty if none were configured
322+ */
264323 @ Transactional
265324 public Optional <List <ClientResponseDTO >> deleteTemplateAuthors (Long exerciseId ) {
266325 List <ExerciseTemplateAuthor > existing = templateAuthorRepository .findByExerciseId (exerciseId );
0 commit comments