1111import com .jobdri .jobdri_api .domain .analysis .entity .Question ;
1212import com .jobdri .jobdri_api .domain .analysis .repository .CustomQuestionCandidateRepository ;
1313import com .jobdri .jobdri_api .domain .analysis .repository .QuestionRepository ;
14- import com .jobdri .jobdri_api .domain .audit .service . AuditLogService ;
14+ import com .jobdri .jobdri_api .domain .audit .annotation . AuditLogEvent ;
1515import com .jobdri .jobdri_api .domain .mockapply .entity .MockApply ;
1616import com .jobdri .jobdri_api .domain .mockapply .entity .MockApplyStatus ;
1717import com .jobdri .jobdri_api .domain .mockapply .repository .MockApplyRepository ;
@@ -51,7 +51,6 @@ public class QuestionService {
5151 private final MockApplyRepository mockApplyRepository ;
5252 private final QuestionRepository questionRepository ;
5353 private final CustomQuestionCandidateRepository customQuestionCandidateRepository ;
54- private final AuditLogService auditLogService ;
5554
5655 public List <QuestionCandidateResponse > getQuestionCandidates (User user , Long mockApplyId ) {
5756 MockApply mockApply = getOwnedMockApply (user , mockApplyId );
@@ -84,6 +83,7 @@ public List<QuestionCandidateResponse> getQuestionCandidates(User user, Long moc
8483 }
8584
8685 @ Transactional
86+ @ AuditLogEvent (action = "CUSTOM_QUESTION_CANDIDATE_ADD" , targetType = "MOCK_APPLY" , targetId = "#arg1" )
8787 public QuestionCandidateResponse addCustomQuestionCandidate (
8888 User user ,
8989 Long mockApplyId ,
@@ -96,23 +96,13 @@ public QuestionCandidateResponse addCustomQuestionCandidate(
9696 CustomQuestionCandidate candidate = findOrCreateCustomCandidate (mockApply , content , request .charLimit ());
9797 boolean selected = questionRepository .existsByMockApplyIdAndContent (mockApply .getId (), candidate .getContent ());
9898
99- QuestionCandidateResponse response = new QuestionCandidateResponse (
99+ return new QuestionCandidateResponse (
100100 candidate .getId (),
101101 candidate .getContent (),
102102 candidate .getLimit (),
103103 selected ,
104104 true
105105 );
106- auditLogService .record (
107- user ,
108- "CUSTOM_QUESTION_CANDIDATE_ADD" ,
109- "MOCK_APPLY" ,
110- mockApply .getId (),
111- null ,
112- response
113- );
114-
115- return response ;
116106 }
117107
118108 private CustomQuestionCandidate findOrCreateCustomCandidate (
@@ -153,6 +143,7 @@ public QuestionSelectionResponse getSelectedQuestions(User user, Long mockApplyI
153143 }
154144
155145 @ Transactional
146+ @ AuditLogEvent (action = "QUESTION_SELECTION_SAVE" , targetType = "MOCK_APPLY" , targetId = "#arg1" )
156147 public QuestionSelectionResponse saveSelectedQuestions (
157148 User user ,
158149 Long mockApplyId ,
@@ -162,9 +153,6 @@ public QuestionSelectionResponse saveSelectedQuestions(
162153 validateSelectionCount (request .questions ().size ());
163154
164155 List <Question > existingQuestions = questionRepository .findAllByMockApplyId (mockApply .getId ());
165- List <QuestionAuditValue > beforeQuestions = existingQuestions .stream ()
166- .map (QuestionAuditValue ::from )
167- .toList ();
168156 questionRepository .deleteAll (existingQuestions );
169157
170158 List <Question > questions = request .questions ().stream ()
@@ -178,24 +166,15 @@ public QuestionSelectionResponse saveSelectedQuestions(
178166 List <Question > savedQuestions = questionRepository .saveAll (questions );
179167 mockApply .updateStatus (MockApplyStatus .ANSWER_WRITE );
180168
181- QuestionSelectionResponse response = new QuestionSelectionResponse (
169+ return new QuestionSelectionResponse (
182170 mockApply .getId (),
183171 mockApply .getStatus (),
184172 savedQuestions .stream ().map (QuestionResponse ::from ).toList ()
185173 );
186- auditLogService .record (
187- user ,
188- "QUESTION_SELECTION_SAVE" ,
189- "MOCK_APPLY" ,
190- mockApply .getId (),
191- beforeQuestions ,
192- savedQuestions .stream ().map (QuestionAuditValue ::from ).toList ()
193- );
194-
195- return response ;
196174 }
197175
198176 @ Transactional
177+ @ AuditLogEvent (action = "QUESTION_ANSWER_SAVE" , targetType = "MOCK_APPLY" , targetId = "#arg1" )
199178 public QuestionAnswerResponse saveAnswers (
200179 User user ,
201180 Long mockApplyId ,
@@ -205,9 +184,6 @@ public QuestionAnswerResponse saveAnswers(
205184 List <Question > questions = questionRepository .findAllByMockApplyIdOrderByIdAsc (mockApply .getId ());
206185 Map <Long , Question > questionMap = questions .stream ()
207186 .collect (Collectors .toMap (Question ::getId , Function .identity ()));
208- List <QuestionAnswerAuditValue > beforeAnswers = questions .stream ()
209- .map (QuestionAnswerAuditValue ::from )
210- .toList ();
211187
212188 for (QuestionAnswerSaveRequest .AnswerItem item : request .answers ()) {
213189 Question question = questionMap .get (item .questionId ());
@@ -220,21 +196,11 @@ public QuestionAnswerResponse saveAnswers(
220196 question .updateAnswer (normalizeAnswer (item .answer ()));
221197 }
222198
223- QuestionAnswerResponse response = new QuestionAnswerResponse (
199+ return new QuestionAnswerResponse (
224200 mockApply .getId (),
225201 mockApply .getStatus (),
226202 questions .stream ().map (QuestionResponse ::from ).toList ()
227203 );
228- auditLogService .record (
229- user ,
230- "QUESTION_ANSWER_SAVE" ,
231- "MOCK_APPLY" ,
232- mockApply .getId (),
233- beforeAnswers ,
234- questions .stream ().map (QuestionAnswerAuditValue ::from ).toList ()
235- );
236-
237- return response ;
238204 }
239205
240206 private MockApply getOwnedMockApply (User user , Long mockApplyId ) {
@@ -284,16 +250,4 @@ private String normalizeAnswer(String answer) {
284250
285251 private record QuestionCandidate (Long id , String content , int charLimit ) {
286252 }
287-
288- private record QuestionAuditValue (Long questionId , String content , int charLimit ) {
289- private static QuestionAuditValue from (Question question ) {
290- return new QuestionAuditValue (question .getId (), question .getContent (), question .getLimit ());
291- }
292- }
293-
294- private record QuestionAnswerAuditValue (Long questionId , String answer ) {
295- private static QuestionAnswerAuditValue from (Question question ) {
296- return new QuestionAnswerAuditValue (question .getId (), question .getAnswer ());
297- }
298- }
299253}
0 commit comments