diff --git a/backend/src/main/java/com/edufocus/edufocus/quiz/controller/QuizController.java b/backend/src/main/java/com/edufocus/edufocus/quiz/controller/QuizController.java index 3a27228..c85822a 100644 --- a/backend/src/main/java/com/edufocus/edufocus/quiz/controller/QuizController.java +++ b/backend/src/main/java/com/edufocus/edufocus/quiz/controller/QuizController.java @@ -42,13 +42,25 @@ public class QuizController { return new ResponseEntity<>(HttpStatus.CREATED); } - @GetMapping("/{quizsetId}") + @GetMapping("/student/{quizsetId}") public ResponseEntity getQuizzes(@PathVariable Long quizsetId) { QuizSetResponse quizSet = quizSetService.findQuizSetResponse(quizsetId); return new ResponseEntity<>(quizSet, HttpStatus.OK); } + @GetMapping("/teacher/{quizsetId}") + public ResponseEntity getQuizzesIncludeAnswer(@RequestHeader("Authorization") String accessToken, @PathVariable Long quizsetId) { + long userId = Long.parseLong(jwtUtil.getUserId(accessToken)); + + QuizSet quizSet = quizSetService.findQuizSet(quizsetId); + if (quizSet.getUser().getId() != userId) { + return new ResponseEntity<>(HttpStatus.UNAUTHORIZED); + } + + return new ResponseEntity<>(quizSet, HttpStatus.OK); + } + @DeleteMapping("/{quizsetId}") public ResponseEntity deleteQuizSet(@RequestHeader("Authorization") String accessToken, @PathVariable long quizsetId) { long userId = Long.parseLong(jwtUtil.getUserId(accessToken));