From 5b94c653d663b59a71c0d78d9d937c4b4c475015 Mon Sep 17 00:00:00 2001 From: skybluelion Date: Thu, 14 Dec 2023 20:21:08 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B2=8C=EC=8B=9C=EB=AC=BC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EB=B3=84=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/controller/BoardController.java | 21 +++++------- .../java/com/dearsanta/app/domain/Board.java | 2 ++ .../app/dto/BoardCreateRequestDto.java | 33 +++++++++++++++++++ .../dearsanta/app/service/BoardService.java | 7 ++-- .../app/service/BoardServiceImpl.java | 10 +++--- .../com/dearsanta/app/mapper/BoardMapper.xml | 8 +++-- .../app/service/BoardServiceTest.java | 9 ++--- 7 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/dearsanta/app/dto/BoardCreateRequestDto.java diff --git a/src/main/java/com/dearsanta/app/controller/BoardController.java b/src/main/java/com/dearsanta/app/controller/BoardController.java index a7c0fe6..0e5da28 100644 --- a/src/main/java/com/dearsanta/app/controller/BoardController.java +++ b/src/main/java/com/dearsanta/app/controller/BoardController.java @@ -1,10 +1,7 @@ package com.dearsanta.app.controller; import com.dearsanta.app.domain.enumtype.Sorted; -import com.dearsanta.app.dto.BoardDto; -import com.dearsanta.app.dto.BoardLikeDto; -import com.dearsanta.app.dto.BoardRequestDto; -import com.dearsanta.app.dto.BoardListDto; +import com.dearsanta.app.dto.*; import com.dearsanta.app.service.BoardService; import lombok.extern.log4j.Log4j; import org.springframework.beans.factory.annotation.Autowired; @@ -28,24 +25,24 @@ public class BoardController { @PostMapping(value="auth/board/new", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity createBoard( - @RequestPart("boardRequestDto") BoardRequestDto boardRequestDto, + @RequestPart("boardCreateRequestDto") BoardCreateRequestDto boardCreateRequestDto, @RequestPart("boardImage") MultipartFile boardImage) { - log.info(boardRequestDto.getTitle() + boardRequestDto.getContent() + boardImage); + log.info(boardCreateRequestDto.getTitle() + boardCreateRequestDto.getContent() + boardImage); String memberId = (String) RequestContextHolder .currentRequestAttributes().getAttribute("memberId", RequestAttributes.SCOPE_REQUEST); if (memberId == null) { throw new RuntimeException("권한이 없습니다."); } - if (boardRequestDto.getTitle().length() > 100) { + if (boardCreateRequestDto.getTitle().length() > 100) { throw new IllegalArgumentException("제목은 100자 이하로 입력해주세요."); } - if (boardRequestDto.getContent().length() > 1000) { + if (boardCreateRequestDto.getContent().length() > 1000) { throw new IllegalArgumentException("내용은 1000자 이하로 입력해주세요."); } - - boardRequestDto.setMemberId(memberId); - - boardService.createBoard(boardRequestDto, boardImage); + String boardCategoryId = boardService.findBoardCategoryId(boardCreateRequestDto.getMainCategory(), boardCreateRequestDto.getSubCategory()); + boardCreateRequestDto.setMemberId(memberId); + boardCreateRequestDto.setBoardCategoryId(boardCategoryId); + boardService.createBoard(boardCreateRequestDto, boardImage); return ResponseEntity.ok().build(); } diff --git a/src/main/java/com/dearsanta/app/domain/Board.java b/src/main/java/com/dearsanta/app/domain/Board.java index 7a54501..c73de40 100644 --- a/src/main/java/com/dearsanta/app/domain/Board.java +++ b/src/main/java/com/dearsanta/app/domain/Board.java @@ -18,6 +18,8 @@ public class Board { private Date updatedDate; private String memberId; private String imgUrl; + private String mainCategory; + private String subCategory; private int likeCount; private int replyCount; private int viewCount; diff --git a/src/main/java/com/dearsanta/app/dto/BoardCreateRequestDto.java b/src/main/java/com/dearsanta/app/dto/BoardCreateRequestDto.java new file mode 100644 index 0000000..b7672b7 --- /dev/null +++ b/src/main/java/com/dearsanta/app/dto/BoardCreateRequestDto.java @@ -0,0 +1,33 @@ +package com.dearsanta.app.dto; + +import com.dearsanta.app.domain.Board; +import lombok.*; + +@Getter +@Setter +@Builder +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class BoardCreateRequestDto { + private String id; + private String boardCategoryId; + private String title; + private String content; + private String memberId; + private String imgUrl; + private String mainCategory; + private String subCategory; + public Board toEntity() { + return Board.builder() + .id(id) + .boardCategoryId(boardCategoryId) + .title(title) + .content(content) + .memberId(memberId) + .imgUrl(imgUrl) + .mainCategory(mainCategory) + .subCategory(subCategory) + .build(); + } +} diff --git a/src/main/java/com/dearsanta/app/service/BoardService.java b/src/main/java/com/dearsanta/app/service/BoardService.java index 2d51235..486c620 100644 --- a/src/main/java/com/dearsanta/app/service/BoardService.java +++ b/src/main/java/com/dearsanta/app/service/BoardService.java @@ -1,14 +1,11 @@ package com.dearsanta.app.service; import com.dearsanta.app.domain.enumtype.Sorted; -import com.dearsanta.app.dto.BoardDto; -import com.dearsanta.app.dto.BoardLikeDto; -import com.dearsanta.app.dto.BoardListDto; -import com.dearsanta.app.dto.BoardRequestDto; +import com.dearsanta.app.dto.*; import org.springframework.web.multipart.MultipartFile; public interface BoardService { - void createBoard(BoardRequestDto boardRequestDto, MultipartFile boardImage); + void createBoard(BoardCreateRequestDto boardCreateRequestDto, MultipartFile boardImage); BoardDto getBoard(String boardId); void updateBoard(String boardId, BoardRequestDto boardRequestDto, MultipartFile boardImage); void deleteBoard(String boardId); diff --git a/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java b/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java index 1641976..d5fec4c 100644 --- a/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java +++ b/src/main/java/com/dearsanta/app/service/BoardServiceImpl.java @@ -90,14 +90,14 @@ public String findBoardCategoryId(String mainCategory, String subCategory) { } @Override - public void createBoard(BoardRequestDto boardRequestDto, MultipartFile boardImage) { - boardRequestDto.setId(UUID.randomUUID().toString()); + public void createBoard(BoardCreateRequestDto boardCreateRequestDto, MultipartFile boardImage) { + boardCreateRequestDto.setId(UUID.randomUUID().toString()); if (boardImage != null) { - String imgUrl = aWSS3.uploadImage(boardRequestDto.getId(), boardImage); - boardRequestDto.setImgUrl(imgUrl); + String imgUrl = aWSS3.uploadImage(boardCreateRequestDto.getId(), boardImage); + boardCreateRequestDto.setImgUrl(imgUrl); } - Board board = boardRequestDto.toEntity(); + Board board = boardCreateRequestDto.toEntity(); boardMapper.createBoard(board); } diff --git a/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml b/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml index 751420a..a9289ee 100644 --- a/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml +++ b/src/main/resources/com/dearsanta/app/mapper/BoardMapper.xml @@ -10,14 +10,18 @@ title, content, member_id, - img_url + img_url, + main_category, + sub_category ) VALUES ( #{id, jdbcType=VARCHAR}, #{boardCategoryId, jdbcType=VARCHAR}, #{title, jdbcType=VARCHAR}, #{content, jdbcType=VARCHAR}, #{memberId, jdbcType=VARCHAR}, - #{imgUrl, jdbcType=VARCHAR} + #{imgUrl, jdbcType=VARCHAR}, + #{mainCategory, jdbcType=VARCHAR}, + #{subCategory, jdbcType=VARCHAR} )