feat: qna 조회 수정

This commit is contained in:
박정민 2024-07-26 16:03:30 +09:00
parent c99d3cc7ec
commit 9c2abc6d6d
4 changed files with 19 additions and 6 deletions

View File

@ -106,9 +106,9 @@ public class QnaController {
}
@GetMapping("/{id}")
public ResponseEntity<Qna> getQna(@PathVariable Long id) {
public ResponseEntity<QnaResponseDto> getQna(@PathVariable Long id) {
try{
Qna findQna= qnaService.getQna(id);
QnaResponseDto findQna= qnaService.getQna(id);
return new ResponseEntity<>(findQna, HttpStatus.ACCEPTED);
} catch (SQLException e) {

View File

@ -13,7 +13,6 @@ import java.util.List;
@Repository
public interface QnaRepository extends JpaRepository<Qna, Long> {
List<Qna> findByLectureId(Long lecturerId);
Page<Qna> findByLectureId(Long lectureId, Pageable pageable);
}

View File

@ -16,7 +16,7 @@ public interface QnaService {
QnaResponseDto createQna(Long id, QnaRequestDto qnaRequestDto, Long lecture_id) throws SQLException;
QnaResponseDto updateQna(Long id,QnaRequestDto qnaRequestDto) throws SQLException;
void deleteQna(Long id) throws SQLException;
Qna getQna(Long id) throws SQLException;
QnaResponseDto getQna(Long id) throws SQLException;
List<QnaResponseDto> getAllQnasByLecture(Long lectureId,int pageNumber) throws SQLException;
QnaResponseDto createAnswer(Long id,QnaRequestDto qnaRequestDto) throws SQLException;

View File

@ -80,8 +80,22 @@ qnaRepository.deleteById(id);
}
@Override
public Qna getQna(Long id) {
return null;
public QnaResponseDto getQna(Long id) {
Optional<Qna> qna;
try {
qna= qnaRepository.findById(id);
} catch (Exception e) {
throw new RuntimeException("Qna 없음 " + id, e);
}
return QnaResponseDto.toEntity(qna.get());
}
@Override