|
12 | 12 | import org.springframework.web.bind.annotation.*; |
13 | 13 |
|
14 | 14 | @RestController |
15 | | -@RequestMapping("/api/sessions") |
16 | 15 | @RequiredArgsConstructor |
17 | 16 | public class QuestionController { |
18 | 17 | private final QuestionService questionService; |
19 | 18 |
|
20 | 19 | // 질문 목록 + 이해도 조회 |
21 | 20 | // GET /api/sessions/{sessionId}/questions?understandingIndex=0 |
22 | | - @GetMapping("/{sessionId}/questions") |
| 21 | + @GetMapping("/api/sessions/{sessionId}/questions") |
23 | 22 | public ResponseEntity<ApiResponse<QuestionResDTO.QuestionRoomResponse>> getQuestionRoom( |
24 | 23 | @PathVariable Long sessionId, |
25 | 24 | @RequestParam(defaultValue = "0") int understandingIndex |
26 | 25 | ) { |
27 | | - QuestionResDTO.QuestionRoomResponse response = |
28 | | - questionService.getQuestionRoom(sessionId, understandingIndex); |
29 | | - |
30 | | - return ResponseUtil.success(QuestionSuccessCode.QUESTION_ROOM_OK, response); |
| 26 | + return ResponseUtil.success(QuestionSuccessCode.QUESTION_ROOM_OK, |
| 27 | + questionService.getQuestionRoom(sessionId, understandingIndex)); |
31 | 28 | } |
32 | 29 |
|
33 | | - // 이해도 체크 응답 |
34 | | - // POST /api/sessions/{sessionId}/understanding-checks/{checkId}/responses |
35 | | - @PostMapping("/{sessionId}/understanding-checks/{checkId}/responses") |
36 | | - public ResponseEntity<ApiResponse<QuestionResDTO.UnderstandingResponseResult>> respondUnderstandingCheck( |
37 | | - @PathVariable Long sessionId, |
38 | | - @PathVariable Long checkId, |
39 | | - @RequestBody QuestionReqDTO.UnderstandingResponseReq request, |
40 | | - @AuthenticationPrincipal Integer userId |
| 30 | + // 질문 상세 조회 |
| 31 | + // GET /api/questions/{questionId} |
| 32 | + @GetMapping("/api/questions/{questionId}") |
| 33 | + public ResponseEntity<ApiResponse<QuestionResDTO.QuestionDetailResponse>> getQuestionDetail( |
| 34 | + @PathVariable Long questionId, |
| 35 | + @AuthenticationPrincipal Long userId |
41 | 36 | ) { |
42 | | - QuestionResDTO.UnderstandingResponseResult response = |
43 | | - questionService.respondUnderstandingCheck(sessionId, checkId, request, userId); |
44 | | - |
45 | | - return ResponseUtil.success(QuestionSuccessCode.UNDERSTANDING_RESPONSE_OK, response); |
| 37 | + return ResponseUtil.success(QuestionSuccessCode.QUESTION_DETAIL_OK, |
| 38 | + questionService.getQuestionDetail(questionId, userId)); |
46 | 39 | } |
47 | 40 |
|
48 | 41 | // 질문 등록 |
49 | 42 | // POST /api/sessions/{sessionId}/questions |
50 | | - @PostMapping("/{sessionId}/questions") |
| 43 | + @PostMapping("/api/sessions/{sessionId}/questions") |
51 | 44 | public ResponseEntity<ApiResponse<QuestionResDTO.CreateRes>> createQuestion( |
52 | 45 | @PathVariable Long sessionId, |
53 | 46 | @RequestBody QuestionReqDTO.CreateReq request, |
54 | 47 | @AuthenticationPrincipal Integer userId |
55 | 48 | ) { |
56 | | - QuestionResDTO.CreateRes response = |
57 | | - questionService.createQuestion(userId.longValue(), request, userId); |
| 49 | + return ResponseUtil.success(QuestionSuccessCode.QUESTION_CREATED, |
| 50 | + questionService.createQuestion(sessionId, request, Long.valueOf(userId))); |
| 51 | + } |
58 | 52 |
|
59 | | - return ResponseUtil.success(QuestionSuccessCode.QUESTION_CREATED, response); |
| 53 | + // 댓글/대댓글 등록 |
| 54 | + // POST /api/questions/{questionId}/comments |
| 55 | + @PostMapping("/api/questions/{questionId}/comments") |
| 56 | + public ResponseEntity<ApiResponse<QuestionResDTO.CommentCreateRes>> createComment( |
| 57 | + @PathVariable Long questionId, |
| 58 | + @RequestBody QuestionReqDTO.CommentReq request, |
| 59 | + @AuthenticationPrincipal Long userId |
| 60 | + ) { |
| 61 | + return ResponseUtil.success(QuestionSuccessCode.COMMENT_CREATED, |
| 62 | + questionService.createComment(questionId, request, userId)); |
| 63 | + } |
| 64 | + |
| 65 | + // 좋아요 토글 |
| 66 | + // POST /api/questions/{questionId}/like |
| 67 | + @PostMapping("/api/questions/{questionId}/like") |
| 68 | + public ResponseEntity<ApiResponse<QuestionResDTO.LikeRes>> toggleLike( |
| 69 | + @PathVariable Long questionId, |
| 70 | + @AuthenticationPrincipal Long userId |
| 71 | + ) { |
| 72 | + return ResponseUtil.success(QuestionSuccessCode.LIKE_TOGGLED, |
| 73 | + questionService.toggleLike(questionId, userId)); |
| 74 | + } |
| 75 | + |
| 76 | + // 이해도 체크 응답 |
| 77 | + // POST /api/sessions/{sessionId}/understanding-checks/{checkId}/responses |
| 78 | + @PostMapping("/api/sessions/{sessionId}/understanding-checks/{checkId}/responses") |
| 79 | + public ResponseEntity<ApiResponse<QuestionResDTO.UnderstandingResponseResult>> respondUnderstandingCheck( |
| 80 | + @PathVariable Long sessionId, |
| 81 | + @PathVariable Long checkId, |
| 82 | + @RequestBody QuestionReqDTO.UnderstandingResponseReq request, |
| 83 | + @AuthenticationPrincipal Long userId |
| 84 | + ) { |
| 85 | + return ResponseUtil.success(QuestionSuccessCode.UNDERSTANDING_RESPONSE_OK, |
| 86 | + questionService.respondUnderstandingCheck(sessionId, checkId, request, userId)); |
60 | 87 | } |
61 | 88 | } |
0 commit comments