feat: [NDGL-148] 유저 엔티티 소셜 로그인 필드 추가#78
Hidden character warning
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@domain/domain-service/src/main/java/com/yapp/ndgl/domain/user/service/UserDomainService.java`:
- Around line 39-48: createSocialUser currently calls
userRepository.save(UserMapper.toEntity(user)) without handling
concurrent-creation constraint violations, so a DataIntegrityViolationException
during save can map to 500 instead of 409; wrap the save call in a try/catch
inside createSocialUser, catch DataIntegrityViolationException, inspect the
cause chain for org.hibernate.exception.ConstraintViolationException or
SQLIntegrityConstraintViolationException (or the constraint name/message
referring to provider/provider_id), and convert it into a domain/API conflict
error (e.g., throw an ApiException or specific ConflictException that maps to
CommonErrorCode.DATA_INTEGRITY_VIOLATION / 409). Reference: createSocialUser,
User.createSocialUser, userRepository.save, UserEntity, ApiExceptionHandler,
CommonErrorCode.DATA_INTEGRITY_VIOLATION.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 78743c32-9d10-4e19-9062-fb774279629d
📒 Files selected for processing (6)
common/src/main/java/com/yapp/ndgl/common/type/SocialProvider.javadomain/domain-rdb/src/main/java/com/yapp/ndgl/domain/user/entity/UserEntity.javadomain/domain-rdb/src/main/java/com/yapp/ndgl/domain/user/repository/UserRepository.javadomain/domain-service/src/main/java/com/yapp/ndgl/domain/user/User.javadomain/domain-service/src/main/java/com/yapp/ndgl/domain/user/mapper/UserMapper.javadomain/domain-service/src/main/java/com/yapp/ndgl/domain/user/service/UserDomainService.java
| @Transactional | ||
| public User createSocialUser( | ||
| final SocialProvider provider, | ||
| final String providerId, | ||
| final String email) { | ||
| String nickname = UserNicknameGenerator.generate(); | ||
| User user = User.createSocialUser(provider, providerId, email, nickname); | ||
| UserEntity savedEntity = userRepository.save(UserMapper.toEntity(user)); | ||
| return UserMapper.toDomain(savedEntity); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# createSocialUser / findByProviderAndProviderId 호출부 확인
rg -nP -C5 '\b(createSocialUser|findByProviderAndProviderId)\s*\(' --type=java -g '!**/UserDomainService.java'Repository: YAPP-Github/NDGL-BE
Length of output: 2037
🏁 Script executed:
#!/bin/bash
rg -nP '\.createSocialUser\s*\(' --type=java
rg -nP '\.findByProviderAndProviderId\s*\(' --type=javaRepository: YAPP-Github/NDGL-BE
Length of output: 417
🏁 Script executed:
#!/bin/bash
# 1) 해당 서비스의 createSocialUser/중복선검사 흐름 확인
sed -n '1,140p' domain/domain-service/src/main/java/com/yapp/ndgl/domain/user/service/UserDomainService.java
# 2) DataIntegrityViolationException/ConstraintViolationException 예외 매핑 확인
rg -n --hidden --no-ignore-vcs 'DataIntegrityViolationException|ConstraintViolationException|CommonErrorCode\.DATA_INTEGRITY_VIOLATION' --type=java
# 3) 유니크 제약(provider, provider_id) 실제 어노테이션 확인
rg -n --hidden --no-ignore-vcs 'provider[_-]?provider_id|provider_id|providerId|`@UniqueConstraint`|uniqueConstraints\s*=' \
--type=java domain/domain-rdb/src/main/java/com/yapp/ndgl/domain/userRepository: YAPP-Github/NDGL-BE
Length of output: 5768
🏁 Script executed:
#!/bin/bash
# ApiExceptionHandler: DataIntegrityViolationException 처리 로직 확인
sed -n '130,210p' application/src/main/java/com/yapp/ndgl/application/common/exception/ApiExceptionHandler.java
# CommonErrorCode: DATA_INTEGRITY_VIOLATION의 상태코드/메시지 확인
rg -n "DATA_INTEGRITY_VIOLATION" -S application/src/main/java domain/src/main/javaRepository: YAPP-Github/NDGL-BE
Length of output: 3813
소셜 계정 중복 생성 시 예외 처리(409/500) 및 레이스 대응 확인 필요
UserEntity에 (provider, provider_id) 유니크 제약이 있고, createSocialUser는 별도 선검사 없이 바로 save를 수행하므로 동시 요청 시 DataIntegrityViolationException이 발생할 수 있습니다. 전역 ApiExceptionHandler는 DataIntegrityViolationException의 cause가 org.hibernate.exception.ConstraintViolationException일 때만 CommonErrorCode.DATA_INTEGRITY_VIOLATION로 409(CONFLICT) 처리하고, 그 외에는 500으로 떨어집니다. 레이스 상황에서 실제로 해당 cause가 항상 매핑되는지(또는 호출부/도메인에서 일관된 예외로 변환하는지) 확인이 필요합니다.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@domain/domain-service/src/main/java/com/yapp/ndgl/domain/user/service/UserDomainService.java`
around lines 39 - 48, createSocialUser currently calls
userRepository.save(UserMapper.toEntity(user)) without handling
concurrent-creation constraint violations, so a DataIntegrityViolationException
during save can map to 500 instead of 409; wrap the save call in a try/catch
inside createSocialUser, catch DataIntegrityViolationException, inspect the
cause chain for org.hibernate.exception.ConstraintViolationException or
SQLIntegrityConstraintViolationException (or the constraint name/message
referring to provider/provider_id), and convert it into a domain/API conflict
error (e.g., throw an ApiException or specific ConflictException that maps to
CommonErrorCode.DATA_INTEGRITY_VIOLATION / 409). Reference: createSocialUser,
User.createSocialUser, userRepository.save, UserEntity, ApiExceptionHandler,
CommonErrorCode.DATA_INTEGRITY_VIOLATION.
e4142af
into
feature/NDGL-147-Server-Spring-Security-도입
요약
소셜 로그인 정보를 도입해 소셜 사용자 생성/조회와 중복 방지를 지원하도록 도메인·DB·서비스를 확장합니다.
변경 내용
참고 사항
기존 데이터에서 (provider, providerId) 중복 가능성 확인 및 마이그레이션 준비가 필요합니다.
Summary by CodeRabbit
새로운 기능