Skip to content

Commit

Permalink
refactor: getById 메서드 사용하도록 리팩터링 (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdkdhoho committed Feb 8, 2024
1 parent 7770623 commit ae9760e
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.listywave.user.application.service;

import static com.listywave.common.exception.ErrorCode.NOT_FOUND;

import com.listywave.auth.application.domain.JwtManager;
import com.listywave.common.exception.CustomException;
import com.listywave.common.util.UserUtil;
import com.listywave.list.application.domain.CategoryType;
import com.listywave.list.application.domain.Lists;
Expand All @@ -16,7 +13,6 @@
import com.listywave.user.repository.follow.FollowRepository;
import com.listywave.user.repository.user.UserRepository;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -32,18 +28,17 @@ public class UserService {

@Transactional(readOnly = true)
public UserInfoResponse getUserInfo(Long userId, String accessToken) {
Optional<User> found = userRepository.findById(userId);
User foundUser = found.orElseThrow(() -> new CustomException(NOT_FOUND));
User user = userRepository.getById(userId);

if (isSignedIn(accessToken)) {
return UserInfoResponse.of(foundUser, false, false);
return UserInfoResponse.of(user, false, false);
}

Long loginUserId = jwtManager.read(accessToken);
if (foundUser.isSame(loginUserId)) {
return UserInfoResponse.of(foundUser, false, true);
if (user.isSame(loginUserId)) {
return UserInfoResponse.of(user, false, true);
}
return UserInfoResponse.of(foundUser, false, false);
return UserInfoResponse.of(user, false, false);
}

private boolean isSignedIn(String accessToken) {
Expand Down

0 comments on commit ae9760e

Please sign in to comment.