Search in sources :

Example 1 with BoardNotFoundException

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;
}
Also used : BoardCommentEntity(com.varsql.web.model.entity.board.BoardCommentEntity) BoardPermissionException(com.varsql.web.exception.BoardPermissionException) BoardFileEntity(com.varsql.web.model.entity.board.BoardFileEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) ArrayList(java.util.ArrayList) BoardNotFoundException(com.varsql.web.exception.BoardNotFoundException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with BoardNotFoundException

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;
}
Also used : BoardResponseDTO(com.varsql.web.dto.board.BoardResponseDTO) BoardEntity(com.varsql.web.model.entity.board.BoardEntity) BoardNotFoundException(com.varsql.web.exception.BoardNotFoundException)

Aggregations

BoardNotFoundException (com.varsql.web.exception.BoardNotFoundException)2 BoardResponseDTO (com.varsql.web.dto.board.BoardResponseDTO)1 BoardPermissionException (com.varsql.web.exception.BoardPermissionException)1 BoardCommentEntity (com.varsql.web.model.entity.board.BoardCommentEntity)1 BoardEntity (com.varsql.web.model.entity.board.BoardEntity)1 BoardFileEntity (com.varsql.web.model.entity.board.BoardFileEntity)1 ResponseResult (com.vartech.common.app.beans.ResponseResult)1 ArrayList (java.util.ArrayList)1 Transactional (org.springframework.transaction.annotation.Transactional)1