From be77c75701bb240ac98de171798b1f4c45113d05 Mon Sep 17 00:00:00 2001 From: chamm99 Date: Thu, 29 Feb 2024 19:57:18 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8feat:=20Question=20=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=95=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/question/controller/QuestionController.java | 9 +++++---- .../domain/question/service/QuestionService.java | 10 +++++----- 2 files changed, 10 insertions(+), 9 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 b7d28f3..82cd822 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 @@ -6,10 +6,10 @@ import com.smunity.petition.domain.question.service.QuestionService; import com.smunity.petition.global.common.ApiResponse; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.*; -import java.util.List; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/questions") @@ -17,10 +17,11 @@ public class QuestionController { private final QuestionService questionService; @GetMapping - public ApiResponse> list() { - return ApiResponse.onSuccess(questionService.getQuestion()); + public ApiResponse> list(Pageable pageable) { + return ApiResponse.onSuccess(questionService.getQuestion(pageable)); } + @GetMapping("/{id}") public ApiResponse read(@PathVariable Long id) { return ApiResponse.onSuccess(questionService.getQuestionById(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 3bf0813..d78f7b2 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 @@ -10,11 +10,11 @@ import com.smunity.petition.global.common.code.status.ErrorCode; import com.smunity.petition.global.common.exception.GeneralException; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -22,9 +22,9 @@ public class QuestionService { private final QuestionRepository questionRepository; private final UserRepository userRepository; - public List getQuestion() { - List questions = questionRepository.findAll(); - return QuestionListDto.from(questions); + public Page getQuestion(Pageable pageable) { + Page questions = questionRepository.findAll(pageable); + return questions.map(QuestionListDto::from); }