Skip to content

Conversation

@minwoo1999
Copy link
Member

@minwoo1999 minwoo1999 commented Aug 4, 2025

🔗 관련 이슈

📘 작업 유형

  • ✨ Feature (기능 추가)
  • 🐞 Bugfix (버그 수정)
  • 🔧 Refactor (코드 리팩토링)
  • ⚙️ Chore (환경 설정)
  • 📝 Docs (문서 작성 및 수정)
  • ✅ Test (기능 테스트)
  • 🎨 Style (코드 스타일 수정)

📙 작업 내역

  • UserBook 도메인에 readingRecordCount 필드 추가
  • 독서 기록 생성 시 해당 책의 readingRecordCount 증가 처리 로직 추가
  • UserBookEntityUserBookRepository 연동을 위한 필드 매핑 및 저장 처리 추가
  • UserBookInfoVO, UserBookResponse 등 응답 객체에 recordCount 필드 반영
  • 기존 도메인 서비스 내 UserBookInfoVO.newInstance 호출부 수정 (recordCount 전달)

🧪 테스트 내역

  • 도서에 독서 기록 추가 시 recordCount가 증가하는지 확인
  • 기존 기능 영향 없는지 확인
  • 엣지 케이스 테스트 완료

🎨 스크린샷 또는 시연 영상 (선택)

기능 설명 미리보기 기능 설명 미리보기
- - - -

✅ PR 체크리스트

  • 커밋 메시지가 명확합니다
  • PR 제목이 컨벤션에 맞습니다
  • 관련 이슈 번호를 작성했습니다
  • 기능이 정상적으로 작동합니다
  • 불필요한 코드를 제거했습니다

💬 추가 설명 or 리뷰 포인트

  • 독서 기록이 추가될 때만 recordCount가 증가하도록 되어 있습니다.
  • 추후 recordCount 일관성 유지를 위한 비즈니스 로직 점검 필요할 수 있습니다.

Summary by CodeRabbit

  • 신규 기능

    • 사용자 도서 정보에 기록 개수(recordCount) 표시가 추가되었습니다.
    • 독서 기록 응답에 저자(author) 정보가 포함됩니다.
  • 버그 수정

    • 없음
  • 기타 개선

    • 사용자 도서 및 독서 기록 관련 정보에 기록 개수와 저자 정보가 일관되게 반영되었습니다.
    • 내부 데이터 유효성 검증 및 예외 처리가 강화되었습니다.

@minwoo1999 minwoo1999 self-assigned this Aug 4, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 4, 2025

📝 Walkthrough

Walkthrough

UserBook 및 ReadingRecord 관련 도메인, DTO, 엔티티에 기록(레코드) 수 및 저자(author) 필드가 추가되었습니다. 이에 따라 관련 팩토리 메서드, 서비스, 엔티티, VO, DTO가 확장 및 수정되었으며, 일부 예외 처리 및 내부 로직이 보강되었습니다. 기타 코드 포맷팅 변경도 포함됩니다.

Changes

Cohort / File(s) Change Summary
UserBook recordCount/readingRecordCount 확장
domain/src/main/kotlin/org/yapp/domain/userbook/UserBook.kt, infra/src/main/kotlin/org/yapp/infra/userbook/entity/UserBookEntity.kt, domain/src/main/kotlin/org/yapp/domain/userbook/vo/UserBookInfoVO.kt, domain/src/main/kotlin/org/yapp/domain/userbook/UserBookDomainService.kt, apis/src/main/kotlin/org/yapp/apis/book/dto/response/UserBookResponse.kt
UserBook 및 관련 VO, DTO, Entity에 기록 수(readingRecordCount/recordCount) 필드 추가 및 관련 팩토리 메서드, 서비스, 변환 로직 확장.
ReadingRecord author 확장
domain/src/main/kotlin/org/yapp/domain/readingrecord/ReadingRecordDomainService.kt, domain/src/main/kotlin/org/yapp/domain/readingrecord/vo/ReadingRecordInfoVO.kt, apis/src/main/kotlin/org/yapp/apis/readingrecord/dto/response/ReadingRecordResponse.kt
ReadingRecord 관련 VO, DTO, 서비스에 저자(author) 필드 추가 및 관련 생성자, 팩토리, 변환 로직 수정.
Repository/Impl 포맷팅
domain/src/main/kotlin/org/yapp/domain/userbook/UserBookRepository.kt, infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/UserBookRepositoryImpl.kt
불필요한 공백 및 trailing comma 제거 등 코드 포맷팅 변경.

