-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
src/main/java/com/ALGo/ALGo_server/quiz/Controller/QuizController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.ALGo.ALGo_server.quiz.Controller; | ||
|
||
import com.ALGo.ALGo_server.quiz.Dto.QuizResponseDto; | ||
import com.ALGo.ALGo_server.quiz.Service.QuizService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/quiz") | ||
@RequiredArgsConstructor | ||
public class QuizController { | ||
private final QuizService quizService; | ||
|
||
@GetMapping() | ||
public QuizResponseDto getQuiz(){ | ||
return quizService.getQuiz(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ALGo.ALGo_server.quiz.Dto; | ||
|
||
import com.ALGo.ALGo_server.entity.Quiz; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
public class QuizDto { | ||
private Long id; | ||
|
||
public QuizDto(Quiz quiz){ | ||
this.id = quiz.getQuiz_id(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/ALGo/ALGo_server/quiz/Dto/QuizResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.ALGo.ALGo_server.quiz.Dto; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
public class QuizResponseDto { | ||
List<QuizDto> quizList; | ||
|
||
public QuizResponseDto(List<QuizDto> quizList){ | ||
this.quizList = quizList; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ALGo.ALGo_server.quiz.Service; | ||
|
||
|
||
import com.ALGo.ALGo_server.entity.Quiz; | ||
import com.ALGo.ALGo_server.quiz.Dto.QuizDto; | ||
import com.ALGo.ALGo_server.quiz.Dto.QuizResponseDto; | ||
import com.ALGo.ALGo_server.repository.QuizRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class QuizService { | ||
private final QuizRepository quizRepository; | ||
|
||
@Transactional(readOnly = true) | ||
public QuizResponseDto getQuiz(){ | ||
Random random = new Random(); | ||
|
||
List<QuizDto> quizDtoList = new ArrayList<>(); | ||
for(int i=0;i<4;i++){ | ||
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); | ||
|
||
return responseDto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters