Skip to content

Feat/week2#20

Open
PHJ2000 wants to merge 2 commits intomainfrom
박재홍

Hidden character warning

The head ref may contain hidden characters: "\ubc15\uc7ac\ud64d"
Open

Feat/week2#20
PHJ2000 wants to merge 2 commits intomainfrom
박재홍

Conversation

@PHJ2000
Copy link
Copy Markdown

@PHJ2000 PHJ2000 commented Nov 7, 2025

변경점 👍

setter취약점 변경, 댓글 기능 추가, 테스트 코드 추가

버그 해결 💊

해결한 버그

테스트 💻

변경점을 테스트하기 위한 방법 기술

스크린샷 🖼

변경된 부분에 대한 스크린샷

비고 ✏

리뷰어에게 전하는 말 등


사용하지 않은 항목은 모두 지워주세요.

@PHJ2000 PHJ2000 self-assigned this Nov 7, 2025
Copy link
Copy Markdown

@Martinel2 Martinel2 left a comment

Choose a reason for hiding this comment

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

2주차 과제 수고하셨습니다!! 코드도 굉장히 완성도가 높고, 테스트코드도 통합 테스트 코드로 잘 작성해주신 것 같네요.
더 해볼 것이 있다면, 사용자 스토리를 먼저 작성 한 뒤, 테스트를 하나의 기능만을(ex)서비스단의 특정 메서드만)을 테스트하는 코드를 먼저 작성해보는 것을 추천드려요!!
그 후, 해당 테스트를 통과하도록 기능을 하나씩 구현하고, 최종적으로 통합테스트까지 통과하게되면, 그 유명한 TDD 방식을 사용하여 코드를 작성하실 수 있습니다

Comment on lines +21 to +25
@Builder
private Comment(String content, Post post) {
this.content = content;
this.post = post;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Setter가 아닌 Builder를 사용하는 방식 아주 좋습니다!

import java.util.List;

@Service
public class CommentService {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DB를 건드리는 코드이니 @transactional을 통하여 트랜잭션을 설정해두면 좋을 것 같아요!!


public Comment create(Long postId, String content) {
Post post = postRepo.findById(postId)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Post not found"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

해당 코드는 아래에 작성한 ensurePostExists와 어떤 차이점이 존재할까요?

Comment on lines +44 to +45
Post post = repo.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Post not found"));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

commentService에서도 같은 방식이 존재하는데, 이러한 코드 중복은 어떻게 처리하는 것이 좋을까요?

import java.util.List;

@RestController
@RequestMapping("/posts/{postId}/comments")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

comment를 설정하는 모든 코드에서 postId가 필수로 존재해야할까요? 그렇다면 왜 그렇게해야할까요? 아니라면 어떤식으로 코드를 수정할 수 있을까요?


@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public PostResponse create(@Valid @RequestBody PostCreateRequest req) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

valid를 사용하여 dto를 검증하는 방식 좋습니당

Comment on lines +5 to +12
public record CommentResponse(
Long id,
String content
) {
public static CommentResponse from(Comment c) {
return new CommentResponse(c.getId(), c.getContent());
}
}
Copy link
Copy Markdown

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.

2 participants