Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chapter 6] 블로그 기획하고 API 만들기 에서 #72

Open
YangGyunShin opened this issue Nov 2, 2024 · 0 comments
Open

[Chapter 6] 블로그 기획하고 API 만들기 에서 #72

YangGyunShin opened this issue Nov 2, 2024 · 0 comments

Comments

@YangGyunShin
Copy link

YangGyunShin commented Nov 2, 2024

6.3 블로그 글 작성을 위한 API 구현하기 부분 중 Controller 부분을 보면 응답시 Entity(article)로 반환한걸로 보입니다.

@PostMapping("/api/articles")
    public ResponseEntity<Article> addArticle(@RequestBody AddArticleRequest request) {
        Article savedArticle = blogService.save(request);
        return ResponseEntity.status(HttpStatus.CREATED).body(savedArticle);
    }  

entity로 반환하기 보단, DTO로 반환하는게 더욱 적절하지 않나요?

<예시>

@PostMapping("/api/articles")
public ResponseEntity<ArticleResponse> addArticle(@RequestBody AddArticleRequest request) {
    Article savedArticle = blogService.save(request);
    return ResponseEntity.status(HttpStatus.CREATED).body(new ArticleResponse(savedArticle));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant