diff --git a/spring/src/main/java/com/bancow/bancowback/domain/main/qna/controller/QnaController.java b/spring/src/main/java/com/bancow/bancowback/domain/main/qna/controller/QnaController.java index f41ec1b1..37df836e 100644 --- a/spring/src/main/java/com/bancow/bancowback/domain/main/qna/controller/QnaController.java +++ b/spring/src/main/java/com/bancow/bancowback/domain/main/qna/controller/QnaController.java @@ -18,6 +18,7 @@ import com.bancow.bancowback.domain.common.dto.ServiceResult; import com.bancow.bancowback.domain.main.qna.dto.QnaReplyDto; import com.bancow.bancowback.domain.main.qna.dto.QnaRequestDto; +import com.bancow.bancowback.domain.main.qna.dto.QnaResponseDto; import com.bancow.bancowback.domain.main.qna.entity.Qna; import com.bancow.bancowback.domain.main.qna.service.QnaService; @@ -31,14 +32,14 @@ public class QnaController { private final QnaService qnaService; @GetMapping("/{id}") - public Response getQna(@PathVariable Long id, @RequestHeader("TOKEN") String token) { - Qna qna = qnaService.getQna(token, id); - return new Response<>(qna, HttpStatus.OK); + public Response getQna(@PathVariable Long id, @RequestHeader("TOKEN") String token) { + QnaResponseDto dto = qnaService.getQna(token, id); + return new Response<>(dto, HttpStatus.OK); } @GetMapping - public Response> getQnaPaging(@RequestParam int page, @RequestHeader("TOKEN") String token) { - Page pagingQna = qnaService.getQnaPaging(page, token); + public Response> getQnaPaging(@RequestParam int page, @RequestHeader("TOKEN") String token) { + Page pagingQna = qnaService.getQnaPaging(page, token); return new Response<>(pagingQna, HttpStatus.OK); } @@ -49,8 +50,8 @@ public Response deleteQna(@PathVariable Long id, @RequestHeader("TOKEN") Stri } @PostMapping("/add") - public Response addQna(@RequestBody @Valid QnaRequestDto qnaRequestDto) { - Qna result = qnaService.addQna(qnaRequestDto); + public Response addQna(@RequestBody @Valid QnaRequestDto qnaRequestDto) { + ServiceResult result = qnaService.addQna(qnaRequestDto); return new Response<>(result, HttpStatus.OK); } diff --git a/spring/src/main/java/com/bancow/bancowback/domain/main/qna/service/QnaService.java b/spring/src/main/java/com/bancow/bancowback/domain/main/qna/service/QnaService.java index 01ba4ac9..cfe4fbfb 100644 --- a/spring/src/main/java/com/bancow/bancowback/domain/main/qna/service/QnaService.java +++ b/spring/src/main/java/com/bancow/bancowback/domain/main/qna/service/QnaService.java @@ -16,6 +16,7 @@ import com.bancow.bancowback.domain.common.util.token.service.TokenService; import com.bancow.bancowback.domain.main.qna.dto.QnaReplyDto; import com.bancow.bancowback.domain.main.qna.dto.QnaRequestDto; +import com.bancow.bancowback.domain.main.qna.dto.QnaResponseDto; import com.bancow.bancowback.domain.main.qna.entity.Qna; import com.bancow.bancowback.domain.main.qna.entity.QnaReply; import com.bancow.bancowback.domain.main.qna.mapper.QnaMapper; @@ -36,20 +37,20 @@ public class QnaService { private final QnaReplyRepository qnaReplyRepository; private final QnaReplyMapper qnaReplyMapper; - public Qna getQna(String token, Long qnaId) { + public QnaResponseDto getQna(String token, Long qnaId) { tokenService.validTokenAuthority(token); Qna qna = qnaRepository.findById(qnaId) .orElseThrow(() -> new QnaException(NOT_Found_QNA, "해당 ID의 QnA를 찾을 수 없습니다.")); - - return qnaRepository.save(qna); + return qnaMapper.toResponse(qna); } - public Page getQnaPaging(int page, String token) { + public Page getQnaPaging(int page, String token) { tokenService.validTokenAuthority(token); - return qnaRepository.findAll( + Page qnaList = qnaRepository.findAll( PageRequest.of(page, 10, Sort.by(Sort.Direction.DESC, "id")) ); + return qnaList.map(qnaMapper::toResponse); } public ServiceResult deleteQna(String token, Long id) { @@ -61,9 +62,10 @@ public ServiceResult deleteQna(String token, Long id) { return ServiceResult.success("QnA를 성공적으로 삭제하였습니다."); } - public Qna addQna(QnaRequestDto qnaRequestDto) { + public ServiceResult addQna(QnaRequestDto qnaRequestDto) { Qna qna = qnaMapper.toEntity(qnaRequestDto); - return qnaRepository.save(qna); + qnaRepository.save(qna); + return ServiceResult.success("QnA를 성공적으로 등록하였습니다."); } public ServiceResult replyQna(QnaReplyDto dto, String token, Long id) {