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 37df836e..eab88ace 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 @@ -16,10 +16,10 @@ import com.bancow.bancowback.domain.common.dto.Response; import com.bancow.bancowback.domain.common.dto.ServiceResult; +import com.bancow.bancowback.domain.main.qna.dto.QnaDeleteRequestDto; 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; import lombok.RequiredArgsConstructor; @@ -49,6 +49,13 @@ public Response deleteQna(@PathVariable Long id, @RequestHeader("TOKEN") Stri return new Response<>(result, HttpStatus.OK); } + @DeleteMapping("/delete") + public Response deleteQnaList(@RequestHeader("TOKEN") String token, + @RequestBody @Valid QnaDeleteRequestDto dto) { + ServiceResult result = qnaService.deleteQnaList(token, dto); + return new Response<>(result, HttpStatus.OK); + } + @PostMapping("/add") public Response addQna(@RequestBody @Valid QnaRequestDto qnaRequestDto) { ServiceResult result = qnaService.addQna(qnaRequestDto); 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 5bb1b94f..b962e31b 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 @@ -14,6 +14,7 @@ import com.bancow.bancowback.domain.common.exception.QnaException; import com.bancow.bancowback.domain.common.util.mail.service.MailService; import com.bancow.bancowback.domain.common.util.token.service.TokenService; +import com.bancow.bancowback.domain.main.qna.dto.QnaDeleteRequestDto; 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; @@ -62,6 +63,16 @@ public ServiceResult deleteQna(String token, Long id) { return ServiceResult.success("QnA를 성공적으로 삭제하였습니다."); } + public ServiceResult deleteQnaList(String token, QnaDeleteRequestDto dto) { + tokenService.validTokenAuthority(token); + List deleteList = qnaRepository.findByIdIn(dto.getId()); + if (deleteList.size() == 0) { + throw new QnaException(NOT_Found_QNA, "해당 ID의 QnA를 찾을 수 없습니다."); + } + deleteList.forEach(qnaRepository::delete); + return ServiceResult.success("해당 문의를 성공적으로 삭제하였습니다."); + } + public ServiceResult addQna(QnaRequestDto qnaRequestDto) { Qna qna = qnaMapper.toEntity(qnaRequestDto); qnaRepository.save(qna); @@ -92,4 +103,5 @@ public Integer uncheckedQna() { public List> countMonth(int year) { return qnaRepository.countMonth(year); } + }