use of com.varsql.web.exception.BoardNotFoundException in project varsql by varsqlinfo.
the class BoardService method commentSave.
/**
* @Method Name : commentSave
* @Method 설명 : 코멘트 저장.
* @작성자 : ytkim
* @작성일 : 2021. 7. 8.
* @변경이력 :
* @param articleId
* @param boardCommentRequestDTO
* @return
*/
@Transactional(transactionManager = ResourceConfigConstants.APP_TRANSMANAGER, rollbackFor = Throwable.class)
public ResponseResult commentSave(long articleId, BoardCommentRequestDTO boardCommentRequestDTO) {
BoardCommentEntity boardCommentEntity;
boolean isNew = NumberUtils.isNullOrZero(boardCommentRequestDTO.getCommentId());
boolean isReComment = false;
if (isNew) {
boardCommentEntity = boardCommentRequestDTO.toEntity();
boardCommentEntity.setArticleId(articleId);
boardCommentEntity.setAuthorName(SecurityUtil.loginInfo().getFullname());
boardCommentEntity.setFileList(new ArrayList<BoardFileEntity>());
// 대댓글
isReComment = !NumberUtils.isNullOrZero(boardCommentRequestDTO.getParentCommentId());
if (isReComment) {
BoardCommentEntity parentBoardCommentEntity = boardCommentEntityRepository.findByArticleIdAndCommentId(articleId, boardCommentRequestDTO.getParentCommentId());
if (parentBoardCommentEntity == null) {
throw new BoardNotFoundException("parent comments not found : " + boardCommentRequestDTO.getParentCommentId());
}
boardCommentEntity.setIndent(parentBoardCommentEntity.getIndent() + 1);
boardCommentEntity.setGrpCommentId(parentBoardCommentEntity.getGrpCommentId());
boardCommentEntity.setGrpSeq(boardCommentEntityRepository.findByGrpSeqMaxQuery(parentBoardCommentEntity.getGrpCommentId()));
} else {
}
} else {
boardCommentEntity = boardCommentEntityRepository.findByArticleIdAndCommentId(articleId, boardCommentRequestDTO.getCommentId());
if (!isCommentModify(boardCommentEntity)) {
throw new BoardPermissionException("no permission");
}
boardCommentEntity.setContents(boardCommentRequestDTO.getContents());
String fileIds = boardCommentRequestDTO.getRemoveFileIds();
if (!StringUtils.isBlank(fileIds)) {
boardFileEntityRepository.deleteByIdInQuery(Arrays.asList(fileIds.split(",")).stream().map(item -> {
return Long.parseLong(item);
}).collect(Collectors.toList()));
}
}
if (boardCommentRequestDTO.getFile().size() > 0) {
List<BoardFileEntity> boardFileList = boardCommentEntity.getFileList();
fileUploadService.uploadFiles(UploadFileType.BOARD, boardCommentRequestDTO.getFile(), boardCommentRequestDTO.getCommentId() + "", boardCommentRequestDTO.getBoardCode(), "file", false, false).forEach(item -> {
BoardFileEntity entity = BoardFileEntity.toBoardFileEntity(item);
entity.setComment(boardCommentEntity);
entity.setContType(COMMENT_CONT_TYPE);
boardFileList.add(entity);
});
boardCommentEntity.setFileList(boardFileList);
}
BoardCommentEntity saveEntity = boardCommentEntityRepository.save(boardCommentEntity);
if (isNew) {
if (!isReComment) {
saveEntity.setGrpCommentId(saveEntity.getCommentId());
boardCommentEntityRepository.save(saveEntity);
} else {
boardCommentEntityRepository.updateGrpSeqQuery(saveEntity.getArticleId(), saveEntity.getGrpCommentId(), saveEntity.getCommentId(), saveEntity.getGrpSeq());
}
}
ResponseResult result = VarsqlUtils.getResponseResultItemList(new ArrayList());
result.setItemOne(1);
return result;
}
use of com.varsql.web.exception.BoardNotFoundException in project varsql by varsqlinfo.
the class BoardService method viewBoardInfo.
/**
* @Method Name : viewBoardInfo
* @Method 설명 : 글 상세보기.
* @작성자 : ytkim
* @작성일 : 2021. 7. 8.
* @변경이력 :
* @param boardCode
* @param articleId
* @return
*/
public BoardResponseDTO viewBoardInfo(String boardCode, long articleId) {
BoardEntity boardEntity = boardEntityRepository.findByArticleId(articleId);
if (boardEntity == null) {
throw new BoardNotFoundException("article id not found : " + articleId);
}
BoardResponseDTO dto = BoardResponseDTO.toDto(boardEntity, true);
dto.setModifyAuth(isModify(boardEntity));
return dto;
}
Aggregations