Skip to content

Commit

Permalink
Merge pull request #60 from smu-nity/feat/50
Browse files Browse the repository at this point in the history
✨feat: Question 페이징 적용 (#50)
  • Loading branch information
hyunmin0317 authored Feb 29, 2024
2 parents 3a1f2fe + be77c75 commit 5b47d0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
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")
public class QuestionController {
private final QuestionService questionService;

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


@GetMapping("/{id}")
public ApiResponse<QuestionResponseDto> read(@PathVariable Long id) {
return ApiResponse.onSuccess(questionService.getQuestionById(id));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
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)
public class QuestionService {
private final QuestionRepository questionRepository;
private final UserRepository userRepository;

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


Expand Down

0 comments on commit 5b47d0d

Please sign in to comment.