Skip to content

Commit

Permalink
[refac] archiving 미사용 함수 정리 및 adaptor 함수 이름 변경 #49
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdtkdgns committed Jul 21, 2023
1 parent 6fe5149 commit 2f63229
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class UpdateArchivingScrapUseCase {
public void execute(Long archivingId, Boolean cancel) {
Long userId = SecurityUtil.getCurrentUserId();
validateExecution(archivingId, userId, cancel);
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
if (cancel) {
scrapDomainService.deleteScrapByUserAndArchivingId(user, archivingId);
archivingDomainService.updateScrapCount(archivingId, -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TokenRefreshUseCase {
public OauthRegisterResponse execute(String refreshToken) {
RefreshTokenEntity oldToken = refreshTokenAdaptor.findTokenByRefreshToken(refreshToken);
Long userId = jwtTokenProvider.parseRefreshToken(oldToken.getRefreshToken());
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
return OauthRegisterResponse.from(tokenGenerateHelper.execute(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class WithdrawUserUseCase {

public void execute(OauthProvider provider, String appleAccessToken) {
Long userId = SecurityUtil.getCurrentUserId();
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
// oauth쪽 탈퇴
withdrawOauth(provider, appleAccessToken, user);
// 우리쪽 탈퇴
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public BlockResponse execute(BlockRequest request) {
blockValidator.validateNotMyself(userId, request.getUserId());
Block block = blockMapper.toEntity(userId, request.getUserId());
blockDomainService.save(block);
return BlockResponse.from(userAdaptor.findUserById(request.getUserId()).getNickname());
return BlockResponse.from(userAdaptor.findById(request.getUserId()).getNickname());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public BlockResponse execute(BlockRequest request) {
Long userId = SecurityUtil.getCurrentUserId();
blockValidator.validateExist(userId, request.getUserId());
blockDomainService.deleteByBlockFromAndBlockUser(userId, request.getUserId());
return BlockResponse.from(userAdaptor.findUserById(request.getUserId()).getNickname());
return BlockResponse.from(userAdaptor.findById(request.getUserId()).getNickname());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GetUserInfoUseCase {
public GetUserInfoResponse execute() {
Long userId = SecurityUtil.getCurrentUserId();
userValidator.validateUserStatusNormal(userId);
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
return GetUserInfoResponse.from(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class GetUserProfileUseCase {
public GetUserProfileResponse execute() {
Long userId = SecurityUtil.getCurrentUserId();
userValidator.validateUserStatusNormal(userId);
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
List<Archiving> archivingList = archivingAdaptor.findAllByUserId(userId);
return userMapper.toGetUserProfileResponse(archivingList, user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public Archiving findById(Long archivingId) {
.orElseThrow(() -> ArchivingNotFoundException.EXCEPTION);
}

public void deleteById(Long archivingId) {
archivingRepository.deleteById(archivingId);
}

public Slice<Archiving> querySliceArchivingExceptBlock(
List<Long> archivingIdList,
List<Long> blockList,
Expand Down Expand Up @@ -73,10 +69,6 @@ public void saveAll(List<Archiving> archivings) {
archivingRepository.saveAll(archivings);
}

public List<Archiving> findAllByUserIdAndDeleted(Long userId) {
return archivingRepository.findAllByUserIdAndDeleteStatus(userId, true);
}

public void deleteAllById(List<Long> archivingIds) {
archivingRepository.deleteAllById(archivingIds);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ public interface ArchivingRepository

List<Archiving> findAllByIdIn(List<Long> ids);

List<Archiving> findAllByUserIdAndDeleteStatus(Long userId, boolean deleteStatus);

List<Archiving> findAllByPublicStatus(Boolean publicStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class UserAdaptor {
private final UserRepository userRepository;

public Boolean exist(OauthInfo oauthInfo) {
return userRepository.findByOauthInfo(oauthInfo).isPresent();
return userRepository.existsByOauthInfo(oauthInfo);
}

public User queryUserByOauthInfo(OauthInfo oauthInfo) {
public User findByOauthInfo(OauthInfo oauthInfo) {
return userRepository
.findByOauthInfo(oauthInfo)
.orElseThrow(() -> UserNotFoundException.EXCEPTION);
Expand All @@ -28,7 +28,7 @@ public void save(User user) {
userRepository.save(user);
}

public User findUserById(Long userId) {
public User findById(Long userId) {
return userRepository.findById(userId).orElseThrow(() -> UserNotFoundException.EXCEPTION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByOauthInfo(OauthInfo oauthInfo);

boolean existsByOauthInfo(OauthInfo oauthInfo);

boolean existsByNickname(String nickname);

List<User> findAllByIdIn(List<Long> userIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ public User registerUser(

@Transactional
public User loginUser(OauthInfo oauthInfo) {
User user = userAdaptor.queryUserByOauthInfo(oauthInfo);
User user = userAdaptor.findByOauthInfo(oauthInfo);
user.login();
return user;
}

@Transactional
public void deleteUserById(Long userId) {
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
user.withdrawUser();
}

public void updateUserInfo(
Long userId, String name, String email, String nickname, String imgUrl) {
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
user.updateInfo(name, email, nickname, imgUrl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ScrapValidator {
private final ScrapAdaptor scrapAdaptor;

public void validateExistScrap(Long userId, Long archivingId) {
User user = userAdaptor.findUserById(userId);
User user = userAdaptor.findById(userId);
if (isScrapExist(user, archivingId)) {
throw AlreadyExistScrapException.EXCEPTION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Boolean checkUserCanRegister(OauthInfo oauthInfo) {
}

public void validateUserStatusNormal(Long userId) {
if (!userAdaptor.findUserById(userId).getUserState().equals(UserState.NORMAL)) {
if (!userAdaptor.findById(userId).getUserState().equals(UserState.NORMAL)) {
throw ForbiddenUserException.EXCEPTION;
}
}
Expand Down

0 comments on commit 2f63229

Please sign in to comment.