Skip to content

Commit

Permalink
✨ feature: Question 페이징 적용 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ohwooseok committed Mar 4, 2024
1 parent 5b47d0d commit a0788a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,11 +18,15 @@
public class QuestionController {
private final QuestionService questionService;

@GetMapping
/* @GetMapping
public ApiResponse<Page<QuestionListDto>> list(Pageable pageable) {
return ApiResponse.onSuccess(questionService.getQuestion(pageable));
}

*/
@GetMapping
public ApiResponse<Page<QuestionListDto>> list(@PageableDefault Pageable pageable){
return ApiResponse.onSuccess(questionService.getQuestion(pageable));
}

@GetMapping("/{id}")
public ApiResponse<QuestionResponseDto> read(@PathVariable Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ public class QuestionService {
private final QuestionRepository questionRepository;
private final UserRepository userRepository;

public Page<QuestionListDto> getQuestion(Pageable pageable) {
/*public Page<QuestionListDto> getQuestion(Pageable pageable) {
Page<Question> questions = questionRepository.findAll(pageable);
return questions.map(QuestionListDto::from);
}*/

public Page<QuestionListDto> getQuestion(Pageable pageable){
Page<Question> 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));
Expand Down

0 comments on commit a0788a7

Please sign in to comment.