Conversation
|
|
||
| @RequiredArgsConstructor | ||
| @RestController | ||
| @RequestMapping("/api/colleges") |
|
|
||
| private final CollegeService collegeService; | ||
|
|
||
| @GetMapping("/") |
There was a problem hiding this comment.
rest api 규칙 중 마지막에 /가 붙지 않는 규칙이 있습니다.
| public ResponseEntity<List<College>> findAll(){ | ||
|
|
||
| List<College> college = collegeService.printAll(); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body((List<College>) college); |
There was a problem hiding this comment.
HttpStatus.CREATED 보다 HttpStatus.OK 가 더 적합한 것 같습니다~
| private final TagService tagService; | ||
|
|
||
| @GetMapping("/") | ||
| public ResponseEntity<List<Tag>>findAll(){ |
| public ResponseEntity<List<Tag>>findAll(){ | ||
|
|
||
| List<Tag> tag = tagService.printAll(); | ||
| return ResponseEntity.status(HttpStatus.CREATED).body((List<Tag>) tag); |
There was a problem hiding this comment.
HttpStatus.CREATED 보다 HttpStatus.OK 가 더 적합한 것 같습니다~
There was a problem hiding this comment.
(List)를 통해 형변환이 이루어지고 있는데,
불필요한 코드 같습니다!
| } | ||
|
|
||
|
|
||
| public List<Tag> printAll(){ |
There was a problem hiding this comment.
함수의 기능상 printAll()보다 findAll()이 더 적합한 것 같습니다!
| private CollegeRepository collegeRepository; | ||
|
|
||
|
|
||
| public List<College> printAll(){ |
There was a problem hiding this comment.
함수의 기능상 printAll()보다 findAll()이 더 적합한 것 같습니다!
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(unique = true, insertable = false, updatable = false, length = 10) |
|
|
||
| http.authorizeHttpRequests() | ||
| .anyRequest().authenticated(); | ||
| .anyRequest().permitAll(); |
| import java.util.List; | ||
| @RequiredArgsConstructor |
There was a problem hiding this comment.
Ctrl + Alt + L 단축키 사용하셔서 포매팅 부탁드립니다~
| public List<College> findAll() { | ||
| return collegeRepository.findAll(); | ||
| } |
There was a problem hiding this comment.
Controller <-> Service간에 데이터를 전달할 때는 entity 보다는 dto를 사용하는 것이 좋습니다~
| public List<Tag> findAll(){ | ||
| return tagRepository.findAll(); } | ||
| } No newline at end of file |
There was a problem hiding this comment.
Controller <-> Service간에 데이터를 전달할 때는 entity 보다는 dto를 사용하는 것이 좋습니다~
|
|
||
| @Getter | ||
| @Entity | ||
| @Table(name = "College") |
There was a problem hiding this comment.
보통 데이터베이스 테이블 이름, 컬럼과 같은 곳에는 소문자만을 사용하는 것이 기본 컨벤션입니다.
| @ManyToMany | ||
| @JoinTable(schema = "College") | ||
| private List<College> users = new ArrayList<>(); |
| @Getter | ||
| public class CollegeResponse { | ||
|
|
||
| private final Long id; | ||
| private final String collegeName; | ||
|
|
||
|
|
||
| public CollegeResponse(College college){ | ||
|
|
||
| this.id = college.getId(); | ||
| this.collegeName = college.getName(); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| } |
There was a problem hiding this comment.
요즘 dto를 만들 때는 record를 사용하시면 편리합니다~
| @Getter | ||
| public class TagResponse { | ||
|
|
||
| private final Long id; | ||
| private final String user; | ||
|
|
||
|
|
||
| public TagResponse(Tag tag){ | ||
| this.id = tag.getId(); | ||
| this.user = tag.getName(); | ||
| } | ||
|
|
||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
요즘 dto를 만들 때는 record를 사용하시면 편리합니다~
| public ResponseEntity<List<College>> findAll(){ | ||
|
|
||
| List<College> college = collegeService.findAll(); | ||
| return ResponseEntity.status(HttpStatus.OK).body((List<College>) college); |
There was a problem hiding this comment.
ResponseEntity.ok(body)를 사용하시면 조금 더 간결하고 편리하게 사용하실 수 있을 것 같습니다~
|
|
||
| private final TagService tagService; | ||
| List<Tag> tag = tagService.findAll(); | ||
| return ResponseEntity.status(HttpStatus.OK).body(tag); |
There was a problem hiding this comment.
ResponseEntity.ok(body)를 사용하시면 조금 더 간결하고 편리하게 사용하실 수 있을 것 같습니다~
No description provided.