Skip to content

Conversation

@joyewon0705
Copy link
Collaborator

📌 개요

  • board 도메인을 post, comment 단위로 구조를 세분화하고,
  • 엔티티 간 연관관계 편의 메서드 및 정적 팩토리 메서드를 도입했습니다.
  • 테스트 디렉토리 구조 또한 동일하게 분리 및 경로를 수정했습니다.

🔨 작업 내용

1. 패키지 구조 리팩토링

  • domain/boarddomain/board/post, domain/board/comment로 세분화
  • controller/docs, repository/custom 구조로 정리
  • 테스트(src/test/java) 디렉토리도 동일한 구조로 리네임

2. 엔티티 개선 (관계 및 비즈니스 로직 보강)

🔹 Post

  • User와의 연관관계에 nullable=false 적용
  • 댓글, 좋아요, 북마크, 카테고리 매핑에 대한 편의 메서드 추가
  • updateCategories() 개선 및 중복 매핑 방지
  • likeCount, bookmarkCount, commentCount 관련 메서드 문서화

🔹 Comment

  • nullable=false 제약 및 columnDefinition="TEXT" 추가
  • createRoot(), createChild() 정적 팩토리 메서드 추가
  • addLike(), removeLike() 등 연관관계 편의 메서드 추가
  • increaseLikeCount(), decreaseLikeCount() 보강

🔹 PostLike, PostBookmark, CommentLike, PostCategoryMapping

  • @UniqueConstraint 추가로 중복 방지
  • 생성자에서 양방향 연관관계 자동 연결 (post.addLike(this) 등)

🔹 User

  • 게시글, 댓글, 좋아요, 북마크, 댓글 좋아요 관련 add/remove 편의 메서드 추가
  • null-safe 초기화(if (this.posts == null) this.posts = new ArrayList<>();)

3. Service 계층 보완

  • 삭제/취소 로직(deletePost, deleteComment, cancelLikeComment, 등)에
    연관관계 해제 로직(user.removePost(), comment.removeLike()) 추가
  • CommentService.createComment()Comment.createRoot() 사용하도록 수정
  • DevInitData의 샘플 데이터 생성 시에도 팩토리 메서드 사용

4. 테스트 코드 전체 수정

  • 모든 엔티티 생성부에서 new Post(user, title, content, null) 형태로 수정
  • 댓글 생성 시 Comment.createRoot(), Comment.createChild() 방식으로 변경
  • PostCategory 생성 시 CategoryType 명시 (new PostCategory("공지사항", CategoryType.SUBJECT))
  • 전체 테스트 케이스 리팩토링 및 일관성 확보

🔗 관련 이슈

Closes #{이슈 번호}

📝 참고 사항

  • 이후 PostRepositoryImpl 및 CommentRepositoryImpl의 QueryDSL 최적화 예정
  • Post와 Comment 모두 양방향 관계를 가지므로, 추후 도메인 이벤트 처리 시 주의 필요

✅ 체크리스트

  • 기능 동작 확인
  • 테스트 코드 작성
  • 문서/주석 추가 및 최신화

@github-actions github-actions bot changed the title Refactor: board 도메인 구조 및 엔티티 개선 Refactor: board 도메인 구조 및 엔티티 개선 (#212) Oct 11, 2025
@joyewon0705 joyewon0705 force-pushed the Refactor/212 branch 2 times, most recently from c6d939c to 1b74e7c Compare October 11, 2025 06:57
@joyewon0705 joyewon0705 force-pushed the Refactor/212 branch 3 times, most recently from ef68aef to 545247b Compare October 11, 2025 08:39
@joyewon0705 joyewon0705 merged commit c209ba7 into dev Oct 11, 2025
3 checks passed
@github-actions github-actions bot deleted the Refactor/212 branch October 11, 2025 09:21
@joyewon0705 joyewon0705 restored the Refactor/212 branch October 11, 2025 09:21
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.

4 participants