-
Notifications
You must be signed in to change notification settings - Fork 4
과제 1-1 jihoonwjj 과제제출 #3
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
base: task/hjh
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고 하셨습니다😁
엔티티하고 레포지터리 이름 정상화하고
서비스 인터페이스에 어노테이션을 붙여놓으신것도 세부 구현 클래스에 붙이는 걸로 수정 바랍니다
} | ||
|
||
@PatchMapping(("/{id}")) | ||
public ResponseEntity<Ang> editThatShit(AnggimoddiDTO anggimoddiDTO, @PathVariable Long id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vaild
어노테이션 적용 안하면 값 검증이 활성화가 안되요!
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Builder | ||
public class AnggimoddiDTO { | ||
private Long id; | ||
private String title; | ||
private String content; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Size
나 @Max
등 수많은 값 검증 어노테이션이 있으니까 특히 Request로 받는 DTO는 검증을 강화해줍시다
public ResponseEntity<List<Ang>> getAngs() { | ||
try { | ||
return ResponseEntity.ok(angRepository.findAll()); | ||
} catch (IllegalArgumentException e) { | ||
List<Ang> emptyList = Collections.emptyList(); | ||
return ResponseEntity.ok(emptyList); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
같이 협업하는 클라이언트 마다 다르긴 했는데 대부분의 클라이언트는 List형 API에서는 값이 없으면 그냥 Empty List를 반환해 주는 것을 선호하더라고요
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Ang extends BaseIdxEntity{ | ||
private String title; | ||
private String content; | ||
|
||
@Builder | ||
public Ang(Long idx, String title, String content){ | ||
this.idx = idx; | ||
this.title = title; | ||
this.content = content; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private final AngRepository angRepository; | ||
|
||
public ResponseEntity<Ang> postPost(Ang ang) { | ||
return ResponseEntity.ok(angRepository.save(ang)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 식으로 설계되어 있으면 오류 발생 시 500뜨고 말거나 이상한 값이 날라갈 거 같은데 예외 처리를 해주는건 어떨까요
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 녀석 인터페이스에 @Service
? 보통의 Aura가 아니군
@GetMapping("/") | ||
public ResponseEntity<List<Ang>> getShitAll() { | ||
return getPost.getAngs(); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<Optional<Ang>> getThatShit(@PathVariable Long id) { | ||
return getPost.getAngById(id); | ||
} | ||
|
||
@PostMapping("/") | ||
public ResponseEntity<Ang> makeShit(Ang ang) { | ||
return postpost.postPost(ang); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GET /articles
나 POST /articles
와 같은 상황에서는 ("/")로 명시하는 것보다 그냥 아무것도 안남기고 @PostMapping
이렇게만 하는게 관례에 더 맞을 것 같습니다
No description provided.