[박준용_BackEnd] 7주차 과제 제출합니다.#4
Conversation
dh2906
left a comment
There was a problem hiding this comment.
고생하셨습니다!
앞으로는 커밋 작성 시 feat, fix, chore 등 커밋 단위도 작성해주세요.
e.g) feat: POST /article API 추가
| <body> | ||
| <p>안녕하세요 제 이름은 박준용입니다.</p> | ||
| </body> | ||
| </html> No newline at end of file |
There was a problem hiding this comment.
EOF 체크 부탁드릴게요. Intellij 자체에서 마지막 줄을 추가해주는 기능도 있으니 찾아서 적용해주시면 될 것 같아요
https://hyeon9mak.github.io/github-no-newline-at-a-end-of-file/
| @@ -0,0 +1,6 @@ | |||
| package com.example.demo; | |||
|
|
|||
| public class article { | |||
There was a problem hiding this comment.
클래스 명은 첫 글자가 대문자가 되도록 컨벤션 유지해주세요
| public Long id; | ||
| public String description; |
There was a problem hiding this comment.
public 접근 제어자를 사용한다면 외부에서 누구나 접근이 가능해지므로 객체지향의 특징인 정보 은닉을 만족하지 못하는 것 아닐까요??
| package com.example.demo; | ||
|
|
||
| public class article { | ||
| public Long id; |
There was a problem hiding this comment.
id 멤버 변수는 기본형 long이 아닌 참조형 Long을 사용한 이유가 무엇인가요?
| Map<Long, article> store = new HashMap<>(); | ||
| long seq = 1; | ||
|
|
||
| @PostMapping("/article") |
There was a problem hiding this comment.
여기 아래부터 한 칸 탭은 불필요해보여요.
앞으로는 코드 작성 후 커밋하기 전 Intellij에서 제공하는 기능인 코드 정렬 기능을 한 번 사용해주세요.
https://carpe08.tistory.com/401
|
|
||
| @PostMapping("/article") | ||
| public article create(@RequestBody article article) { | ||
| article.id = seq++; |
There was a problem hiding this comment.
이 코멘트는 심화 내용입니다! 그냥 한 번 보고 생각만 해주세요.
만약 게시글 POST 요청이 여러 사용자에 의해 동시에 들어왔다면 id는 중복될 수 있습니다. 그렇다면 이러한 문제를 해결하기 위해 어떻게 해야할까요?
| public article create(@RequestBody article article) { | ||
| article.id = seq++; | ||
| store.put(article.id, article); | ||
| return article; |
There was a problem hiding this comment.
나중에 다룰 내용이지만 DTO에 대해서 알아보시는걸 추천드려요.
| Map<Long, article> store = new HashMap<>(); | ||
| long seq = 1; |
There was a problem hiding this comment.
이 둘의 접근 제어자는 default로 둔 이유가 있나요?
| if (article == null) { | ||
| return null; | ||
| } | ||
| article.description = req.description; | ||
| return article; |
There was a problem hiding this comment.
| if (article == null) { | |
| return null; | |
| } | |
| article.description = req.description; | |
| return article; | |
| if (article != null) { | |
| article.description = req.description; | |
| } | |
| return article; |
이런 식으로 코드를 정리할 수도 있어 보여요.
| return article; | ||
| } | ||
|
|
||
| @GetMapping("/article/{id}") |
There was a problem hiding this comment.
저번주 과제에서는 /articles로 복수형을 사용하셨는데, 이번엔 단수형을 채택한 이유가 있으실까요??
There was a problem hiding this comment.
아..!! 제가 요구사항에 단수형으로 적어놨네요?!
이 코멘트는 무시하셔도 됩니다!!
| import java.util.Map; | ||
|
|
||
| @RestController | ||
| public class HelloController { |
There was a problem hiding this comment.
지금은 Article을 다루고 있으므로 클래스 명이 ArticleController로 변경되어야 할 것 같아요.
그렇게 된다면 기존에 있던 HelloContoller에 있던 코드는 지우지 않아도 사용할 수 있지 않을까요?
- ArticleController, Service, Repository 추가 - PostController, posts.html 추가 - Member, Board, Article 모델 추가
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public Long getMemberId() { | ||
| return memberId; | ||
| } |
There was a problem hiding this comment.
getXXX, setXXX와 같은 메소드는 멤버 변수의 수에 비례하므로 Lombok 라이브러리를 활용하시면 좋을 것 같습니다!
사실상 편의성 측면에서는 필수 라이브러리라서 알아보시는 것을 추천드려요.
| public Article update(Long id, Article req) { | ||
| Article article = repository.findById(id); | ||
| if (article == null) return null; | ||
| article.setTitle(req.getTitle()); | ||
| article.setContent(req.getContent()); | ||
| return article; | ||
| } |
There was a problem hiding this comment.
Article 모델에서 update 변수도 있던데, 게시글을 수정하면 수정된 시각도 변경해야 할 것 같아요
| } | ||
|
|
||
| @PostMapping("/articles") | ||
| public ResponseEntity<Article> create(@RequestBody Article article) { |
There was a problem hiding this comment.
요청과 응답 모두 Article 모델을 사용하고 있는데, DTO를 적용하지 않은 이유가 있으신가요??
만약 DTO를 사용하지 않는다면 무슨 불편함을 겪을까요?
# Conflicts: # src/main/java/com/example/demo/ArticleService.java
No description provided.