feat: qna 페이지네이션 수정
This commit is contained in:
parent
d539bc39e7
commit
064881b851
@ -144,16 +144,14 @@ public class QnaController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/all/{id}")
|
@GetMapping("/all/{id}")
|
||||||
public ResponseEntity<List<QnaResponseDto>> getAllQna(@PathVariable Long id) {
|
public ResponseEntity<List<QnaResponseDto>> getAllQna(
|
||||||
|
@PathVariable Long id,
|
||||||
|
@RequestParam(defaultValue = "0") int page) {
|
||||||
try {
|
try {
|
||||||
|
List<QnaResponseDto> qnaList = qnaService.getAllQnasByLecture(id, page, PAGE_SIZE);
|
||||||
|
|
||||||
List<QnaResponseDto> qnaList = qnaService.getAllQnasByLecture(id, PAGE_SIZE);
|
|
||||||
|
|
||||||
return new ResponseEntity<>(qnaList, HttpStatus.ACCEPTED);
|
return new ResponseEntity<>(qnaList, HttpStatus.ACCEPTED);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public interface QnaService {
|
|||||||
|
|
||||||
QnaResponseDto getQna(Long id, Long userId) throws SQLException;
|
QnaResponseDto getQna(Long id, Long userId) throws SQLException;
|
||||||
|
|
||||||
List<QnaResponseDto> getAllQnasByLecture(Long lectureId, int pageNumber) throws SQLException;
|
List<QnaResponseDto> getAllQnasByLecture(Long lectureId, int page, int pageNumber) throws SQLException;
|
||||||
|
|
||||||
QnaResponseDto createAnswer(Long id, QnaRequestDto qnaRequestDto) throws SQLException;
|
QnaResponseDto createAnswer(Long id, QnaRequestDto qnaRequestDto) throws SQLException;
|
||||||
|
|
||||||
|
@ -120,19 +120,16 @@ public class QnaServiceImpl implements QnaService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<QnaResponseDto> getAllQnasByLecture(Long lectureId, int pageSize) {
|
public List<QnaResponseDto> getAllQnasByLecture(Long lectureId, int page, int pageSize) {
|
||||||
|
Pageable pageable = PageRequest.of(page, pageSize);
|
||||||
Pageable pageable = PageRequest.of(0, pageSize);
|
|
||||||
|
|
||||||
Page<Qna> qnaPage = qnaRepository.findByLectureId(lectureId, pageable);
|
Page<Qna> qnaPage = qnaRepository.findByLectureId(lectureId, pageable);
|
||||||
|
|
||||||
|
|
||||||
return qnaPage.getContent().stream()
|
return qnaPage.getContent().stream()
|
||||||
.map(QnaResponseDto::toEntity)
|
.map(QnaResponseDto::toEntity)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public QnaResponseDto createAnswer(Long id, QnaRequestDto qnaRequestDto) throws SQLException {
|
public QnaResponseDto createAnswer(Long id, QnaRequestDto qnaRequestDto) throws SQLException {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user