package kr.wisestone.owl.web.controller; import kr.wisestone.owl.constant.Constants; import kr.wisestone.owl.service.AttachedFileService; import kr.wisestone.owl.util.ConvertUtil; import kr.wisestone.owl.vo.AttachedFileVo; import kr.wisestone.owl.web.condition.AttachedFileCondition; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import java.util.HashMap; import java.util.Map; @Controller public class AttatchedFileController extends BaseController { @Autowired private AttachedFileService attachedFileService; // 파일 등록 @RequestMapping(value = "/attached/add", method = RequestMethod.POST) public @ResponseBody Map add(MultipartHttpServletRequest request) { Map resJsonData = new HashMap<>(); Map content = ConvertUtil.convertJsonToMap(request.getParameter(Constants.REQ_KEY_CONTENT)); resJsonData.put("attachedFiles", ConvertUtil.convertObjectsToClasses(this.attachedFileService.addAttachedFile(request.getFiles("file"), content), AttachedFileVo.class)); return this.setSuccessMessage(resJsonData); } // 파일 조회 @RequestMapping(value = "/attached/find", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody Map find(@RequestBody Map> params) { Map resJsonData = new HashMap<>(); this.attachedFileService.findAttachedFile(resJsonData, AttachedFileCondition.make(params.get(Constants.REQ_KEY_CONTENT))); return this.setSuccessMessage(resJsonData); } // 파일 다운로드 @RequestMapping(value = "/attached/download", method = {RequestMethod.GET, RequestMethod.POST}) public ModelAndView downloadFile(@RequestParam(value="id") Long id, Model model) { return this.attachedFileService.checkUseWorkspaceTraffic(id, model); } }