Sequence Diagram(s)

sequenceDiagram
    participant API
    participant UserBookDomainService
    participant UserBookRepository
    participant UserBookEntity

    API->>UserBookDomainService: upsertUserBook(), findUserBooksByDynamicCondition(), ...
    UserBookDomainService->>UserBookRepository: findById(), save(), 등
    UserBookRepository->>UserBookEntity: toDomain(), fromDomain()
    UserBookEntity-->>UserBookRepository: UserBook(readingRecordCount)
    UserBookRepository-->>UserBookDomainService: UserBook(readingRecordCount)
    UserBookDomainService-->>API: UserBookInfoVO(recordCount)
    API-->>Client: UserBookResponse(recordCount)
Loading
sequenceDiagram
    participant API
    participant ReadingRecordDomainService
    participant UserBookDomainService

    API->>ReadingRecordDomainService: createReadingRecord(), findReadingRecordById(), ...
    ReadingRecordDomainService->>UserBookDomainService: get userBook (for author, recordCount)
    ReadingRecordDomainService-->>API: ReadingRecordInfoVO(author)
    API-->>Client: ReadingRecordResponse(author)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Suggested labels

✨ feat

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BOOK-217-feature/#73

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63a9fd4 and 3387a7b.

📒 Files selected for processing (10)
  • apis/src/main/kotlin/org/yapp/apis/book/dto/response/UserBookResponse.kt (2 hunks)
  • apis/src/main/kotlin/org/yapp/apis/readingrecord/dto/response/ReadingRecordResponse.kt (2 hunks)
  • domain/src/main/kotlin/org/yapp/domain/readingrecord/ReadingRecordDomainService.kt (5 hunks)
  • domain/src/main/kotlin/org/yapp/domain/readingrecord/vo/ReadingRecordInfoVO.kt (3 hunks)
  • domain/src/main/kotlin/org/yapp/domain/userbook/UserBook.kt (4 hunks)
  • domain/src/main/kotlin/org/yapp/domain/userbook/UserBookDomainService.kt (2 hunks)
  • domain/src/main/kotlin/org/yapp/domain/userbook/UserBookRepository.kt (1 hunks)
  • domain/src/main/kotlin/org/yapp/domain/userbook/vo/UserBookInfoVO.kt (3 hunks)
  • infra/src/main/kotlin/org/yapp/infra/userbook/entity/UserBookEntity.kt (3 hunks)
  • infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/UserBookRepositoryImpl.kt (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-validation
🔇 Additional comments (10)
apis/src/main/kotlin/org/yapp/apis/book/dto/response/UserBookResponse.kt (1)

20-20: 새로운 recordCount 필드 추가 승인

recordCount 필드가 올바르게 추가되었고, 팩토리 메서드에서 적절히 매핑되고 있습니다. 도메인 모델과의 일관성을 유지하는 좋은 구현입니다.

Also applies to: 37-37

domain/src/main/kotlin/org/yapp/domain/readingrecord/vo/ReadingRecordInfoVO.kt (1)

18-18: author 필드 추가 승인

author 필드가 다른 선택적 필드들과 일관된 패턴으로 올바르게 추가되었습니다. newInstance 팩토리 메서드도 적절히 업데이트되었습니다.

Also applies to: 34-34, 48-48

infra/src/main/kotlin/org/yapp/infra/userbook/entity/UserBookEntity.kt (2)

69-71: readingRecordCount 필드 데이터베이스 매핑 승인

새로운 readingRecordCount 필드가 적절한 데이터베이스 제약조건(nullable = false)과 기본값(0)으로 올바르게 매핑되었습니다. protected setter 사용도 기존 패턴과 일치합니다.


83-83: 도메인 변환 메서드 업데이트 승인

toDomain() 메서드에 readingRecordCount 필드가 올바르게 포함되어 엔티티에서 도메인으로의 변환이 완전히 이루어집니다.

domain/src/main/kotlin/org/yapp/domain/userbook/vo/UserBookInfoVO.kt (1)

19-19: 독서 기록 수 필드 추가가 잘 구현되었습니다.

recordCount 필드 추가와 관련된 변경사항들이 일관성 있게 잘 적용되었습니다. 특히 검증 로직에서 음수 값을 방지하는 부분이 좋습니다.

Also applies to: 26-26, 35-35, 49-49

domain/src/main/kotlin/org/yapp/domain/userbook/UserBookDomainService.kt (1)

38-38: 일관된 매개변수 업데이트가 잘 이루어졌습니다.

모든 UserBookInfoVO.newInstance 호출에 readingRecordCount 매개변수가 일관되게 추가되어 새로운 필드가 올바르게 전파되고 있습니다.

Also applies to: 49-49, 57-57, 62-62

apis/src/main/kotlin/org/yapp/apis/readingrecord/dto/response/ReadingRecordResponse.kt (1)

42-45: 저자 필드 추가가 적절하게 구현되었습니다.

새로운 author 필드가 nullable 타입으로 적절히 추가되었고, Swagger 문서화와 매핑 로직이 올바르게 구현되었습니다.

Also applies to: 63-63

domain/src/main/kotlin/org/yapp/domain/userbook/UserBook.kt (1)

18-18: 독서 기록 수 추적 기능이 잘 구현되었습니다.

readingRecordCount 필드와 increaseReadingRecordCount() 메서드가 적절히 추가되었습니다. 불변성을 유지하면서 카운트를 증가시키는 방식이 도메인 모델의 설계 원칙에 부합합니다.

Also applies to: 27-29, 66-66, 81-81

domain/src/main/kotlin/org/yapp/domain/readingrecord/ReadingRecordDomainService.kt (2)

34-38: UserBook 조회 및 카운트 증가 로직이 잘 구현되었습니다.

독서 기록 생성 시 UserBook 존재 여부를 확인하고 카운트를 증가시키는 로직이 적절히 구현되었습니다. 예외 처리도 명시적으로 잘 되어 있습니다.

Also applies to: 61-61


63-70: 저자 필드 추가가 일관되게 적용되었습니다.

ReadingRecordInfoVO에 저자 정보를 포함하도록 모든 관련 메서드가 일관되게 업데이트되었습니다.

Also applies to: 95-97, 119-121

Comment on lines 63 to 70
return ReadingRecordInfoVO.newInstance(
readingRecord = savedReadingRecord,
emotionTags = tags.map { it.name },
bookTitle = userBook?.title,
bookPublisher = userBook?.publisher,
bookCoverImageUrl = userBook?.coverImageUrl
bookTitle = userBook.title,
bookPublisher = userBook.publisher,
bookCoverImageUrl = userBook.coverImageUrl,
author = userBook.author
)
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

성능 최적화 고려사항

createReadingRecord 메서드에서 이미 UserBook을 조회했으므로, ReadingRecordInfoVO.newInstance 호출 시 재조회하는 대신 이미 가져온 userBook 객체를 직접 사용하는 것이 더 효율적일 수 있습니다.

현재는 buildReadingRecordInfoVO 메서드 내부에서 UserBook을 다시 조회하고 있습니다. 다음과 같이 리팩터링을 고려해보세요:

return ReadingRecordInfoVO.newInstance(
    readingRecord = savedReadingRecord,
    emotionTags = tags.map { it.name },
-   bookTitle = userBook.title,
-   bookPublisher = userBook.publisher,
-   bookCoverImageUrl = userBook.coverImageUrl,
-   author = userBook.author
+   bookTitle = userBook.title,
+   bookPublisher = userBook.publisher,  
+   bookCoverImageUrl = userBook.coverImageUrl,
+   author = userBook.author
)

또는 buildReadingRecordInfoVO 메서드를 오버로드하여 이미 조회된 UserBook을 받도록 수정할 수 있습니다.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
domain/src/main/kotlin/org/yapp/domain/readingrecord/ReadingRecordDomainService.kt
around lines 63 to 70, the buildReadingRecordInfoVO method currently re-fetches
the UserBook even though it was already retrieved in createReadingRecord. To
optimize performance, refactor buildReadingRecordInfoVO to accept the already
fetched userBook as a parameter or overload it to do so, and use this passed
userBook directly instead of querying again.

Comment on lines +39 to +40


Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

불필요한 빈 줄 제거

인터페이스 끝에 추가된 빈 줄들이 불필요합니다. 코드 일관성을 위해 제거하는 것을 권장합니다.

-    
-    
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
}
🤖 Prompt for AI Agents
In domain/src/main/kotlin/org/yapp/domain/userbook/UserBookRepository.kt at
lines 39 to 40, there are unnecessary blank lines at the end of the interface.
Remove these extra blank lines to maintain code consistency and cleanliness.

