diff --git a/src/main/java/com/hangeulbada/domain/workbookset/repository/QuestionIdsDTO.java b/src/main/java/com/hangeulbada/domain/workbookset/dto/QuestionIdsDTO.java similarity index 91% rename from src/main/java/com/hangeulbada/domain/workbookset/repository/QuestionIdsDTO.java rename to src/main/java/com/hangeulbada/domain/workbookset/dto/QuestionIdsDTO.java index e2af652..82f524b 100644 --- a/src/main/java/com/hangeulbada/domain/workbookset/repository/QuestionIdsDTO.java +++ b/src/main/java/com/hangeulbada/domain/workbookset/dto/QuestionIdsDTO.java @@ -1,4 +1,4 @@ -package com.hangeulbada.domain.workbookset.repository; +package com.hangeulbada.domain.workbookset.dto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/hangeulbada/domain/workbookset/repository/IncorrectAnswerTagRepository.java b/src/main/java/com/hangeulbada/domain/workbookset/repository/IncorrectAnswerTagRepository.java index 4d4ce57..1411a05 100644 --- a/src/main/java/com/hangeulbada/domain/workbookset/repository/IncorrectAnswerTagRepository.java +++ b/src/main/java/com/hangeulbada/domain/workbookset/repository/IncorrectAnswerTagRepository.java @@ -1,5 +1,6 @@ package com.hangeulbada.domain.workbookset.repository; +import com.hangeulbada.domain.workbookset.dto.QuestionIdsDTO; import com.hangeulbada.domain.workbookset.entity.IncorrectAnswerTag; import org.springframework.data.mongodb.repository.Aggregation; import org.springframework.data.mongodb.repository.MongoRepository; @@ -18,4 +19,6 @@ public interface IncorrectAnswerTagRepository extends MongoRepository getReviewWorkbooks(String studentId); + + void deleteRecordByQuestionId(String questionId); } diff --git a/src/main/java/com/hangeulbada/domain/workbookset/service/impl/IncorrectAnswerServiceImpl.java b/src/main/java/com/hangeulbada/domain/workbookset/service/impl/IncorrectAnswerServiceImpl.java index 642637b..f577682 100644 --- a/src/main/java/com/hangeulbada/domain/workbookset/service/impl/IncorrectAnswerServiceImpl.java +++ b/src/main/java/com/hangeulbada/domain/workbookset/service/impl/IncorrectAnswerServiceImpl.java @@ -9,7 +9,7 @@ import com.hangeulbada.domain.workbookset.entity.Workbook; import com.hangeulbada.domain.workbookset.exception.NoIncorrectsException; import com.hangeulbada.domain.workbookset.repository.IncorrectAnswerTagRepository; -import com.hangeulbada.domain.workbookset.repository.QuestionIdsDTO; +import com.hangeulbada.domain.workbookset.dto.QuestionIdsDTO; import com.hangeulbada.domain.workbookset.repository.WorkbookRepository; import com.hangeulbada.domain.workbookset.service.IncorrectAnswerService; import com.hangeulbada.domain.workbookset.service.WorkbookService; @@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; import org.modelmapper.ModelMapper; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.*; @@ -37,6 +38,7 @@ public class IncorrectAnswerServiceImpl implements IncorrectAnswerService { private final WorkbookRepository workbookRepository; private final GroupService groupService; private final GroupRepository groupRepository; + private final IncorrectAnswerTagRepository incorrectAnswerTagRepository; @Override public List countIncorrects(String studentId) { @@ -71,6 +73,7 @@ public QuestionIdsDTO getIncorrectsByTag(String studentId, String tagName) { return questionIdsDTO; } + @Transactional @Override public WorkbookIdResponseDto createIncorrectsWorkbook(String studentId, TagRequestDto tagRequestDto){ // 오답 태그로 이뤄진 문장 가져오기 @@ -117,4 +120,10 @@ public List getReviewWorkbooks(String studentId) { return workbookDtos; } + @Transactional + @Override + public void deleteRecordByQuestionId(String questionId) { + incorrectAnswerTagRepository.deleteAllByQuestionId(questionId); + } + } diff --git a/src/main/java/com/hangeulbada/domain/workbookset/service/impl/QuestionServiceImpl.java b/src/main/java/com/hangeulbada/domain/workbookset/service/impl/QuestionServiceImpl.java index 272ee4c..76c798f 100644 --- a/src/main/java/com/hangeulbada/domain/workbookset/service/impl/QuestionServiceImpl.java +++ b/src/main/java/com/hangeulbada/domain/workbookset/service/impl/QuestionServiceImpl.java @@ -10,6 +10,7 @@ import com.hangeulbada.domain.workbookset.exception.WorkbookException; import com.hangeulbada.domain.workbookset.repository.QuestionRepository; import com.hangeulbada.domain.workbookset.repository.WorkbookRepository; +import com.hangeulbada.domain.workbookset.service.IncorrectAnswerService; import com.hangeulbada.domain.workbookset.service.QuestionService; import com.hangeulbada.domain.workbookset.service.WorkbookService; import lombok.RequiredArgsConstructor; @@ -33,6 +34,7 @@ public class QuestionServiceImpl implements QuestionService { private final TTSService ttsService; private final ApiService apiService; private final WorkbookService workbookService; + private final IncorrectAnswerService incorrectAnswerService; @Override public List getQuestionsByWorkbookId(String workbookId) { @@ -70,6 +72,7 @@ public void deleteQuestion(String teacherId, String questionId) { workbookService.updateWorkbookDifficulty(w.getId()); } } + incorrectAnswerService.deleteRecordByQuestionId(questionId); ttsService.deleteFileFromS3(question.getAudioFilePath()); questionRepository.deleteById(questionId); }