Skip to content

[오소현] sprint6#97

Open
Oh-Sohyeon wants to merge 2 commits into
codeit-bootcamp-spring:오소현from
Oh-Sohyeon:오소현-sprint6

Hidden character warning

The head ref may contain hidden characters: "\uc624\uc18c\ud604-sprint6"
Open

[오소현] sprint6#97
Oh-Sohyeon wants to merge 2 commits into
codeit-bootcamp-spring:오소현from
Oh-Sohyeon:오소현-sprint6

Conversation

@Oh-Sohyeon
Copy link
Copy Markdown

요구사항

기본

  • API 명세 기준 Controller/Api 인터페이스 응답 타입 정리
  • PostgreSQL 데이터베이스 연결 설정 및 schema.sql 작성
  • Spring Data JPA, PostgreSQL 의존성 추가
  • BaseEntity, BaseUpdatableEntity 정의 및 Auditing 적용
  • Entity 연관관계 매핑 적용
  • cascade, orphanRemoval 적용
  • 기존 Repository를 JpaRepository 기반으로 변경
  • 서비스 레이어를 트랜잭션, 변경 감지, 지연 로딩 기준으로 수정
  • DTO 정의 및 Entity 직접 노출 최소화
  • MapStruct 기반 Mapper 컴포넌트 추가
  • BinaryContent 엔티티에서 bytes 제거
  • BinaryContentStorage 인터페이스 및 로컬 저장소 구현
  • BinaryContent 다운로드 API 추가
  • 메시지 목록 Slice 기반 페이징 적용

심화

  • N+1 발생 가능 지점 확인 및 EntityGraph, batch fetch, bulk query로 개선

주요 변경사항

  • 기존 File/JCF Repository 구조를 Spring Data JPA Repository로 변경했습니다.
  • Entity의 UUID 참조 필드를 JPA 연관관계 객체 참조로 변경하고, ERD 기준으로 관계 매핑을 적용했습니다.
  • Controller 응답에서 Entity를 직접 노출하지 않도록 DTO와 Mapper를 추가했습니다.
  • BinaryContent는 DB에 메타데이터만 저장하고, 실제 파일 데이터는 로컬 디스크 저장소에 저장하도록 분리했습니다.
  • /api/binaryContents/{binaryContentId}/download 다운로드 API를 추가했습니다.
  • 메시지 목록 조회를 50개 단위, 최신순 Slice 페이징 방식으로 변경했습니다.
  • 메시지/채널 조회 과정에서 발생할 수 있는 N+1 문제를 일부 개선했습니다.

연관관계 매핑 정리

엔티티 관계 다중성 방향성 부모-자식 관계 연관관계의 주인
User : UserStatus 1:1 양방향 부모: User, 자식: UserStatus UserStatus
User : BinaryContent(profile) 1:0..1 User → BinaryContent 단방향 부모: User, 자식: BinaryContent User
Channel : Message 1:N Message → Channel 단방향 부모: Channel, 자식: Message Message
User : Message(author) 1:N Message → User 단방향 부모: User, 자식: Message Message
User : ReadStatus 1:N ReadStatus → User 단방향 부모: User, 자식: ReadStatus ReadStatus
Channel : ReadStatus 1:N ReadStatus → Channel 단방향 부모: Channel, 자식: ReadStatus ReadStatus
Message : BinaryContent(attachments) 1:N Message → BinaryContent 단방향 부모: Message, 자식: BinaryContent Message

Entity 직접 노출 대신 DTO를 사용하는 이유

  • Entity 구조가 API 응답 구조에 직접 묶이는 문제를 줄일 수 있습니다.
  • 양방향 연관관계에서 JSON 직렬화 시 순환 참조가 발생하는 것을 방지할 수 있습니다.
  • password 같은 민감한 필드가 응답에 노출되는 위험을 줄일 수 있습니다.
  • 지연 로딩 필드를 Controller에서 직접 접근하는 문제를 줄이고, 필요한 데이터만 응답할 수 있습니다.

스크린샷

image

멘토에게

  • JPA 연관관계 매핑, DTO 변환, BinaryContent 저장소 분리, 메시지 페이징을 중심으로 수정했습니다.
  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

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.

1 participant