-
Notifications
You must be signed in to change notification settings - Fork 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
[10주차] COW JPA API 개발 미션(Hoya324) #5
base: main
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.
해당 수정사항 잘 반영 부탁드립니다!
private final MemberService memberService; | ||
|
||
@PostMapping("/new") | ||
public MemberResponse create(@Valid @RequestBody MemberRequest memberRequest) { |
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.
ResponseEntity 적용을 한번 고려해보면 좋을 듯
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.
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.
return ResponseEntity.created()~~~
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { |
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 MemberRepository memberRepository; | ||
|
||
public MemberResponse join(MemberRequest memberRequest) { |
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.
parameter에 final을 사용하라.
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.
updatePostWriter(request); | ||
} | ||
|
||
private void updatePostWriter(UpdateMemberRequest request) { |
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 PostService postService; | ||
|
||
@PostMapping("/new") | ||
public PostResponse post(@PathVariable Long memberId, @Valid @RequestBody PostRequest postRequest) { |
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.
PostRequest : 요청 DTO인데, 엔티티로의 변환이 서비스에서 이루어짐. BUT, 응답을 받아올 때 entity -> 응답 dto로의 변환은 Controller에서 이뤄지고 있음.
@Transactional(readOnly = true) | ||
public Post findPost(Long postId) { | ||
return postRepository.findById(postId) | ||
.orElseThrow(() -> new IllegalArgumentException("사용자가 존재하지 않습니다.")); |
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.
에러 처리 형식을 맞추자
|
||
public void delete(Long memberId, Long postId) throws Exception { | ||
Member member = memberService.findOne(memberId); | ||
List<Post> posts = member.getPosts(); |
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.
post에서 member를 가져와야함.
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.
Post post = postRepository.findById(postId);
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
username: root | ||
url: jdbc:mysql://localhost:3306/cow_session | ||
password: Gh852852! |
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.
yml파일의 컬럼을 git에 그대로 등록하면 pw, key 노출 가능성이 있다. 어떻게 할까?
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.
암호화라던가 뭐 아니면 저런 yml파일을 관리하는 방식을 공부할 필요가 있을 것 같다.
@SpringBootTest | ||
class JpapracticeApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
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.
테스트 짜기.
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor |
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.
accessLevel
재할당 막기, delete 시에 post에서 해당 사용자인지 확인하도록 변경
postman API