Comment on lines +101 to +103
).apply {
this.readingRecordCount = userBook.readingRecordCount
}
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

도메인에서 엔티티로의 변환 로직 검증 필요

readingRecordCount가 apply 블록에서 설정되는 방식은 올바르지만, 이 카운트의 일관성 유지 방법을 확인해야 합니다. PR 목표에 따르면 현재는 읽기 기록 추가 시에만 증가하며, 향후 비즈니스 로직 검토가 필요하다고 명시되어 있습니다.

다음 사항들을 확인해 주세요:

  1. 읽기 기록 삭제 시 카운트 감소 로직이 구현되어 있는지
  2. 기존 데이터의 카운트 초기화 방법
  3. 카운트 불일치 발생 시 복구 방안

🏁 Script executed:

#!/bin/bash
# 읽기 기록 관련 increment/decrement 로직 확인
ast-grep --pattern 'incrementReadingRecordCount($_)'
ast-grep --pattern 'decrementReadingRecordCount($_)'

# ReadingRecord 삭제 관련 로직 확인  
rg -A 5 "delete.*ReadingRecord"

Length of output: 143


🏁 Script executed:

#!/bin/bash
# infra/src 및 도메인 계층 전반에서 readingRecordCount 키워드 검색
rg -n "readingRecordCount"

