Skip to content

Commit

Permalink
YEL-145 [fix] soft deleted 유저의 yelloId 중복 체크
Browse files Browse the repository at this point in the history
YEL-145 [fix] soft deleted 유저의 yelloId 중복 체크
  • Loading branch information
euije authored Aug 26, 2023
2 parents f2e53c9 + 5f376ff commit 11b2cb4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void validateSignupRequest(SignUpRequest signUpRequest) {
throw new UserConflictException(UUID_CONFLICT_USER_EXCEPTION);
});

userRepository.findByYelloId(signUpRequest.yelloId())
userRepository.findByYelloIdNotFiltered(signUpRequest.yelloId())
.ifPresent(action -> {
throw new UserConflictException(YELLOID_CONFLICT_USER_EXCEPTION);
});
Expand All @@ -81,7 +81,7 @@ public void validateSignupRequest(SignUpRequest signUpRequest) {
public Boolean renewUserData(User user) {
final Long userId = user.getId();

if (user.getDeletedAt()!=null) {
if (user.getDeletedAt() != null) {
user.renew();

friendRepository.findAllByUserIdNotFiltered(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Boolean isYelloIdDuplicated(String yelloId) {
throw new AuthBadRequestException(YELLOID_REQUIRED_EXCEPTION);
}

return userRepository.findByYelloId(yelloId).isPresent();
return userRepository.findByYelloIdNotFiltered(yelloId).isPresent();
}

@Transactional
Expand All @@ -103,7 +103,7 @@ public SignUpResponse signUp(SignUpRequest signUpRequest) {

@Transactional
public void recommendUser(String recommendYelloId, String userYelloId) {
if (recommendYelloId!=null && !recommendYelloId.isEmpty()) {
if (recommendYelloId != null && !recommendYelloId.isEmpty()) {
User recommendedUser = userRepository.getByYelloId(recommendYelloId);
User user = userRepository.getByYelloId(userYelloId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public interface UserJpaRepository extends JpaRepository<User, Long> {
"and u.deletedAt is null")
Optional<User> findByYelloId(@Param("yelloId") String yelloId);

@Query("select u from User u " +
"where u.yelloId = :yelloId")
Optional<User> findByYelloIdNotFiltered(@Param("yelloId") String yelloId);

@Query("select u from User u " +
"where u.group.id = :groupId " +
"and u.deletedAt is null")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface UserRepository {

Optional<User> findByYelloId(String yelloId);

Optional<User> findByYelloIdNotFiltered(String yelloId);

User getByYelloId(String yelloId);

Optional<User> findByDeviceToken(String deviceToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public Optional<User> findByYelloId(String yelloId) {
return userJpaRepository.findByYelloId(yelloId);
}

@Override
public Optional<User> findByYelloIdNotFiltered(String yelloId) {
return userJpaRepository.findByYelloIdNotFiltered(yelloId);
}

@Override
public User getByYelloId(String yelloId) {
return userJpaRepository.findByYelloId(yelloId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public class HealthCheckController {
public String healthCheck() {
return "Yell:o world!";
}

@GetMapping("/abc")
public void text() throws Exception {
throw new Exception("Abc");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void validateSignupRequest(SignUpRequest signUpRequest) {
throw new UserConflictException(UUID_CONFLICT_USER_EXCEPTION);
});

userRepository.findByYelloId(signUpRequest.yelloId())
userRepository.findByYelloIdNotFiltered(signUpRequest.yelloId())
.ifPresent(action -> {
throw new UserConflictException(YELLOID_CONFLICT_USER_EXCEPTION);
});
Expand All @@ -86,7 +86,7 @@ public void validateSignupRequest(SignUpRequest signUpRequest) {
public Boolean renewUserData(User user) {
final Long userId = user.getId();

if (user.getDeletedAt()!=null) {
if (user.getDeletedAt() != null) {
user.renew();

friendRepository.findAllByUserIdNotFiltered(userId)
Expand Down
12 changes: 10 additions & 2 deletions src/test/java/com/yello/server/domain/user/FakeUserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class FakeUserRepository implements UserRepository {

@Override
public User save(User user) {
if (user.getId()!=null && user.getId() > id) {
if (user.getId() != null && user.getId() > id) {
id = user.getId();
}

User newUser = User.builder()
.id(user.getId()==null ? ++id : user.getId())
.id(user.getId() == null ? ++id : user.getId())
.recommendCount(0L)
.name(user.getName())
.yelloId(user.getYelloId())
Expand Down Expand Up @@ -82,6 +82,14 @@ public boolean existsByUuid(String uuid) {

@Override
public Optional<User> findByYelloId(String yelloId) {
return data.stream()
.filter(user -> user.getDeletedAt() == null)
.filter(user -> user.getYelloId().equals(yelloId))
.findFirst();
}

@Override
public Optional<User> findByYelloIdNotFiltered(String yelloId) {
return data.stream()
.filter(user -> user.getYelloId().equals(yelloId))
.findFirst();
Expand Down

0 comments on commit 11b2cb4

Please sign in to comment.