diff --git a/src/main/java/com/dailylife/domain/board/controller/BoardController.java b/src/main/java/com/dailylife/domain/board/controller/BoardController.java index 1e4c0d5..7aa350e 100644 --- a/src/main/java/com/dailylife/domain/board/controller/BoardController.java +++ b/src/main/java/com/dailylife/domain/board/controller/BoardController.java @@ -1,6 +1,7 @@ package com.dailylife.domain.board.controller; import com.dailylife.domain.board.dto.BoardCreateRequest; +import com.dailylife.domain.board.dto.BoardCreateResponse; import com.dailylife.domain.board.dto.BoardPagination; import com.dailylife.domain.board.dto.BoardUpdateRequest; import com.dailylife.domain.board.entity.Board; @@ -16,6 +17,7 @@ import javax.validation.Valid; import java.io.IOException; +import java.util.ArrayList; import java.util.List; @RestController @@ -28,7 +30,7 @@ public class BoardController { @ApiOperation(value = "게시물 업로드", notes = "게시물 업로드 완료") @PostMapping("/create") - public ResponseEntity createBoard(@Valid @ModelAttribute BoardCreateRequest boardCreateRequest) throws IOException { + public ResponseEntity createBoard(@Valid @ModelAttribute BoardCreateRequest boardCreateRequest) throws IOException { return ResponseEntity.ok(boardService.create(boardCreateRequest)); } diff --git a/src/main/java/com/dailylife/domain/board/dto/BoardCreateResponse.java b/src/main/java/com/dailylife/domain/board/dto/BoardCreateResponse.java new file mode 100644 index 0000000..b0ca0f3 --- /dev/null +++ b/src/main/java/com/dailylife/domain/board/dto/BoardCreateResponse.java @@ -0,0 +1,29 @@ +package com.dailylife.domain.board.dto; + + +import com.dailylife.domain.board.entity.Board; +import io.swagger.annotations.ApiModel; +import lombok.*; + +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "게시물 작성시 응답 객체 ") +@Builder +public class BoardCreateResponse { + + private String title; + private String content; + private List originalFileName; + + public static BoardCreateResponse from(Board board , List originalFileName) { + return BoardCreateResponse.builder() + .title(board.getTitle()) + .content(board.getContent()) + .originalFileName(originalFileName).build(); + } + +} diff --git a/src/main/java/com/dailylife/domain/board/entity/Board.java b/src/main/java/com/dailylife/domain/board/entity/Board.java index f5f32c8..5f1b844 100644 --- a/src/main/java/com/dailylife/domain/board/entity/Board.java +++ b/src/main/java/com/dailylife/domain/board/entity/Board.java @@ -23,7 +23,6 @@ public class Board { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long boardNum; - private String title; private String content; private String userNickName; diff --git a/src/main/java/com/dailylife/domain/board/service/BoardService.java b/src/main/java/com/dailylife/domain/board/service/BoardService.java index 9a8bcf4..7f2c88c 100644 --- a/src/main/java/com/dailylife/domain/board/service/BoardService.java +++ b/src/main/java/com/dailylife/domain/board/service/BoardService.java @@ -1,9 +1,6 @@ package com.dailylife.domain.board.service; -import com.dailylife.domain.board.dto.BoardCreateRequest; -import com.dailylife.domain.board.dto.BoardDeleteRequest; -import com.dailylife.domain.board.dto.BoardPagination; -import com.dailylife.domain.board.dto.BoardUpdateRequest; +import com.dailylife.domain.board.dto.*; import com.dailylife.domain.board.entity.Board; import java.io.IOException; @@ -11,7 +8,7 @@ public interface BoardService { - Board create(BoardCreateRequest boardCreateRequest) throws IOException; + BoardCreateResponse create(BoardCreateRequest boardCreateRequest) throws IOException; Board update(BoardCreateRequest boardCreateRequest, Long boardNum) throws IOException; diff --git a/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java b/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java index ed6d74b..40b4eae 100644 --- a/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java +++ b/src/main/java/com/dailylife/domain/board/service/BoardServiceImpl.java @@ -1,9 +1,6 @@ package com.dailylife.domain.board.service; -import com.dailylife.domain.board.dto.BoardCreateRequest; -import com.dailylife.domain.board.dto.BoardDeleteRequest; -import com.dailylife.domain.board.dto.BoardPagination; -import com.dailylife.domain.board.dto.BoardUpdateRequest; +import com.dailylife.domain.board.dto.*; import com.dailylife.domain.board.entity.Board; import com.dailylife.domain.board.repository.BoardPaginationRepository; import com.dailylife.domain.board.repository.BoardRepository; @@ -19,9 +16,11 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; import javax.swing.text.html.parser.Entity; import java.io.IOException; +import java.util.ArrayList; import java.util.List; @Slf4j @@ -34,20 +33,24 @@ public class BoardServiceImpl implements BoardService{ private final ImageRepository imageRepository; private final MultiUpload multiUpload; private final ImageRemove imageRemove; - private final BoardPaginationRepository paginationRepository; @Override @Transactional - public Board create(BoardCreateRequest boardCreateRequest) throws IOException { + public BoardCreateResponse create(BoardCreateRequest boardCreateRequest) throws IOException { + List originalFileName = new ArrayList<>(); Board board = boardRepository.save(Board.toEntity(boardCreateRequest, userRepository.findByUserId(jwtService.getLoginId()))); if(boardCreateRequest.getImageName() != null) { - List images = multiUpload.FileUpload(boardCreateRequest.getImageName()); + for (MultipartFile file : boardCreateRequest.getImageName()) { + originalFileName.add(file.getOriginalFilename()); + } + List images = multiUpload.FileUpload(boardCreateRequest.getImageName()); for (String fileName : images) { + imageRepository.save(Image.toEntity(fileName, board)); } } - return board; + return BoardCreateResponse.from(board , originalFileName); } @Override diff --git a/src/main/java/com/dailylife/global/interceptor/JwtInterceptor.java b/src/main/java/com/dailylife/global/interceptor/JwtInterceptor.java index 67b4af3..a3cd991 100644 --- a/src/main/java/com/dailylife/global/interceptor/JwtInterceptor.java +++ b/src/main/java/com/dailylife/global/interceptor/JwtInterceptor.java @@ -16,9 +16,9 @@ public class JwtInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - - System.out.println("request.getRequestURI() => "+ request.getRequestURI()); - + if(request.getMethod().equals("OPTIONS")) { + return true; + } jwtService.getLoginId(); return true; } diff --git a/src/main/java/com/dailylife/global/web/WebConfig.java b/src/main/java/com/dailylife/global/web/WebConfig.java index b181f38..4fb3a70 100644 --- a/src/main/java/com/dailylife/global/web/WebConfig.java +++ b/src/main/java/com/dailylife/global/web/WebConfig.java @@ -52,6 +52,7 @@ public void addInterceptors(InterceptorRegistry registry) { "/api/users/loginTest" ,"/error"); + } @Override diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4536416..e9a947d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,9 +1,9 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/jpashop?useUnicode=yes&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Seoul - username: sa - password: km971gb5!! + url: jdbc:mysql://146.56.39.196:3306/dailylife?useUnicode=yes&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Seoul + username: dailylife + password: 1234 mvc: pathmatch: