From 244d21ddcdc93f68be4ece9af6d4c1a8b09d39ae Mon Sep 17 00:00:00 2001 From: Donghun Lee Date: Sat, 12 Aug 2023 03:49:19 +0900 Subject: [PATCH] feat : @RequestParam -> @PathVariable --- .../contents/web/QuestionController.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/bside/BSIDE/contents/web/QuestionController.java b/src/main/java/com/bside/BSIDE/contents/web/QuestionController.java index 3cc646a..de8bd34 100644 --- a/src/main/java/com/bside/BSIDE/contents/web/QuestionController.java +++ b/src/main/java/com/bside/BSIDE/contents/web/QuestionController.java @@ -31,23 +31,21 @@ * @일자 2023.04.23. **/ -@CrossOrigin(origins = {"http://localhost:3000","http://www.goming.site"},allowCredentials = "true") +@CrossOrigin(origins = { "http://localhost:3000", "http://www.goming.site" }, allowCredentials = "true") @RestController @RequestMapping("/question") public class QuestionController { private final QuestionService questionService; - private final AnswerService answerService; - public QuestionController(QuestionService questionService, AnswerService answerService) { + public QuestionController(QuestionService questionService) { this.questionService = questionService; - this.answerService = answerService; } /* 질문 저장 */ @PostMapping("/insertQuestion") @Operation(summary = "질문 저장") - public ResponseEntity createQuestion(@RequestBody Map obj ) { + public ResponseEntity createQuestion(@RequestBody Map obj) { QuestionDto qDto = new QuestionDto(); qDto.setQCategory((String) obj.get("qCategory")); qDto.setQWriter((String) obj.get("qWriter")); @@ -57,9 +55,9 @@ public ResponseEntity createQuestion(@RequestBody Map ob return ResponseEntity.ok("입력되었습니다."); } - @GetMapping("/unanswered") + @GetMapping("/unanswered/{writer}") @Operation(summary = "금일 답변하지 않은 개수 조회") - public ResponseEntity countUnansweredQuestionsToday(@RequestParam("writer") String writer) { + public ResponseEntity countUnansweredQuestionsToday(@PathVariable("writer") String writer) { Integer count = 3 - questionService.countAnsweredQuestionsToday(writer) - questionService.countPassQuestions(writer); System.out.println("사용자가 답변한 질문은 " + questionService.countAnsweredQuestionsToday(writer) + "개입니다."); @@ -68,9 +66,9 @@ public ResponseEntity countUnansweredQuestionsToday(@RequestParam("writ } /* 이번달에 답변한 질문 개수 조회 */ - @GetMapping("/answered/month") + @GetMapping("/answered/month/{writer}") @Operation(summary = "이번달에 답변한 질문 개수 조회") - public ResponseEntity countAnsweredQuestionsThisMonth(@RequestParam("writer") String writer) { + public ResponseEntity countAnsweredQuestionsThisMonth(@PathVariable("writer") String writer) { Integer count = questionService.countAnsweredQuestionsThisMonth(writer); String message = String.format("이번 달에 답변한 질문 개수는 " + count + "개 입니다."); System.out.println(message); @@ -78,9 +76,9 @@ public ResponseEntity countAnsweredQuestionsThisMonth(@RequestParam("wr } /* 오늘 답변한 질문 개수 조회 */ - @GetMapping("/answered/day") + @GetMapping("/answered/day/{writer}") @Operation(summary = "오늘 답변한 질문 개수 조회") - public ResponseEntity countAnsweredQuestionsToday(@RequestParam("writer") String writer) { + public ResponseEntity countAnsweredQuestionsToday(@PathVariable("writer") String writer) { Integer count = questionService.countAnsweredQuestionsToday(writer); String message = String.format("오늘 답변한 질문 개수는 " + count + "개 입니다."); System.out.println(message); @@ -157,8 +155,8 @@ else if (dateArr.length == 2) { ResponseEntity.ok("선택한 날짜의 값이 존재하지 않습니다."); } - System.out.println(page+"@##!#!##!#$$!@$!@$!@4pagE@#!@@#$!@$!@$"); - if(page>0) { + System.out.println(page + "@##!#!##!#$$!@$!@$!@4pagE@#!@@#$!@$!@$"); + if (page > 0) { // 페이징 처리를 위한 Pageable 생성 int totalElements = questionAndAnswers.size(); int totalPages = (int) Math.ceil((double) totalElements / size); @@ -173,7 +171,7 @@ else if (dateArr.length == 2) { PagedResponse pagedResponse = new PagedResponse<>(pageContent, currentPage, size, totalElements); return ResponseEntity.ok(pagedResponse); - }else{ + } else { return ResponseEntity.ok(questionAndAnswers); }