게시물 작성 기능 작업중.
parent
5134bcbe13
commit
326932d08f
|
|
@ -2,6 +2,7 @@ package com.dbnt.kcgfilemanager.controller;
|
||||||
|
|
||||||
import com.dbnt.kcgfilemanager.model.Board;
|
import com.dbnt.kcgfilemanager.model.Board;
|
||||||
import com.dbnt.kcgfilemanager.model.UserInfo;
|
import com.dbnt.kcgfilemanager.model.UserInfo;
|
||||||
|
import com.dbnt.kcgfilemanager.service.BoardService;
|
||||||
import com.dbnt.kcgfilemanager.service.UserInfoService;
|
import com.dbnt.kcgfilemanager.service.UserInfoService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
|
@ -19,14 +20,7 @@ import java.util.List;
|
||||||
@RequestMapping("/board")
|
@RequestMapping("/board")
|
||||||
public class BoardController {
|
public class BoardController {
|
||||||
|
|
||||||
// private final UserInfoService userInfoService;
|
private final BoardService boardService;
|
||||||
|
|
||||||
// @GetMapping("/user/login")
|
|
||||||
// public ModelAndView goLogin() {
|
|
||||||
// ModelAndView mav = new ModelAndView("login");
|
|
||||||
// return mav;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/contentWrite")
|
@GetMapping("/contentWrite")
|
||||||
public ModelAndView contentWrite(Principal principal) {
|
public ModelAndView contentWrite(Principal principal) {
|
||||||
|
|
@ -38,12 +32,8 @@ public class BoardController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/saveContent")
|
@PostMapping("/saveContent")
|
||||||
public Integer saveContent(Board board){
|
public Integer saveContent(Board content, MultipartHttpServletRequest request){
|
||||||
System.out.println("controller coming");
|
content.setFileList(request.getMultiFileMap().get("uploadFiles"));
|
||||||
return board.getContentSeq();
|
return boardService.saveContent(content);
|
||||||
}
|
|
||||||
@PostMapping("/uploadFiles")
|
|
||||||
public void uploadFiles(Integer contentSeq, MultipartHttpServletRequest request){
|
|
||||||
System.out.println("controller coming");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import org.hibernate.annotations.DynamicInsert;
|
import org.hibernate.annotations.DynamicInsert;
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
@ -40,6 +41,9 @@ public class Board extends BaseModel{
|
||||||
private List<FileInfo> childFiles;
|
private List<FileInfo> childFiles;
|
||||||
@Transient
|
@Transient
|
||||||
private List<HashTagLink> hashTags;
|
private List<HashTagLink> hashTags;
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
private String hashTagStr;
|
private String hashTagStr;
|
||||||
|
@Transient
|
||||||
|
private List<MultipartFile> fileList;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.dbnt.kcgfilemanager.repository;
|
||||||
|
|
||||||
|
import com.dbnt.kcgfilemanager.model.BoardLog;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface BoardLogRepository extends JpaRepository<BoardLog, BoardLog.BoardLogId> {
|
||||||
|
Optional<BoardLog> findTopByContentSeqOrderByLogSeqDesc(Integer contentSeq);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.dbnt.kcgfilemanager.repository;
|
||||||
|
|
||||||
|
import com.dbnt.kcgfilemanager.model.Board;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface BoardRepository extends JpaRepository<Board, Integer> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.dbnt.kcgfilemanager.repository;
|
||||||
|
|
||||||
|
import com.dbnt.kcgfilemanager.model.FileInfo;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface FileInfoRepository extends JpaRepository<FileInfo, FileInfo.FileInfoId> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.dbnt.kcgfilemanager.repository;
|
||||||
|
|
||||||
|
import com.dbnt.kcgfilemanager.model.HashTagLink;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface HashTagLinkRepository extends JpaRepository<HashTagLink, HashTagLink.HashTagLinkId> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.dbnt.kcgfilemanager.repository;
|
||||||
|
|
||||||
|
import com.dbnt.kcgfilemanager.model.HashTag;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface HashTagRepository extends JpaRepository<HashTag, Integer> {
|
||||||
|
Optional<HashTag> findByTagName(String tagName);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
package com.dbnt.kcgfilemanager.service;
|
||||||
|
|
||||||
|
import com.dbnt.kcgfilemanager.model.Board;
|
||||||
|
import com.dbnt.kcgfilemanager.model.BoardLog;
|
||||||
|
import com.dbnt.kcgfilemanager.model.HashTag;
|
||||||
|
import com.dbnt.kcgfilemanager.model.HashTagLink;
|
||||||
|
import com.dbnt.kcgfilemanager.repository.BoardLogRepository;
|
||||||
|
import com.dbnt.kcgfilemanager.repository.BoardRepository;
|
||||||
|
import com.dbnt.kcgfilemanager.repository.HashTagLinkRepository;
|
||||||
|
import com.dbnt.kcgfilemanager.repository.HashTagRepository;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class BoardService {
|
||||||
|
|
||||||
|
private BoardRepository boardRepository;
|
||||||
|
private BoardLogRepository boardLogRepository;
|
||||||
|
private HashTagRepository hashTagRepository;
|
||||||
|
private HashTagLinkRepository hashTagLinkRepository;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Integer saveContent(Board content){
|
||||||
|
boardRepository.save(content);
|
||||||
|
saveBoardLog(content.getContentSeq(), "I", null, content.getCreateId());
|
||||||
|
saveHashTagLink(content.getContentSeq(), content.getHashTagStr());
|
||||||
|
saveUploadFiles(content.getContentSeq(), content.getFileList());
|
||||||
|
return content.getContentSeq();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveBoardLog(Integer contentSeq, String status, String description, String createId){
|
||||||
|
BoardLog lastLog = boardLogRepository.findTopByContentSeqOrderByLogSeqDesc(contentSeq).orElse(null);
|
||||||
|
BoardLog log = new BoardLog();
|
||||||
|
log.setContentSeq(contentSeq);
|
||||||
|
log.setLogSeq(lastLog == null?1:(lastLog.getLogSeq()+1));
|
||||||
|
log.setLogStatus(status);
|
||||||
|
log.setDescription(description);
|
||||||
|
log.setCreateId(createId);
|
||||||
|
boardLogRepository.save(log);
|
||||||
|
}
|
||||||
|
public HashTag saveHashTag(String tagName){
|
||||||
|
HashTag tag = new HashTag();
|
||||||
|
tag.setTagName(tagName);
|
||||||
|
return hashTagRepository.save(tag);
|
||||||
|
}
|
||||||
|
public void saveHashTagLink(Integer contentSeq, String hashTagStr){
|
||||||
|
String[] hashTagAry = hashTagStr.trim().replaceAll(",", "").split("#");
|
||||||
|
for(String tagName : hashTagAry){
|
||||||
|
HashTag tag = hashTagRepository.findByTagName(tagName).orElse(null);
|
||||||
|
if(tag==null){
|
||||||
|
tag = saveHashTag(tagName);
|
||||||
|
}
|
||||||
|
HashTagLink link = new HashTagLink();
|
||||||
|
link.setContentSeq(contentSeq);
|
||||||
|
link.setTagSeq(tag.getTagSeq());
|
||||||
|
hashTagLinkRepository.save(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void saveUploadFiles(Integer contentSeq, List<MultipartFile> files){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -50,6 +50,10 @@ $(document).on('click', '.fileDelete', function (){
|
||||||
})
|
})
|
||||||
$(document).on('click', '#saveBtn', function (){
|
$(document).on('click', '#saveBtn', function (){
|
||||||
const formData = new FormData($("#contentForm")[0]);
|
const formData = new FormData($("#contentForm")[0]);
|
||||||
|
for(const file of files) {
|
||||||
|
if(!file.isDelete)
|
||||||
|
formData.append('uploadFiles', file, file.name);
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type : 'POST',
|
type : 'POST',
|
||||||
data : formData,
|
data : formData,
|
||||||
|
|
@ -58,7 +62,6 @@ $(document).on('click', '#saveBtn', function (){
|
||||||
contentType: false,
|
contentType: false,
|
||||||
success : function(data) {
|
success : function(data) {
|
||||||
$("#contentSeq").val(data);
|
$("#contentSeq").val(data);
|
||||||
uploadFiles();
|
|
||||||
},
|
},
|
||||||
error : function(xhr, status) {
|
error : function(xhr, status) {
|
||||||
|
|
||||||
|
|
@ -102,24 +105,6 @@ function selectorDisabler(depth){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function uploadFiles(){
|
|
||||||
const formData = new FormData($("#fileForm")[0]);
|
|
||||||
$.ajax({
|
|
||||||
type : 'POST',
|
|
||||||
data : formData,
|
|
||||||
url : "/board/uploadFiles",
|
|
||||||
enctype: "multipart/form-data",
|
|
||||||
processData: false,
|
|
||||||
contentType: false,
|
|
||||||
success : function(data) {
|
|
||||||
alert("저장되었습니다.")
|
|
||||||
},
|
|
||||||
error : function(xhr, status) {
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function setFileDiv(file, idx){
|
function setFileDiv(file, idx){
|
||||||
const uploadDiv = $("#uploadDiv");
|
const uploadDiv = $("#uploadDiv");
|
||||||
if(files.length===1){
|
if(files.length===1){
|
||||||
|
|
|
||||||
|
|
@ -91,12 +91,13 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<label for="files" class="col-sm-2 col-form-label">업로드 자료</label>
|
<label for="fileInputer" class="col-sm-2 col-form-label">업로드 자료</label>
|
||||||
<div class="col-sm-10" style="min-height: 70px;">
|
<div class="col-sm-10" style="min-height: 70px;">
|
||||||
<div class="w-100 h-100 border border-info rounded text-center" id="uploadDiv">
|
<div class="w-100 h-100 border border-info rounded text-center" id="uploadDiv">
|
||||||
<br>파일을 업로드 해주세요.
|
<br>파일을 업로드 해주세요.
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<input type="file" class="d-none" id="fileInputer" multiple>
|
||||||
</div>
|
</div>
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<label for="description" class="col-sm-2 col-form-label">설명</label>
|
<label for="description" class="col-sm-2 col-form-label">설명</label>
|
||||||
|
|
@ -111,10 +112,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<form id="fileForm" class="d-none" th:action="@{/board/uploadFiles}" method="post" enctype="multipart/form-data">
|
|
||||||
<input type="text" id="contentSeq" name="contentSeq">
|
|
||||||
<input type="file" id="fileInputer" name="fileInputer" multiple>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue