Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Gopistol
Copy link

@Gopistol Gopistol commented Sep 12, 2023

@Gopistol Gopistol changed the title [10주차] API 개발 미션 [10주차] API 개발 미션 (Gopistol Sep 13, 2023
@Gopistol Gopistol changed the title [10주차] API 개발 미션 (Gopistol [10주차] API 개발 미션 (Gopistol) Sep 13, 2023
Comment on lines +25 to +30
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'
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@RequestBody CommentRequestDTO commentRequestDTO) {
@RequestBody CommentRequestDTO commentRequestDTO
) {


private final CommentService commentService;

@PostMapping("/members/{memberId}/posts/{postId}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Path 다시 고민해보기.

Comment on lines +6 to +11
@Getter
@NoArgsConstructor
public class CommentRequestDTO {

String comment;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@Getter
@NoArgsConstructor
public class CommentRequestDTO {
String comment;
}
public record CommentRequestDTO(String comment) {}

record로 처리할 수 있으면 record로 하고 일반 클래스라면 final 넣어주기.
jacksonConverter가 문제라면 @JsonCreator 같은 어노테이션 확인해보기

Comment on lines +35 to +37
public static Comment create(Member member, Post post, String comment) {
return new Comment(null, comment, member, post);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

정적 팩토리 메서드 네이밍 컨벤션 참고하기!

Comment on lines +51 to +60
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;
Copy link
Member

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;
Copy link
Member

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}")
Copy link
Member

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 해당 필드가 필요한 지 고민해보기!

Comment on lines +58 to +63
public void addComment(Comment comment) {
this.getComments().add(comment);
comment.setPost(this);
// 댓글 개수 1 증가시킴
plusCommentCount();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

댓글 개수 증가시키는 로직에서 동시성 문제 고민해보기

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants