-
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주차] API 개발 미션 (Gopistol) #2
base: main
Are you sure you want to change the base?
Conversation
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
compileOnly 'org.projectlombok:lombok' | ||
runtimeOnly 'com.mysql:mysql-connector-j' | ||
annotationProcessor 'org.projectlombok:lombok' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' |
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.
별건 아니지만 앞으로는 dependencies도 성격에 맞게 관리해주면 좋을듯!
public void createComment( | ||
@PathVariable Long memberId, | ||
@PathVariable Long postId, | ||
@RequestBody CommentRequestDTO commentRequestDTO) { |
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.
@RequestBody CommentRequestDTO commentRequestDTO) { | |
@RequestBody CommentRequestDTO commentRequestDTO | |
) { |
|
||
private final CommentService commentService; | ||
|
||
@PostMapping("/members/{memberId}/posts/{postId}") |
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.
Path 다시 고민해보기.
@Getter | ||
@NoArgsConstructor | ||
public class CommentRequestDTO { | ||
|
||
String comment; | ||
} |
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.
@Getter | |
@NoArgsConstructor | |
public class CommentRequestDTO { | |
String comment; | |
} | |
public record CommentRequestDTO(String comment) {} |
record로 처리할 수 있으면 record
로 하고 일반 클래스라면 final
넣어주기.
jacksonConverter
가 문제라면 @JsonCreator
같은 어노테이션 확인해보기
public static Comment create(Member member, Post post, String comment) { | ||
return new Comment(null, comment, member, post); | ||
} |
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 static Comment create(Member member, Post post, String comment) { | |
return new Comment(null, comment, member, post); | |
} | |
public static Comment of(Member member, Post post, String comment) { | |
return new Comment(null, comment, member, post); | |
} |
정적 팩토리 메서드 네이밍 컨벤션 참고하기!
List<Member> members = findAllMembers(); | ||
List<MemberResponseDTO> memberResponseDTOList = new ArrayList<>(members.size()); | ||
for (Member member : members) { | ||
MemberResponseDTO memberResponseDTO = new MemberResponseDTO(); | ||
memberResponseDTO.setAuthId(member.getAuthId()); | ||
memberResponseDTO.setName(member.getName()); | ||
|
||
memberResponseDTOList.add(memberResponseDTO); | ||
} | ||
return memberResponseDTOList; |
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.
Stream
으로 고민해보기!- 불변 컬렉션 알아보기
package com.example.demo.post.controller; | ||
|
||
import com.example.demo.post.controller.request.CreatePostRequest; | ||
//import com.example.demo.post.controller.response.AllPostsResponseDTO; |
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 postService.getAllPosts(); | ||
} | ||
|
||
@PostMapping("/members/{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.
- path 다시 고민해보기
- 이대로 한다면
memberId
라고 명확히 표현하기. post 도메인에서 그냥 id라는 표현은 모호할 수 있다.
|
||
private String content; | ||
|
||
private int commentCount; |
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 addComment(Comment comment) { | ||
this.getComments().add(comment); | ||
comment.setPost(this); | ||
// 댓글 개수 1 증가시킴 | ||
plusCommentCount(); | ||
} |
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.
댓글 개수 증가시키는 로직에서 동시성 문제 고민해보기
ERD

Postman API
https://documenter.getpostman.com/view/26102875/2s9YC32a3s