정주찬 api코드 작성#14
Hidden character warning
Conversation
juchan2002
commented
Jun 5, 2024
- close 정주찬 api 코드 작성 #13
| public class TaskController { | ||
| private final TaskService taskService; | ||
|
|
||
| @Autowired |
There was a problem hiding this comment.
음?... 이건 조금 이상하네요... 인터넷에 생성자 주입으로 Spring관련해서 검색해보시면 좋을 것 같아요.
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| @Controller |
There was a problem hiding this comment.
@responsebody 보다는
해당 애너테이션을 @RestController 로 수정하면 됩니다 !
| private String password; | ||
|
|
||
| // Constructors | ||
| public User() {} |
| this.userRepository = new UserRepository(); | ||
| } | ||
|
|
||
| public User createUser(String name, String email, String password) { |
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
|
|
||
| @SpringBootTest |
|
|
||
| @PostMapping | ||
| @ResponseBody | ||
| public Task createTask(@RequestParam String title, @RequestParam String description, @RequestParam LocalDate dueDate, @RequestParam boolean status) { |
coke98
left a comment
There was a problem hiding this comment.
LGTM 고생하셨습니다! 유일하게 이슈와 PR 연동해서 작성해주신 점도 좋았어요. 프로젝트에서는 이슈, PR 템플릿도 지정하여 협업할 수도 있으니 활용해보셔도 좋을 것 같아요.
| this.status = status; | ||
| } | ||
|
|
||
| // Getters and setters |
There was a problem hiding this comment.
자동 생성이라면 사용하지 않는 게터 세터는 삭제하는 편이 좋아요. 캡슐화와 정보 은닉에서 객체지향의 장점을 어떻게 살릴 수 있을지 고민해보면 좋을 듯 합니다
| private boolean status; | ||
|
|
||
| // Constructors | ||
| public Task() {} |
There was a problem hiding this comment.
기본 생성자가 필요한 이유, 해당 코드에서 기본 생성자를 직접 명시해준 이유가 무엇일까요?
|
|
||
| public class UserRepository { | ||
| private List<User> users = new ArrayList<>(); | ||
| private AtomicLong nextId = new AtomicLong(1); |
There was a problem hiding this comment.
데이터베이스 연동없이 레포지토리 계층 만들기위해 필드로 임시로 메모리 저장을 시도해주셨네요👍
| return user.orElse(null); | ||
| } | ||
|
|
||
| @PutMapping("/{id}") |
There was a problem hiding this comment.
patch put 모두 수정에 사용되는 메서드인데요, 둘은 어떤 차이가 있을까요? 그렇다면 현재는 어떤 메서드를 사용하는 것이 좀 더 적절할까요? 답변 남겨주시면 감사하겠습니다!
|
|
||
| @PostMapping | ||
| @ResponseBody | ||
| public User createUser(@RequestParam String name, @RequestParam String email, @RequestParam String password) { |
There was a problem hiding this comment.
requestParam 대신 post 요청에서는 requestBody를 사용하는 편이 더 적절할 것 같아요.
보통 코딩을 하다 파라미터가 3개 이상 나열되기 시작한다면(책 - 클린코드) 다른 방법이 없을지 고민해보면 좋을 것 같아요.
바디를 사용하면 바인딩을 통해 원하는 객체(예: UserCreateRequest)로 곧바로 변환해 활용할 수 있습니당