|
|
@@ -1,5 +1,6 @@
|
|
|
package com.example.ili_web.board.service;
|
|
|
|
|
|
+import com.example.ili_web.board.domain.Board;
|
|
|
import com.example.ili_web.board.dto.*;
|
|
|
import com.example.ili_web.board.repository.BoardRepository;
|
|
|
import com.example.ili_web.board.repository.BoardRepositoryDsl;
|
|
|
@@ -9,11 +10,20 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
import org.springframework.web.reactive.function.client.WebClient;
|
|
|
import reactor.netty.http.client.HttpClient;
|
|
|
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import static java.net.http.HttpClient.*;
|
|
|
|
|
|
@Service
|
|
|
@@ -22,6 +32,10 @@ import static java.net.http.HttpClient.*;
|
|
|
public class BoardService {
|
|
|
private final BoardRepository repository;
|
|
|
private final BoardRepositoryDsl boardDsl;
|
|
|
+ @Value("${multipart.file.storage.win}")
|
|
|
+ private String fileStorageWindow;
|
|
|
+ @Value("${multipart.file.storage.linux}")
|
|
|
+ private String fileStorageLinux;
|
|
|
@Value("${global.message.sms.address}")
|
|
|
private String address;
|
|
|
@Value("${global.message.sms.url}")
|
|
|
@@ -82,4 +96,39 @@ public class BoardService {
|
|
|
public CheckDupleRes checkNickName(BoardInfoReq req) {
|
|
|
return new CheckDupleRes(repository.countBoardsByNickName(req.getNickname()));
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public void insertBoard(BoardInfoReq req, List<MultipartFile> file) throws IOException {
|
|
|
+ Board board = new Board(req);
|
|
|
+ repository.save(board);
|
|
|
+ String osPath = osProperty();
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ String filePath = osPath + "/" + req.getType() + "/Board" + board.getId()+"/";
|
|
|
+ fileUpload(filePath, file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String osProperty() {
|
|
|
+ String os = System.getProperty("os.name").toLowerCase();
|
|
|
+ String result;
|
|
|
+ if (os.contains("win")) {
|
|
|
+ result = fileStorageWindow;
|
|
|
+ } else {
|
|
|
+ result = fileStorageLinux;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void fileUpload(String path, List<MultipartFile> files) throws IOException {
|
|
|
+ File dir = new File(path);
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ byte[] bytes = file.getBytes();
|
|
|
+ Path realPath = Paths.get(path + file.getOriginalFilename());
|
|
|
+ Files.createDirectories(realPath.getParent());
|
|
|
+ Files.write(realPath, bytes);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|