From a0788a7311224ed968c8f3a612aa6857cc913b2e Mon Sep 17 00:00:00 2001 From: Ohwooseok <63221878+Ohwooseok@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:33:37 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feature:=20Question=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=A0=81=EC=9A=A9=20(#50)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/question/controller/QuestionController.java | 10 ++++++++-- .../domain/question/service/QuestionService.java | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/smunity/petition/domain/question/controller/QuestionController.java b/src/main/java/com/smunity/petition/domain/question/controller/QuestionController.java index 82cd822..9b9ec4b 100644 --- a/src/main/java/com/smunity/petition/domain/question/controller/QuestionController.java +++ b/src/main/java/com/smunity/petition/domain/question/controller/QuestionController.java @@ -5,9 +5,11 @@ import com.smunity.petition.domain.question.dto.QuestionResponseDto; import com.smunity.petition.domain.question.service.QuestionService; import com.smunity.petition.global.common.ApiResponse; +import jdk.jfr.Frequency; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.*; @RequiredArgsConstructor @@ -16,11 +18,15 @@ public class QuestionController { private final QuestionService questionService; - @GetMapping + /* @GetMapping public ApiResponse> list(Pageable pageable) { return ApiResponse.onSuccess(questionService.getQuestion(pageable)); } - +*/ + @GetMapping + public ApiResponse> list(@PageableDefault Pageable pageable){ + return ApiResponse.onSuccess(questionService.getQuestion(pageable)); + } @GetMapping("/{id}") public ApiResponse read(@PathVariable Long id) { diff --git a/src/main/java/com/smunity/petition/domain/question/service/QuestionService.java b/src/main/java/com/smunity/petition/domain/question/service/QuestionService.java index d78f7b2..e6b6e25 100644 --- a/src/main/java/com/smunity/petition/domain/question/service/QuestionService.java +++ b/src/main/java/com/smunity/petition/domain/question/service/QuestionService.java @@ -22,12 +22,19 @@ public class QuestionService { private final QuestionRepository questionRepository; private final UserRepository userRepository; - public Page getQuestion(Pageable pageable) { + /*public Page getQuestion(Pageable pageable) { + Page questions = questionRepository.findAll(pageable); + return questions.map(QuestionListDto::from); + }*/ + + public Page getQuestion(Pageable pageable){ Page questions = questionRepository.findAll(pageable); return questions.map(QuestionListDto::from); } + + public QuestionResponseDto getQuestionById(Long id) { Question QuestionEntity = questionRepository.findById(id).orElseThrow( () -> new GeneralException(ErrorCode.QUESTION_NOT_FOUND));