Skip to content

Commit

Permalink
add deleteQnaList in Qna Service in Controller [#337]
Browse files Browse the repository at this point in the history
  • Loading branch information
kho903 committed Feb 13, 2022
1 parent 66291e7 commit 2ce62e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ServiceResult> addQna(@RequestBody @Valid QnaRequestDto qnaRequestDto) {
ServiceResult result = qnaService.addQna(qnaRequestDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Qna> 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);
Expand Down Expand Up @@ -92,4 +103,5 @@ public Integer uncheckedQna() {
public List<Map<String, Object>> countMonth(int year) {
return qnaRepository.countMonth(year);
}

}

0 comments on commit 2ce62e8

Please sign in to comment.