Skip to content

Commit f9f646d

Browse files
HYH0804claude
andauthored
#86 [Fix] characterType null 체크 추가 - 미설정 유저 NPE 수정 (#88)
## #️⃣ 연관된 이슈 <!-- Ex) - #이슈번호 --> <!-- 연관된 이슈 번호를 링크 형태로 작성하세요 --> - #86 ## 📝 작업 내용 <!-- 이번 PR/이슈에서 실제 수행한 작업 내용을 작성하세요 --> - UserService: getCharacterType() NPE 방지, null이면 null 반환 - PerspectiveService: characterImageUrl 생성 시 characterType null 체크 (3군데) - PerspectiveCommentService: characterImageUrl 생성 시 characterType null 체크 (2군데) ## 📝 작업 내용 ### 🐛 Fix | 내용 | 파일 | |------|------| | `getCharacterType()` null 체크 추가 - null이면 null 반환 | `UserService.java` | | `characterImageUrl` 생성 시 `characterType` null 체크 (3군데) | `PerspectiveService.java` | | `characterImageUrl` 생성 시 `characterType` null 체크 (2군데) | `PerspectiveCommentService.java` | ## 📌 공유 사항 > 1. 회원가입(최초 로그인) 시 `character_type`은 NULL로 시작하며, 사용자가 프로필에서 캐릭터를 선택해야 설정됩니다. > 2. 기존 코드는 `character_type`이 항상 non-null임을 가정하고 있어, 캐릭터 미설정 유저가 관점/댓글 API 호출 시 NPE가 발생했습니다. > 3. `MypageService` 기존 처리 방식과 동일하게, null이면 null 그대로 응답에 내려보내도록 수정했습니다. ## ✅ 체크리스트 - [ x ] Reviewer에 팀원들을 선택했나요? - [ x ] Assignees에 본인을 선택했나요? - [ x ] 컨벤션에 맞는 Type을 선택했나요? - [ x ] Development에 이슈를 연동했나요? - [ x ] Merge 하려는 브랜치가 올바르게 설정되어 있나요? - [ x ] 컨벤션을 지키고 있나요? - [ x ] 로컬에서 실행했을 때 에러가 발생하지 않나요? - [ x ] 팀원들에게 PR 링크 공유를 했나요? ## 📸 스크린샷 > EC2 서버 로그에서 확인된 NPE: > `Cannot invoke "CharacterType.name()" because the return value of "UserProfile.getCharacterType()" is null` > `at UserService.findSummaryById(UserService.java:80)` ## 💬 리뷰 요구사항 > 1. 현재 캐릭터 미설정 유저에 대해 `characterType`, `characterImageUrl` 모두 null로 내려보내는 중 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 11c4f99 commit f9f646d

3 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/main/java/com/swyp/picke/domain/perspective/service/PerspectiveCommentService.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public CreateCommentResponse createComment(Long perspectiveId, Long userId, Crea
6161
perspective.incrementCommentCount();
6262

6363
UserSummary userSummary = userQueryService.findSummaryById(userId);
64-
String characterImageUrl = s3PresignedUrlService.generatePresignedUrl(
65-
CharacterType.from(userSummary.characterType()).getImageKey());
64+
String characterImageUrl = userSummary.characterType() != null
65+
? s3PresignedUrlService.generatePresignedUrl(CharacterType.from(userSummary.characterType()).getImageKey())
66+
: null;
6667
Long postVoteOptionId = voteService.findPostVoteOptionId(perspective.getBattle().getId(), userId);
6768
String stance = null;
6869
if (postVoteOptionId != null) {
@@ -96,8 +97,9 @@ public CommentListResponse getComments(Long perspectiveId, Long userId, String c
9697
.filter(c -> !c.isHidden())
9798
.map(c -> {
9899
UserSummary user = userQueryService.findSummaryById(c.getUser().getId());
99-
String characterImageUrl = s3PresignedUrlService.generatePresignedUrl(
100-
CharacterType.from(user.characterType()).getImageKey());
100+
String characterImageUrl = user.characterType() != null
101+
? s3PresignedUrlService.generatePresignedUrl(CharacterType.from(user.characterType()).getImageKey())
102+
: null;
101103
Long postVoteOptionId = voteService.findPostVoteOptionId(battleId, c.getUser().getId());
102104
String stance = null;
103105
if (postVoteOptionId != null) {

src/main/java/com/swyp/picke/domain/perspective/service/PerspectiveService.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ public PerspectiveDetailResponse getPerspectiveDetail(Long perspectiveId, Long u
5454
throw new CustomException(ErrorCode.PERSPECTIVE_NOT_FOUND);
5555
}
5656
UserSummary user = userQueryService.findSummaryById(perspective.getUser().getId());
57-
String characterImageUrl = s3PresignedUrlService.generatePresignedUrl(
58-
CharacterType.from(user.characterType()).getImageKey());
57+
String characterImageUrl = user.characterType() != null
58+
? s3PresignedUrlService.generatePresignedUrl(CharacterType.from(user.characterType()).getImageKey())
59+
: null;
5960
BattleOption option = perspective.getOption();
6061
boolean isLiked = perspectiveLikeRepository.existsByPerspectiveAndUserId(perspective, userId);
6162
return new PerspectiveDetailResponse(
@@ -123,8 +124,9 @@ public PerspectiveListResponse getPerspectives(Long battleId, Long userId, Strin
123124
List<PerspectiveListResponse.Item> items = perspectives.stream()
124125
.map(p -> {
125126
UserSummary user = userQueryService.findSummaryById(p.getUser().getId());
126-
String characterImageUrl = s3PresignedUrlService.generatePresignedUrl(
127-
CharacterType.from(user.characterType()).getImageKey());
127+
String characterImageUrl = user.characterType() != null
128+
? s3PresignedUrlService.generatePresignedUrl(CharacterType.from(user.characterType()).getImageKey())
129+
: null;
128130
BattleOption option = p.getOption();
129131
boolean isLiked = perspectiveLikeRepository.existsByPerspectiveAndUserId(p, userId);
130132
return new PerspectiveListResponse.Item(
@@ -171,8 +173,9 @@ public MyPerspectiveResponse getMyPerspective(Long battleId, Long userId) {
171173
.orElseThrow(() -> new CustomException(ErrorCode.PERSPECTIVE_NOT_FOUND));
172174

173175
UserSummary user = userQueryService.findSummaryById(userId);
174-
String characterImageUrl = s3PresignedUrlService.generatePresignedUrl(
175-
CharacterType.from(user.characterType()).getImageKey());
176+
String characterImageUrl = user.characterType() != null
177+
? s3PresignedUrlService.generatePresignedUrl(CharacterType.from(user.characterType()).getImageKey())
178+
: null;
176179
BattleOption option = perspective.getOption();
177180
boolean isLiked = perspectiveLikeRepository.existsByPerspectiveAndUserId(perspective, userId);
178181

src/main/java/com/swyp/picke/domain/user/service/UserService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public UserSummary findSummaryById(Long userId) {
7777
User user = userRepository.findById(userId)
7878
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
7979
UserProfile profile = findUserProfile(user.getId());
80-
return new UserSummary(user.getUserTag(), profile.getNickname(), profile.getCharacterType().name());
80+
String characterType = profile.getCharacterType() != null ? profile.getCharacterType().name() : null;
81+
return new UserSummary(user.getUserTag(), profile.getNickname(), characterType);
8182
}
8283

8384
public User findCurrentUser() {

0 commit comments

Comments
 (0)