# 증감 메서드 명 확인
rg -n "incrementReadingRecordCount"
rg -n "decrementReadingRecordCount"

# 읽기 기록 추가/삭제 메서드 확인
rg -n "addReadingRecord"
rg -n "removeReadingRecord"

# DB 삭제 쿼리나 리포지토리 삭제 메서드 검색
rg -n "delete.*ReadingRecord"

Length of output: 1675


ReadingRecordCount 동기화 로직 보완 필요

UserBookEntityreadingRecordCount를 도메인에서 엔티티로 복사하는 부분은 정상적이나, 검색 결과 아래 내용이 확인되지 않았습니다.

삭제 시 감소 구현 부재

  • addReadingRecord()로 증가만 처리되고, 삭제할 때 readingRecordCount를 감소시키는 메서드(removeReadingRecord() 또는 decrement…)가 코드베이스에 없습니다.
  • 비즈니스에서 읽기 기록 삭제를 허용한다면, 도메인·엔티티 양쪽에 감소 로직을 반드시 추가해야 합니다.

기존 데이터 초기화 방안 미확인

  • DB 마이그레이션 또는 초기화 스크립트에서 기존 레코드의 reading_record_count 컬럼을 백필(backfill)했는지 확인이 필요합니다.
  • 컬럼 추가 시 기본값이 0으로 설정되었다면 이미 생성된 레코드는 별도 처리 없이 0으로 초기화되었는지 검증해주세요.

불일치 복구 전략 부재

  • 운영 중 카운트가 도메인·엔티티 간 불일치가 발생할 경우를 대비해, 정합성 체크 및 복구(예: 배치 작업, 스크립트)를 설계하고 문서화해야 합니다.

위 항목들을 반영하여 다음을 진행해주세요.

  1. 삭제 시 readingRecordCount-- 로직 추가
  2. DB 마이그레이션·백필 스크립트 검토/작성
  3. 정합성 체크 및 복구 플로우 정의
🤖 Prompt for AI Agents
In infra/src/main/kotlin/org/yapp/infra/userbook/entity/UserBookEntity.kt around
lines 101 to 103, the readingRecordCount is only incremented but lacks a
corresponding decrement method for when reading records are deleted. Add a
method like removeReadingRecord() to decrement readingRecordCount in both the
domain and entity layers. Additionally, review or create DB migration and
backfill scripts to ensure existing records have correct initial
readingRecordCount values. Finally, define and document a consistency check and
recovery process to handle any discrepancies between domain and entity counts
during operation.

Comment on lines +84 to +85


Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

불필요한 빈 줄 제거

클래스 끝에 추가된 빈 줄들이 불필요합니다. 코드 일관성을 위해 제거하는 것을 권장합니다.

-

 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
infra/src/main/kotlin/org/yapp/infra/userbook/repository/impl/UserBookRepositoryImpl.kt
at lines 84 to 85, there are unnecessary blank lines at the end of the class.
Remove these extra blank lines to maintain code consistency and cleanliness.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 4, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@minwoo1999 minwoo1999 merged commit a902846 into develop Aug 4, 2025
7 of 8 checks passed
@move-hoon move-hoon changed the title Book 217 feature/#73 feat: 내 서재에 기록 수 컬럼 추가 Aug 5, 2025
@move-hoon move-hoon deleted the BOOK-217-feature/#73 branch August 12, 2025 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BOOK-217/feat] 내서재에 기록 수 컬럼을 추가해요.

2 participants