fixed: response status 변경, list 객체 바인딩 수정
This commit is contained in:
@@ -12,6 +12,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
@@ -88,6 +89,7 @@ public class BoardApiController {
|
||||
* @return BoardResponseDto 게시판 상세 응답 DTO
|
||||
*/
|
||||
@PostMapping("/api/v1/boards")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public BoardResponseDto save(@RequestBody @Valid BoardSaveRequestDto requestDto) {
|
||||
return boardService.save(requestDto);
|
||||
}
|
||||
@@ -110,6 +112,7 @@ public class BoardApiController {
|
||||
* @param boardNo 게시판 번호
|
||||
*/
|
||||
@DeleteMapping("/api/v1/boards/{boardNo}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void delete(@PathVariable Integer boardNo) {
|
||||
boardService.delete(boardNo);
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ public class BoardResponseDto implements Serializable {
|
||||
* @param posts 게시물 목록
|
||||
*/
|
||||
public void setNewestPosts(List<PostsSimpleResponseDto> posts) {
|
||||
this.posts = new ArrayList<>(posts);
|
||||
this.posts = posts == null ? null : new ArrayList<>(posts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.egovframe.cloud.boardservice.api.comment.dto.CommentSaveRequestDto;
|
||||
import org.egovframe.cloud.boardservice.api.comment.dto.CommentUpdateRequestDto;
|
||||
import org.egovframe.cloud.boardservice.service.comment.CommentService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -94,6 +95,7 @@ public class CommentApiController {
|
||||
* @param requestDto 댓글 등록 요청 DTO
|
||||
*/
|
||||
@PostMapping("/api/v1/comments")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public CommentResponseDto save(@RequestBody @Valid CommentSaveRequestDto requestDto) {
|
||||
return commentService.save(requestDto);
|
||||
}
|
||||
@@ -119,6 +121,7 @@ public class CommentApiController {
|
||||
* @param commentNo 댓글 번호
|
||||
*/
|
||||
@DeleteMapping("/api/v1/comments/delete/{boardNo}/{postsNo}/{commentNo}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void deleteByCreator(@PathVariable Integer boardNo, @PathVariable Integer postsNo, @PathVariable Integer commentNo) {
|
||||
String userId = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
|
||||
@@ -143,6 +146,7 @@ public class CommentApiController {
|
||||
* @param commentNo 댓글 번호
|
||||
*/
|
||||
@DeleteMapping("/api/v1/comments/{boardNo}/{postsNo}/{commentNo}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void delete(@PathVariable Integer boardNo, @PathVariable Integer postsNo, @PathVariable Integer commentNo) {
|
||||
commentService.delete(boardNo, postsNo, commentNo);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -132,6 +133,7 @@ public class PostsApiController {
|
||||
* @return PostsResponseDto 게시물 상세 응답 DTO
|
||||
*/
|
||||
@PostMapping("/api/v1/posts/save/{boardNo}")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public PostsResponseDto saveByCreator(@PathVariable Integer boardNo, @RequestBody @Valid PostsSimpleSaveRequestDto requestDto) {
|
||||
String userId = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
return postsService.save(boardNo, requestDto, userId);
|
||||
@@ -159,6 +161,7 @@ public class PostsApiController {
|
||||
* @param postsNo 게시물 번호
|
||||
*/
|
||||
@DeleteMapping("/api/v1/posts/remove/{boardNo}/{postsNo}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void deleteByCreator(@PathVariable Integer boardNo, @PathVariable Integer postsNo) {
|
||||
String userId = SecurityContextHolder.getContext().getAuthentication().getName();
|
||||
|
||||
@@ -173,6 +176,7 @@ public class PostsApiController {
|
||||
* @return PostsResponseDto 게시물 상세 응답 DTO
|
||||
*/
|
||||
@PostMapping("/api/v1/posts/{boardNo}")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public PostsResponseDto save(@PathVariable Integer boardNo, @RequestBody @Valid PostsSaveRequestDto requestDto) {
|
||||
return postsService.save(boardNo, requestDto);
|
||||
}
|
||||
@@ -222,6 +226,7 @@ public class PostsApiController {
|
||||
* @param requestDtoList 게시물 삭제 요청 DTO List
|
||||
*/
|
||||
@PutMapping("/api/v1/posts/delete")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
public void delete(@RequestBody @Valid List<PostsDeleteRequestDto> requestDtoList) {
|
||||
postsService.delete(requestDtoList);
|
||||
}
|
||||
|
||||
@@ -203,14 +203,14 @@ public class PostsResponseDto implements Serializable {
|
||||
* 이전 게시물
|
||||
*/
|
||||
public void setPrevPosts(List<PostsSimpleResponseDto> prevPosts) {
|
||||
this.prevPosts = new ArrayList<>(prevPosts);
|
||||
this.prevPosts = prevPosts == null ? null : new ArrayList<>(prevPosts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 다음 게시물
|
||||
*/
|
||||
public void setNextPosts(List<PostsSimpleResponseDto> nextPosts) {
|
||||
this.nextPosts = new ArrayList<>(nextPosts);
|
||||
this.nextPosts = nextPosts == null ? null : new ArrayList<>(nextPosts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ public class Posts extends BaseEntity {
|
||||
this.noticeAt = noticeAt;
|
||||
this.deleteAt = deleteAt;
|
||||
this.creator = creator;
|
||||
this.comments = new ArrayList<>(comments);
|
||||
this.comments = comments == null ? null : new ArrayList<>(comments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ public class HttpUtil {
|
||||
* static method 만으로 구성된 유틸리티 클래스
|
||||
* 객체 생성 금지
|
||||
*/
|
||||
private HttpUtil() {
|
||||
private HttpUtil() throws IllegalStateException {
|
||||
throw new IllegalStateException("Http Utility Class");
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ public class BoardApiControllerTest {
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
|
||||
|
||||
BoardResponseDto dto = responseEntity.getBody();
|
||||
assertThat(dto).isNotNull();
|
||||
@@ -354,7 +354,7 @@ public class BoardApiControllerTest {
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
|
||||
Optional<Board> board = selectData(boardNo);
|
||||
assertThat(board).isNotPresent();
|
||||
|
||||
@@ -320,7 +320,7 @@ class CommentApiControllerTest {
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
|
||||
|
||||
CommentResponseDto dto = responseEntity.getBody();
|
||||
assertThat(dto).isNotNull();
|
||||
@@ -476,7 +476,7 @@ class CommentApiControllerTest {
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
|
||||
Optional<Comment> comment = selectData(boardNo, postsNo, commentNo);
|
||||
assertThat(comment).isPresent();
|
||||
|
||||
@@ -442,7 +442,7 @@ class PostsApiControllerTest {
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
|
||||
|
||||
PostsResponseDto dto = responseEntity.getBody();
|
||||
assertThat(dto).isNotNull();
|
||||
@@ -640,7 +640,7 @@ class PostsApiControllerTest {
|
||||
);
|
||||
|
||||
// then
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
|
||||
|
||||
List<Posts> list = postsRepository.findAll();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user