Skip to content

Commit

Permalink
DB CREATE
Browse files Browse the repository at this point in the history
  • Loading branch information
Johyunik committed Nov 27, 2023
1 parent 1152f2c commit 18495ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/main/java/com/weatherfit/board/controller/BoardController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -72,7 +72,7 @@ public BoardDetailResponseDTO detailBoard(@PathVariable int boardId) {
boardDetailResponseDTO.setHashTag(boardEntity.getHashTag());
boardDetailResponseDTO.setStatus(boardEntity.isStatus());
List<ImageDTO> imageDTOList = new ArrayList<>();
for(ImageEntity images : boardEntity.getImages()) {
for (ImageEntity images : boardEntity.getImages()) {
imageDTOList.add(images.entityToDTO(images));
}
boardDetailResponseDTO.setImages(imageDTOList);
Expand All @@ -84,15 +84,15 @@ 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 {
BoardWriteDTO boardWriteDTO = objectMapper.readValue(boardJson, BoardWriteDTO.class);

BoardEntity boardEntity = BoardEntity.builder()
.boardId(boardWriteDTO.getBoardId())
.nickName(boardWriteDTO.getNickName())
.nickName(nickName)
.content(boardWriteDTO.getContent())
.temperature(boardWriteDTO.getTemperature())
.category(boardWriteDTO.getCategory())
Expand Down Expand Up @@ -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();
Expand All @@ -137,6 +138,7 @@ public boolean patchBoard(@PathVariable int boardId,
}

private final KafkaTemplate<String, String> kafkaTemplate;

@GetMapping("/test")
public String partion() {
kafkaTemplate.send("hashtag", 1, "update", "Test");
Expand All @@ -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<BoardSearchDTO> search(@RequestParam(required = false) List<String> categories,
@RequestParam(required = false) List<String> hashtags) {
@RequestParam(required = false) List<String> hashtags) {
return boardService.search(categories, hashtags);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 18495ec

Please sign in to comment.