From 44e9308927ae95ce5890e1c35edf351459611a12 Mon Sep 17 00:00:00 2001 From: kgc91747 Date: Fri, 2 Aug 2024 16:18:17 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Quiz=20=EA=B0=95=EC=82=AC/=ED=95=99?= =?UTF-8?q?=EC=83=9D=20=ED=83=80=EC=9E=85=EB=B3=84=20=ED=80=B4=EC=A6=88=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B2=B0=EA=B3=BC=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edufocus/quiz/controller/QuizController.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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));