Skip to content

Commit

Permalink
Chore : 학습 세트 추가 시 중복 처리
Browse files Browse the repository at this point in the history
- 기존에 존재하던 학습 세트 번호일 경우 추가하지 않음
- 기존에 존재하던 학습 세트는 수정 api 구현 필요
  • Loading branch information
chanmin-00 committed Dec 29, 2024
1 parent 3b91dd4 commit bca5845
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ public interface LearningSetRepository extends JpaRepository<LearningSet, Long>

@Query("SELECT l.id FROM LearningSet l WHERE l.level = :level")
List<Long> findIdsByLevel(@Param("level") Level level);

@Query("SELECT ls.learningSetNum FROM LearningSet ls")
List<String> findAllLearningSetNums();
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,28 @@ public class LearningAdminService {
@Transactional
public void createLearningSetByExcel() {
try {

List<LearningSet> learningSetList = parseLearningSetsFromExcel();
Map<String, LearningSet> learningSetMap =
learningSetList.stream()
.collect(
Collectors.toMap(LearningSet::getLearningSetNum, learningSet -> learningSet));

// 기존에 존재하는 LearningSetNum 조회
List<String> existingLearningSetNums = learningSetRepository.findAllLearningSetNums();

// 새로운 학습 세트만 필터링
List<LearningSet> newLearningSets =
learningSetList.stream()
.filter(
learningSet -> !existingLearningSetNums.contains(learningSet.getLearningSetNum()))
.collect(Collectors.toList());

addConceptsToLearningSets(learningSetMap);
addQuizzesToLearningSets(learningSetMap);

learningSetRepository.saveAll(learningSetList);

// 모든 사용자에게 학습 세트를 배포
learningSetCompleteEventListener.handleLearningSetCompleteEvent(learningSetList);
learningSetRepository.saveAll(newLearningSets);
learningSetCompleteEventListener.handleLearningSetCompleteEvent(newLearningSets);

} catch (Exception e) {
log.error("Failed to save learning set by excel", e);
Expand Down

0 comments on commit bca5845

Please sign in to comment.