From 18495ec9ca4c2071bae924f16cab4c422b59d1e1 Mon Sep 17 00:00:00 2001 From: Johyunik Date: Mon, 27 Nov 2023 13:15:34 +0900 Subject: [PATCH] DB CREATE --- .../board/controller/BoardController.java | 17 ++++++++++------- .../board/controller/LikeController.java | 4 ++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/weatherfit/board/controller/BoardController.java b/src/main/java/com/weatherfit/board/controller/BoardController.java index 2b2a323..012199c 100644 --- a/src/main/java/com/weatherfit/board/controller/BoardController.java +++ b/src/main/java/com/weatherfit/board/controller/BoardController.java @@ -18,12 +18,12 @@ import org.springframework.kafka.core.KafkaTemplate; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; + import java.util.ArrayList; import java.util.List; import java.util.Optional; - @RestController @RequiredArgsConstructor public class BoardController { @@ -72,7 +72,7 @@ public BoardDetailResponseDTO detailBoard(@PathVariable int boardId) { boardDetailResponseDTO.setHashTag(boardEntity.getHashTag()); boardDetailResponseDTO.setStatus(boardEntity.isStatus()); List imageDTOList = new ArrayList<>(); - for(ImageEntity images : boardEntity.getImages()) { + for (ImageEntity images : boardEntity.getImages()) { imageDTOList.add(images.entityToDTO(images)); } boardDetailResponseDTO.setImages(imageDTOList); @@ -84,7 +84,7 @@ public BoardDetailResponseDTO detailBoard(@PathVariable int boardId) { // 게시글 작성 @PostMapping("/write") - public String insertBoard(@RequestParam("board") String boardJson, @RequestPart("images") MultipartFile[] images) { + public String insertBoard(@RequestHeader("decodedToken") String nickName, @RequestParam("board") String boardJson, @RequestPart("images") MultipartFile[] images) { ObjectMapper objectMapper = new ObjectMapper(); try { @@ -92,7 +92,7 @@ public String insertBoard(@RequestParam("board") String boardJson, @RequestPart( BoardEntity boardEntity = BoardEntity.builder() .boardId(boardWriteDTO.getBoardId()) - .nickName(boardWriteDTO.getNickName()) + .nickName(nickName) .content(boardWriteDTO.getContent()) .temperature(boardWriteDTO.getTemperature()) .category(boardWriteDTO.getCategory()) @@ -123,7 +123,8 @@ public String insertBoard(@RequestParam("board") String boardJson, @RequestPart( // 게시글 수정 @PatchMapping(value = "/edit/{boardId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseBody - public boolean patchBoard(@PathVariable int boardId, + public boolean patchBoard( + @PathVariable int boardId, @RequestPart("board") String boardJson, @RequestPart(value = "images", required = false) MultipartFile[] images) { ObjectMapper objectMapper = new ObjectMapper(); @@ -137,6 +138,7 @@ public boolean patchBoard(@PathVariable int boardId, } private final KafkaTemplate kafkaTemplate; + @GetMapping("/test") public String partion() { kafkaTemplate.send("hashtag", 1, "update", "Test"); @@ -147,14 +149,15 @@ public String partion() { // 게시글 삭제 @DeleteMapping("/delete/{boardId}") @ResponseBody - public void deleteBoard(@PathVariable int boardId) { + public void deleteBoard( + @PathVariable int boardId) { boardService.deleteBoard(boardId); } // 게시글 검색 @GetMapping("/search") public List search(@RequestParam(required = false) List categories, - @RequestParam(required = false) List hashtags) { + @RequestParam(required = false) List hashtags) { return boardService.search(categories, hashtags); } } \ No newline at end of file diff --git a/src/main/java/com/weatherfit/board/controller/LikeController.java b/src/main/java/com/weatherfit/board/controller/LikeController.java index 97fab1d..696b4ee 100644 --- a/src/main/java/com/weatherfit/board/controller/LikeController.java +++ b/src/main/java/com/weatherfit/board/controller/LikeController.java @@ -16,8 +16,8 @@ public LikeController(LikeService likeService) { } @PostMapping("/like/{boardId}") - public boolean like (@PathVariable("boardId") int boardId, @RequestBody LikeRequestDTO likeRequestDto) { - likeService.like(boardId, likeRequestDto.getNickName()); + public boolean like (@RequestHeader("decodedToken") String nickName, @PathVariable("boardId") int boardId) { + likeService.like(boardId, nickName); return true; } } \ No newline at end of file