Skip to content

Feat/week 2#19

Open
zwo-n wants to merge 4 commits intoApptiveDev:강지원from
zwo-n:feat/week-2
Open

Feat/week 2#19
zwo-n wants to merge 4 commits intoApptiveDev:강지원from
zwo-n:feat/week-2

Conversation

@zwo-n
Copy link
Copy Markdown

@zwo-n zwo-n commented Nov 7, 2025

변경점 👍

setter, optional 등 보안 및 캡슐화 취약점 보완
테스트 코드 작성

테스트 💻

SpringBootTest, MockMvc을 활용하여 테스트 진행하였음.

스크린샷 🖼

테스트 결과
스크린샷 2025-11-07 오후 5 43 41

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주차 수고하셨습니다!! 테스트 코드까지 아주 잘 구성하셨습니다!
도전해볼 점이 있다면, 테스트를 더욱 작게 쪼개어 하나의 기능마다 하나의 테스트를 할 수 있게 만들면 추후에 코드 리팩토링을 하더라도 바로바로 테스트할 수 있어서 좋습니다.
또한, 이러한 작은 테스트들을 먼저 작성해두고, 이 테스트를 통과하도록 코드를 짜는 TDD 방식을 사용해보시는 것도 추천드려요

@PatchMapping("/{commentId}")
public ResponseEntity<Comment> updateComment(
@PathVariable Long commentId,
@RequestBody Map<String, String> request
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Map을 DTO로 만들어서 사용하면 코드를 더욱 유연하게 작성할 수 있을 것 같아요!

}

@PostMapping
public Comment createComment(@PathVariable Long postId, @RequestBody Comment comment) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

RequestBody로 Comment를 바로 받게 되면, 필요없는 정보까지 받아내야해서 낭비가 될 수 있어요 (ex createAt은 사용자가 주어야하는 정보가 아니라, db가 자동으로 저장할 수 있는 정보) DTO를 만들어서 필요한 정보만을 받을 수 있도록 하면 좋을 것 같아요

import java.util.Map;

@RestController
@RequestMapping("/post/{postId}/comment")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

postId를 해당 컨트롤러 내의 모든 코드에서 사용할까요? 예를 들어, 댓글을 삭제할 때도 postId가 필요할까요?

Comment on lines +23 to +27
@JoinColumn(
name="post_id",
nullable = false,
foreignKey = @ForeignKey(name = "fk_diary_user_id_ref_user_id")
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

해당 코드에서 foreign key를 설정해둔 이유가 있을까요?

nullable = false,
foreignKey = @ForeignKey(name = "fk_diary_user_id_ref_user_id")
)
@JsonBackReference
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

위에서 Entity를 직접 사용하는 것에서 Dto를 사용하는 것으로 변경하면 해당 직렬화 어노테이션은 필요가 없어질 것입니당!!

import java.util.Optional;

@Service
public class PostService {
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 어노테이션을 사용하여 트랜잭션을 설정하는 것이 좋아요! 트랜잭션을 설정해야하는 이유는 무엇일까요?

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