i was trying to make a simple board with spring boot and data jpa that users can make a post and admins can make boards. this is the code of api i made that creates a board.
@PostMapping
public ResponseEntity<BoardResponseDto> createBoard(@RequestBody @Validated BoardNameRequestDto boardNameRequestDto) {
long boardId = boardService.createBoard(boardNameRequestDto);
return ResponseEntity.created(URI.create("/board/" + boardId))
.body(
BoardResponseDto.builder()
.code(ms.getMessage("suc.code", null, null))
.message(ms.getMessage("suc.message", null, null))
.build()
);
}
uri over there is mapped with board details page. so when i send my request, it should create a board and redirect to board details page of the board that i created.
and this is the code of board details page.
@GetMapping("/{boardId}")
public ResponseEntity<BoardResponseDto> getBoard(@PathVariable long boardId, Pageable pageable) {
Board findBoard = boardService.findBoard(boardId).orElseThrow(NoBoardException::new);
List<PostListDto> boardPost = postService.getBoardPost(boardId, pageable);
return ResponseEntity.ok(
BoardResponseDto.builder()
.code(ms.getMessage("suc.code", null, null))
.message(ms.getMessage("suc.message", null, null))
.boardName(findBoard.getBoardName())
.postCount(boardPost.size())
.postList(boardPost)
.build()
);
}
so this is actual response of board details page and the expected response of redirection from creating a board.
{
"code": "SUC",
"message": "Success",
"boardName": "test",
"postCount": 0,
"postList": []
}
but this is what i actually got when i send a request to create a board.
{
"code": "SUC",
"message": "Success",
"boardName": null,
"postCount": 0,
"postList": null
}
as far as i know redirecting to a page is same as accessing to the page with GET method, but it seems to be different.. help me please. sorry about my poor english