Search in sources :

Example 6 with NodePtrDTO

use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.

the class RestController method destroy.

/**
 * 게시물 삭제시 호출되는 함수입니다.
 * @param board_id 삭제를 원하는 게시물의 board_id
 * @param version 삭제를 원하는 게시물의 version
 */
@RequestMapping(value = "/boards/{board_id}/{version}", method = RequestMethod.DELETE)
@ResponseBody
public Map<String, Object> destroy(@PathVariable(value = "board_id") int board_id, @PathVariable(value = "version") int version) throws Exception {
    Map<String, Object> resultMap = new HashMap<>();
    try {
        NodePtrDTO leapPtrDTO = new NodePtrDTO(board_id, version);
        versionManagementService.deleteArticle(leapPtrDTO);
        resultMap.put("result", "success");
    } catch (Exception e) {
        resultMap.put("result", e.getMessage());
    }
    return resultMap;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) HashMap(java.util.HashMap) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with NodePtrDTO

use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.

the class RestController method history.

/**
 * 이력 상세보기 입니다.
 * @param board_id 상세 조회 할 게시물의 board_id
 * @param version 상세 조회 할 게시물의 version
 * @return modelAndView 이력의 상세 내용, board-boardHistory 구분자 , file 데이터 , viewName을 리턴합니다.
 */
@RequestMapping(value = "/history/{board_id}/{version}", method = RequestMethod.GET)
@ResponseBody
public ModelAndView history(@PathVariable(value = "board_id") int board_id, @PathVariable(value = "version") int version) {
    NodePtrDTO node = new NodePtrDTO(board_id, version);
    BoardHistoryDTO boardHistory = boardHistoryMapper.getHistory(node);
    BoardDTO board = new BoardDTO(boardHistory);
    FileDTO file = fileMapper.getFile(board.getFile_id());
    String deCompreesedContent = "";
    try {
        deCompreesedContent = Compress.deCompress(boardHistory.getHistory_content());
    } catch (IOException e) {
        e.printStackTrace();
        deCompreesedContent = "압축 해제 실패";
        throw new RuntimeException(e);
    }
    board.setContent(deCompreesedContent);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("board", board);
    modelAndView.addObject("isHistory", 1);
    modelAndView.addObject("file", file);
    modelAndView.setViewName("boardDetail");
    return modelAndView;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) FileDTO(com.worksmobile.Assignment.Domain.FileDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) ModelAndView(org.springframework.web.servlet.ModelAndView) IOException(java.io.IOException) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 8 with NodePtrDTO

use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.

the class RestController method updateWithoutAttachment.

/**
 * 게시물에 첨부파일을 유지하고 싶은 경우를 제외하고는 글수정 데이터를 받아 DB에 등록합니다.
 * @param board 사용자가 수정한 board 데이터를 받습니다.
 * @param attachment 첨부파일 데이터를 받습니다.
 */
@RequestMapping(value = "/boards/update2", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateWithoutAttachment(BoardDTO board, MultipartHttpServletRequest attachment) {
    Map<String, Object> resultMap = new HashMap<>();
    MultipartFile mFile = null;
    Iterator<String> iter = attachment.getFileNames();
    while (iter.hasNext()) {
        String uploadFile_name = iter.next();
        mFile = attachment.getFile(uploadFile_name);
    }
    try {
        if (mFile != null) {
            if (!mFile.getOriginalFilename().equals("")) {
                FileDTO file = new FileDTO();
                file.setFile_name(mFile.getOriginalFilename());
                file.setFile_data(mFile.getBytes());
                file.setFile_size(mFile.getSize());
                fileMapper.createFile(file);
                board.setFile_id(file.getFile_id());
            }
        }
        NodePtrDTO leapPtrDTO = new NodePtrDTO(board.getBoard_id(), board.getVersion());
        NodePtrDTO newNode = versionManagementService.modifyVersion(board, leapPtrDTO);
        if (newNode == null) {
            resultMap.put("result", "수정 실패");
        } else {
            resultMap.put("result", "success");
        }
    } catch (Exception e) {
        resultMap.put("result", e.getMessage());
        e.printStackTrace();
        return resultMap;
    }
    return resultMap;
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) MultipartFile(org.springframework.web.multipart.MultipartFile) FileDTO(com.worksmobile.Assignment.Domain.FileDTO) HashMap(java.util.HashMap) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with NodePtrDTO

use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.

the class VersionManagementTest method testRecoverVersion.

@Test
public void testRecoverVersion() throws InterruptedException, ExecutionException, JsonProcessingException {
    BoardHistoryDTO createdHistoryDTO = versionManagementService.createArticle(defaultBoardDTO);
    NodePtrDTO prevPtrDTO = createdHistoryDTO;
    BoardDTO prevLeapDTO = boardMapper.viewDetail(prevPtrDTO.toMap());
    NodePtrDTO newLeapPtrDTO = versionManagementService.recoverVersion(prevPtrDTO, prevPtrDTO);
    BoardHistoryDTO recoveredHistoryDTO = boardHistoryMapper.getHistory(newLeapPtrDTO);
    BoardDTO newLeapDTO = boardMapper.viewDetail(newLeapPtrDTO.toMap());
    prevLeapDTO.setNodePtrDTO(newLeapPtrDTO);
    assertNotNull(recoveredHistoryDTO);
    Utils.assertConvertToJsonObject(newLeapDTO, prevLeapDTO);
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) BoardDTO(com.worksmobile.Assignment.Domain.BoardDTO) BoardHistoryDTO(com.worksmobile.Assignment.Domain.BoardHistoryDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with NodePtrDTO

use of com.worksmobile.Assignment.Domain.NodePtrDTO in project Assignment by WMPeople.

the class VersionManagementTest method testDeleteRootNode.

@Test
public void testDeleteRootNode() throws JsonProcessingException {
    NodePtrDTO child = makeChild(defaultCreatedDTO);
    assertNotNull(child);
    NodePtrDTO newLeafNodePtr = versionManagementService.deleteVersion(defaultCreatedDTO);
    assertNull(newLeafNodePtr);
}
Also used : NodePtrDTO(com.worksmobile.Assignment.Domain.NodePtrDTO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

NodePtrDTO (com.worksmobile.Assignment.Domain.NodePtrDTO)29 BoardHistoryDTO (com.worksmobile.Assignment.Domain.BoardHistoryDTO)16 Test (org.junit.Test)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 BoardDTO (com.worksmobile.Assignment.Domain.BoardDTO)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 ModelAndView (org.springframework.web.servlet.ModelAndView)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 FileDTO (com.worksmobile.Assignment.Domain.FileDTO)2 Transactional (org.springframework.transaction.annotation.Transactional)2 MultipartFile (org.springframework.web.multipart.MultipartFile)1