-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 약관동의여부 API 기능개발 #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... 📒 Files selected for processing (2)
📝 Walkthrough""" Walkthrough사용자의 약관 동의 상태를 저장 및 갱신하는 API가 추가되었습니다. 이를 위해 도메인, 인프라, DTO, 서비스, 컨트롤러 계층에 Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthController
participant AuthUseCase
participant UserAuthService
participant UserDomainService
participant UserRepository
participant UserEntity
Client->>AuthController: PUT /api/v1/auth/terms-agreement (TermsAgreementRequest)
AuthController->>AuthUseCase: updateTermsAgreement(userId, termsAgreed)
AuthUseCase->>UserAuthService: updateTermsAgreement(userId, termsAgreed)
UserAuthService->>UserDomainService: updateTermsAgreement(userId, termsAgreed)
UserDomainService->>UserRepository: findById(userId)
UserRepository-->>UserDomainService: UserEntity
UserDomainService->>UserEntity: update termsAgreed
UserDomainService->>UserRepository: save(UserEntity)
UserDomainService-->>UserAuthService: UserProfileVO
UserAuthService-->>AuthUseCase: UserProfileResponse
AuthUseCase-->>AuthController: UserProfileResponse
AuthController-->>Client: 200 OK (UserProfileResponse)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~45 minutes Suggested labels
Suggested reviewers
Tip CodeRabbit can enforce grammar and style rules using `languagetool`.Configure ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (13)
apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthController.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthControllerApi.kt(2 hunks)apis/src/main/kotlin/org/yapp/apis/auth/dto/request/TermsAgreementRequest.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/dto/response/UserProfileResponse.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/service/UserAuthService.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/auth/usecase/AuthUseCase.kt(1 hunks)apis/src/main/kotlin/org/yapp/apis/book/service/UserBookService.kt(3 hunks)domain/src/main/kotlin/org/yapp/domain/user/User.kt(7 hunks)domain/src/main/kotlin/org/yapp/domain/user/UserDomainService.kt(1 hunks)domain/src/main/kotlin/org/yapp/domain/user/vo/UserProfileVO.kt(2 hunks)domain/src/main/kotlin/org/yapp/domain/userbook/UserBookDomainService.kt(2 hunks)infra/src/main/kotlin/org/yapp/infra/common/BaseTimeEntity.kt(1 hunks)infra/src/main/kotlin/org/yapp/infra/user/entity/UserEntity.kt(4 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 (24)
apis/src/main/kotlin/org/yapp/apis/auth/usecase/AuthUseCase.kt (1)
58-61: 새로운 약관 동의 업데이트 메서드가 올바르게 구현되었습니다.트랜잭션 어노테이션이 적절히 적용되었고, 서비스 계층으로의 위임이 깔끔하게 처리되었습니다. 기존 메서드들과 일관된 패턴을 따르고 있습니다.
apis/src/main/kotlin/org/yapp/apis/book/service/UserBookService.kt (3)
21-32: 메서드 본문 리팩터링이 적절히 수행되었습니다.단일 표현식 함수에서 명시적인 블록 본문으로 변경하여 코드 가독성과 디버깅 편의성이 향상되었습니다. 기능적 동작은 동일하게 유지됩니다.
42-47: 일관된 코드 스타일로 리팩터링되었습니다.중간 변수를 사용한 명시적 매핑 방식으로 변경하여 코드의 명확성이 개선되었습니다.
55-57: 매핑 로직이 명확하게 개선되었습니다.페이지 결과를 중간 변수에 할당한 후 매핑하는 방식으로 변경하여 코드 가독성이 향상되었습니다.
domain/src/main/kotlin/org/yapp/domain/userbook/UserBookDomainService.kt (3)
39-41: 매핑 스타일이 일관되게 개선되었습니다.중간 변수와 람다 표현식을 사용한 명시적 매핑 방식으로 변경하여 코드 일관성과 가독성이 향상되었습니다.
49-51: 페이지 매핑 로직이 명확해졌습니다.페이지 결과를 중간 변수에 할당한 후 매핑하는 방식으로 코드의 명확성이 개선되었습니다.
57-59: 컬렉션 매핑이 일관된 스타일로 개선되었습니다.중간 변수를 활용한 명시적 매핑 방식으로 변경하여 코드베이스 전반의 일관성이 향상되었습니다.
apis/src/main/kotlin/org/yapp/apis/auth/service/UserAuthService.kt (1)
24-28: 약관 동의 업데이트 서비스 메서드가 올바르게 구현되었습니다.사용자 존재 여부 검증을 먼저 수행한 후 도메인 서비스로 위임하는 적절한 패턴을 따르고 있습니다. 기존 서비스 메서드들과 일관된 구조를 유지합니다.
domain/src/main/kotlin/org/yapp/domain/user/UserDomainService.kt (1)
73-79: 도메인 서비스 메서드 검증 완료 및 승인User 엔터티의
updateTermsAgreement메서드가
domain/src/main/kotlin/org/yapp/domain/user/User.kt에 아래와 같이 올바르게 구현되어 있습니다:fun updateTermsAgreement(termsAgreed: Boolean): User { return this.copy(termsAgreed = termsAgreed) }따라서
UserDomainService.updateTermsAgreement구현은
- 사용자 조회 및 예외 처리
- 엔터티 불변성(copy) 유지
- 저장 및 VO 변환 패턴
모두 적절히 따르고 있으므로 변경 사항을 승인합니다.
apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthController.kt (2)
8-8: 새로운 DTO import가 적절하게 추가되었습니다.TermsAgreementRequest import가 올바르게 추가되어 새로운 API 엔드포인트에서 사용할 수 있습니다.
48-55: 약관 동의 업데이트 엔드포인트가 올바르게 구현되었습니다.PUT 메서드를 사용한 RESTful 설계가 적절하며, 인증된 사용자와 검증된 요청 본문을 받아 처리하는 구조가 좋습니다. 기존 컨트롤러 패턴과 일관성을 유지하고 있습니다.
domain/src/main/kotlin/org/yapp/domain/user/vo/UserProfileVO.kt (2)
10-11: 약관 동의 필드가 적절하게 추가되었습니다.Boolean 타입의 termsAgreed 필드가 생성자 매개변수로 올바르게 추가되었습니다. Boolean 값은 별도의 검증이 필요하지 않으므로 현재 구현이 적절합니다.
26-27: 팩토리 메서드가 새로운 필드를 올바르게 매핑합니다.newInstance 메서드에서 User 도메인 객체의 termsAgreed 속성을 UserProfileVO로 올바르게 매핑하고 있습니다.
apis/src/main/kotlin/org/yapp/apis/auth/dto/response/UserProfileResponse.kt (2)
38-42: Swagger 문서화가 잘 구현된 새로운 필드입니다.termsAgreed 필드가 적절한 설명과 예시와 함께 추가되었습니다. API 문서화가 명확하여 API 사용자가 필드의 목적을 쉽게 이해할 수 있습니다.
50-51: 응답 매핑이 올바르게 구현되었습니다.UserProfileVO에서 UserProfileResponse로의 termsAgreed 필드 매핑이 정확하게 구현되어 있습니다.
infra/src/main/kotlin/org/yapp/infra/common/BaseTimeEntity.kt (2)
17-17: lateinit 초기화 문제가 적절하게 해결되었습니다.
createdAt필드에 기본값을 설정하여UninitializedPropertyAccessException을 방지합니다. JPA Auditing이 실제 값을 설정하므로 이 기본값은 안전한 fallback 역할을 합니다.
22-22: updatedAt 필드의 초기화가 올바르게 수정되었습니다.lateinit 사용을 제거하고 기본값으로 초기화하여 런타임 오류를 방지합니다.
@LastModifiedDate어노테이션이 있어 JPA Auditing이 적절한 시점에 값을 업데이트할 것입니다.apis/src/main/kotlin/org/yapp/apis/auth/controller/AuthControllerApi.kt (2)
14-14: 새로운 import 추가가 적절합니다.
PutMapping과TermsAgreementRequestimport가 새로운 약관 동의 엔드포인트를 위해 올바르게 추가되었습니다.Also applies to: 17-17
111-130: 약관 동의 업데이트 API 인터페이스가 잘 설계되었습니다.PUT 메서드를 사용한 RESTful 설계, 적절한 OpenAPI 문서화(200, 404 응답 코드), 그리고
@Valid와@AuthenticationPrincipal어노테이션 사용이 모두 베스트 프랙티스를 따르고 있습니다.infra/src/main/kotlin/org/yapp/infra/user/entity/UserEntity.kt (3)
40-40: 기본값 설정이 적절합니다.약관 동의 상태의 기본값을
false로 설정한 것이 합리적입니다. 사용자는 명시적으로 동의해야 합니다.
68-68: 도메인 변환 메서드가 일관성 있게 업데이트되었습니다.
toDomain()과fromDomain()메서드 모두에서termsAgreed필드가 올바르게 처리되어 엔티티와 도메인 모델 간의 일관성을 유지합니다.Also applies to: 83-83
56-58: 데이터베이스 컬럼 매핑 및 마이그레이션 검증 요청
매핑은 올바르며terms_agreed컬럼도nullable = false로 설정되어 있습니다.
다만, 마이그레이션 스크립트(예:src/main/resources/db/migration하위의.sql,.yml,.yaml파일)에서 기존 레코드에 대해terms_agreed컬럼의 기본값이 설정되었는지 수동으로 확인해주세요.
- 마이그레이션 파일에
terms_agreed컬럼 추가 및 기본값(default) 지정 여부 점검domain/src/main/kotlin/org/yapp/domain/user/User.kt (2)
44-48: 불변 객체 패턴을 잘 따른 업데이트 메서드입니다.
copy()메서드를 사용하여 불변성을 유지하면서 약관 동의 상태를 업데이트하는 것이 도메인 모델의 일관성을 보장합니다.
56-57: 팩토리 메서드들이 일관성 있게 업데이트되었습니다.모든 팩토리 메서드(
create,createWithRole,reconstruct)에서termsAgreed매개변수가 기본값false와 함께 적절히 추가되어 기존 코드와의 호환성을 유지합니다.Also applies to: 66-67, 78-79, 88-89, 101-101, 114-114
apis/src/main/kotlin/org/yapp/apis/auth/dto/request/TermsAgreementRequest.kt
Show resolved
Hide resolved
| data class TermsAgreementRequest private constructor( | ||
| @Schema(description = "Whether the user agrees to the terms of service", example = "true", required = true) | ||
| val termsAgreed: Boolean? = null | ||
|
|
||
|
|
||
| ) { | ||
| fun validTermsAgreed(): Boolean = termsAgreed!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null 안전성 문제와 검증 로직을 개선해야 합니다.
현재 구현에는 심각한 문제가 있습니다:
termsAgreed필드가 nullable이지만 적절한 검증 어노테이션이 없습니다validTermsAgreed()메서드에서!!연산자로 강제 언래핑하면 NullPointerException이 발생할 수 있습니다
다음과 같이 수정하는 것을 권장합니다:
+import jakarta.validation.constraints.NotNull
@Schema(description = "Request to update terms agreement status")
-data class TermsAgreementRequest private constructor(
+data class TermsAgreementRequest(
- @Schema(description = "Whether the user agrees to the terms of service", example = "true", required = true)
- val termsAgreed: Boolean? = null
+ @field:NotNull(message = "약관 동의 여부는 필수입니다")
+ @Schema(description = "Whether the user agrees to the terms of service", example = "true", required = true)
+ val termsAgreed: Boolean?
-
-
-) {
- fun validTermsAgreed(): Boolean = termsAgreed!!
-}
+)그리고 컨트롤러에서는 request.termsAgreed!! 대신 request.termsAgreed (검증이 보장되므로)를 사용하세요.
🤖 Prompt for AI Agents
In apis/src/main/kotlin/org/yapp/apis/auth/dto/request/TermsAgreementRequest.kt
around lines 7 to 13, the termsAgreed field is nullable without validation, and
validTermsAgreed() uses !! which risks NullPointerException. Fix this by making
termsAgreed non-nullable and adding appropriate validation annotations to ensure
it is always provided. Then update validTermsAgreed() to safely return the value
without forced unwrapping. Also, adjust controller code to use
request.termsAgreed directly without !! since validation guarantees non-null.
| val providerType: ProviderType, | ||
| val providerId: ProviderId, | ||
| val role: Role, | ||
| val termsAgreed: Boolean = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
도메인 모델에 약관 동의 필드가 적절히 추가되었습니다.
기본값 false로 설정하여 명시적 동의가 필요하도록 한 것이 올바른 설계입니다.
클래스 문서화 주석(19-22줄)에 새로 추가된 termsAgreed 속성에 대한 설명을 추가하는 것을 권장합니다:
* @property role The roles of the user (e.g., USER, ADMIN).
+* @property termsAgreed Whether the user has agreed to the terms and conditions.
* @property createdAt The timestamp when the user was created.📝 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.
| val termsAgreed: Boolean = false, | |
| * @property role The roles of the user (e.g., USER, ADMIN). | |
| * @property termsAgreed Whether the user has agreed to the terms and conditions. | |
| * @property createdAt The timestamp when the user was created. |
🤖 Prompt for AI Agents
In domain/src/main/kotlin/org/yapp/domain/user/User.kt at line 31, the new field
termsAgreed is correctly added with a default value of false. To complete this
update, add a description of the termsAgreed property to the class documentation
comments between lines 19 and 22, explaining its purpose as indicating whether
the user has explicitly agreed to the terms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minwoo1999 요거 주석 달면 좋을 거 같아요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
6ed277f to
a547b7e
Compare
move-hoon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 민우님~~
사소한 부분 몇개 코멘트 남겼습니다!
로직적으로는 수정할 부분이 없는거 같아서 어푸르브 했습니다~
| @Schema(description = "Whether the user agrees to the terms of service", example = "true", required = true) | ||
| val termsAgreed: Boolean? = null | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid 로직이 빠진 것 같아요!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid validTermsAgreed() 여기있어요!!~
| upsertUserBookRequest.bookCoverImageUrl, | ||
| upsertUserBookRequest.status | ||
| ) | ||
| fun upsertUserBook(upsertUserBookRequest: UpsertUserBookRequest): UserBookResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(사소) UpsertUserBookRequest의 필드에도 validation을 하면 좋을 것 같다는 생각이 듭니다!!
| val providerType: ProviderType, | ||
| val providerId: ProviderId, | ||
| val role: Role, | ||
| val termsAgreed: Boolean = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@minwoo1999 요거 주석 달면 좋을 거 같아요~
|


🔗 관련 이슈
Close [BOOK-162/feat] 약관동의 여부를 확인하는 API를 작성합니다. #50
📘 작업 유형
✨ Feature (기능 추가)
🐞 Bugfix (버그 수정)
📙 작업 내역
이번 PR은 사용자의 약관 동의 상태를 관리하는 새로운 기능을 추가하고, 기존
BaseTimeEntity의lateinit오류를 해결합니다.API 계층 (
apis모듈):사용자의 약관 동의 상태를 업데이트하는 새로운
PUT /api/v1/auth/terms-agreement엔드포인트를 추가했습니다.UserProfileResponse에termsAgreed필드를 추가하여 약관 동의 여부를 응답에 포함하도록 수정했습니다.약관 동의 상태 업데이트 요청을 위한
TermsAgreementRequestDTO를 정의했습니다.AuthController와UserAuthService에 약관 동의 업데이트 및 사용자 프로필 조회 시 약관 동의 상태를 처리하는 로직을 구현했습니다.도메인 계층 (
domain모듈):User도메인 엔티티에termsAgreed불리언 필드를 추가하고, 해당 필드를 업데이트하는updateTermsAgreement메서드를 구현했습니다.UserProfileVO에termsAgreed필드를 반영하여 사용자 프로필 정보에 약관 동의 여부가 포함되도록 했습니다.UserDomainService에 사용자의 약관 동의 상태를 업데이트하고 영속화하는 로직을 추가했습니다.인프라 계층 (
infra모듈):데이터베이스의
UserEntity에terms_agreed컬럼을 추가했습니다.BaseTimeEntity에서createdAt과updatedAt필드의lateinit오류를 해결하기 위해 초기값을 직접 할당하여, 객체 생성 시 항상 유효한 값이 설정되도록 했습니다.🧪 테스트 내역
브라우저/기기에서 동작 확인 (API 테스트 도구 사용)
엣지 케이스 테스트 완료 (예: 약관 동의 요청 시 값이
null이거나 유효하지 않은 경우)기존 기능 영향 없음 (기존 사용자 프로필 조회 및 인증/인가 흐름 정상 작동 확인)
🎨 스크린샷 또는 시연 영상 (선택)
✅ PR 체크리스트
커밋 메시지가 명확합니다
PR 제목이 컨벤션에 맞습니다
관련 이슈 번호를 작성했습니다
기능이 정상적으로 작동합니다
불필요한 코드를 제거했습니다
💬 추가 설명 or 리뷰 포인트 (선택)
이번 변경 사항을 통해 서비스 약관 동의 여부를 명확히 관리할 수 있게 되었으며, 법적 준수 사항에도 도움이 될 것입니다.
BaseTimeEntity수정은 애플리케이션의 안정성을 높이는 중요한 개선 사항입니다. 특히, 새로 추가된 API 엔드포인트의 보안 및 예외 처리 로직, 그리고 도메인 계층에서의 비즈니스 로직을 중점적으로 검토해주시면 감사하겠습니다.Summary by CodeRabbit
신규 기능
버그 수정
리팩터링
스타일
기타