Skip to content

Commit

Permalink
[FIX] 유저 정보 조회시 에러 수정 (#80)
Browse files Browse the repository at this point in the history
* fix : 유저 정보 조회시 Profile의 Null 처리 #79

* refactor : Optional 사용하여 null 처리 #79
  • Loading branch information
bongsh0112 authored Nov 3, 2023
1 parent b114bea commit bc3693c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import tify.server.api.config.security.SecurityUtils;
import tify.server.api.question.model.response.RetrieveCategoryIsAnsweredDTO;
Expand All @@ -16,6 +17,7 @@
import tify.server.domain.domains.user.domain.DetailCategory;
import tify.server.domain.domains.user.domain.SmallCategory;

@Slf4j
@UseCase
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand Down Expand Up @@ -47,6 +49,7 @@ public List<RetrieveCategoryIsAnsweredDTO> retrieveIsAnsweredBySmallCategory() {
.filter(category -> category.getSmallCategory().equals(smallCategory))
.toList()
.size(); // smallCategory와 같은 smallCategory를 가지는 detailCategory의 개수

categoryIsAnsweredDTOS.add(
RetrieveCategoryIsAnsweredDTO.of(
smallCategory, userAnswerCategorySize == size));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class UserController {
private final RetrieveUserListUseCase retrieveUserListUseCase;
private final RetrieveMutualFriendsUseCase retrieveMutualFriendsUseCase;

// userId를 pathvariable로 받아서 그 해당 유저의 profile 정보를 리턴하기.
@Operation(summary = "유저 정보 조회")
@GetMapping("/{userId}")
public UserProfileVo getUserProfileInfo(@PathVariable Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import tify.server.domain.common.vo.UserInfoVo;
import tify.server.domain.common.vo.UserProfileVo;
import tify.server.domain.domains.user.adaptor.UserAdaptor;
import tify.server.domain.domains.user.domain.User;

@UseCase
@RequiredArgsConstructor
Expand All @@ -18,8 +17,7 @@ public class UserInfoUseCase {
private final UserAdaptor userAdaptor;

public UserProfileVo execute(Long userId) {
User user = userAdaptor.query(userId);
return user.toUserProfileVo();
return userAdaptor.query(userId).toUserProfileVo();
}

public UserInfoVo executeByToken() {
Expand Down
28 changes: 22 additions & 6 deletions Domain/src/main/java/tify/server/domain/common/vo/UserInfoVo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


import java.time.LocalDateTime;
import java.util.Optional;
import lombok.Builder;
import lombok.Getter;
import tify.server.domain.domains.user.domain.Gender;
import tify.server.domain.domains.user.domain.Profile;
import tify.server.domain.domains.user.domain.User;
import tify.server.domain.domains.user.domain.UserOnBoardingStatus;

@Getter
@Builder
Expand Down Expand Up @@ -33,14 +36,27 @@ public class UserInfoVo {
public static UserInfoVo from(User user) {
return UserInfoVo.builder()
.id(user.getId())
.userName(user.getProfile().getUserName())
.userName(
Optional.ofNullable(user.getProfile())
.map(Profile::getUserName)
.orElse(null))
.userId(user.getUserId())
.imageUrl(user.getProfile().getThumbNail())
.birth(user.getProfile().getBirth())
.job(user.getProfile().getJob())
.imageUrl(
Optional.ofNullable(user.getProfile())
.map(Profile::getThumbNail)
.orElse(null))
.birth(Optional.ofNullable(user.getProfile()).map(Profile::getBirth).orElse(null))
.job(Optional.ofNullable(user.getProfile()).map(Profile::getJob).orElse(null))
.createdAt(user.getCreatedAt().toLocalDateTime())
.gender(Gender.toValue(user.getProfile().getGender()))
.onBoardingStatus(user.getOnBoardingStatus().getName())
.gender(
Gender.toValue(
Optional.ofNullable(user.getProfile())
.map(Profile::getGender)
.orElse(null)))
.onBoardingStatus(
Optional.ofNullable(user.getOnBoardingStatus())
.map(UserOnBoardingStatus::getName)
.orElse(null))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package tify.server.domain.common.vo;


import java.util.Optional;
import lombok.Builder;
import lombok.Getter;
import tify.server.domain.domains.user.domain.Gender;
import tify.server.domain.domains.user.domain.Profile;
import tify.server.domain.domains.user.domain.User;
import tify.server.domain.domains.user.domain.UserOnBoardingStatus;

@Getter
@Builder
Expand All @@ -28,14 +31,27 @@ public class UserProfileVo {

public static UserProfileVo from(User user) {
return UserProfileVo.builder()
.userName(user.getProfile().getUserName())
.userName(
Optional.ofNullable(user.getProfile())
.map(Profile::getUserName)
.orElse(null))
.userId(user.getUserId())
.email(user.getProfile().getEmail())
.thumbnail(user.getProfile().getThumbNail())
.birth(user.getProfile().getBirth())
.job(user.getProfile().getJob())
.gender(Gender.toValue(user.getProfile().getGender()))
.onBoardingStatus(user.getOnBoardingStatus().getName())
.email(Optional.ofNullable(user.getProfile()).map(Profile::getEmail).orElse(null))
.thumbnail(
Optional.ofNullable(user.getProfile())
.map(Profile::getThumbNail)
.orElse(null))
.birth(Optional.ofNullable(user.getProfile()).map(Profile::getBirth).orElse(null))
.job(Optional.ofNullable(user.getProfile()).map(Profile::getJob).orElse(null))
.gender(
Gender.toValue(
Optional.ofNullable(user.getProfile())
.map(Profile::getGender)
.orElse(null)))
.onBoardingStatus(
Optional.ofNullable(user.getOnBoardingStatus())
.map(UserOnBoardingStatus::getName)
.orElse(null))
.build();
}
}

0 comments on commit bc3693c

Please sign in to comment.