From b5a90b6519820e0239bfa9ce40f723a6a062fac6 Mon Sep 17 00:00:00 2001 From: yunji118 Date: Fri, 12 Jan 2024 19:37:40 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20quiz=20=EC=A4=91=EB=B3=B5=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20#32?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ALGo/ALGo_server/quiz/Service/QuizService.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java b/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java index 460e4a6..9595cfd 100644 --- a/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java +++ b/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java @@ -9,9 +9,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import java.util.*; @Service @RequiredArgsConstructor @@ -22,14 +20,14 @@ public class QuizService { public QuizResponseDto getQuiz(){ Random random = new Random(); - List quizDtoList = new ArrayList<>(); - for(int i=0;i<4;i++){ + Set quizDtoList = new HashSet<>(); + while (quizDtoList.size() < 4){ Long randomNum = Long.valueOf(random.nextInt(16) + 1); Quiz q = quizRepository.findById(randomNum).get(); QuizDto quizDto = new QuizDto(q); quizDtoList.add(quizDto); } - QuizResponseDto responseDto = new QuizResponseDto(quizDtoList); + QuizResponseDto responseDto = new QuizResponseDto(quizDtoList.stream().toList()); return responseDto; }