Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
import com.promsearch.auth.domain.enums.SocialProvider;
import com.promsearch.auth.domain.exception.AuthDomainException;
import com.promsearch.auth.domain.exception.AuthErrorCode;
import com.promsearch.user.application.port.out.social.DeleteUserSocialAccountsPort;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class SocialAccountPersistenceAdapter implements LoadSocialAccountPort, SaveSocialAccountPort {
public class SocialAccountPersistenceAdapter implements
LoadSocialAccountPort,
SaveSocialAccountPort,
DeleteUserSocialAccountsPort {

private final SocialAccountRepository socialAccountRepository;

Expand All @@ -36,4 +40,9 @@ public Optional<SocialAccount> findByProviderAndProviderUserId(SocialProvider pr
return socialAccountRepository.findByProviderAndProviderUserId(provider, providerUserId)
.map(SocialAccountJpaEntity::toDomain);
}

@Override
public void deleteByUserId(Long userId) {
socialAccountRepository.deleteByUserId(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public interface SocialAccountRepository extends JpaRepository<SocialAccountJpaE
Optional<SocialAccountJpaEntity> findByProviderAndProviderUserId(SocialProvider provider, String providerUserId);

boolean existsByProviderAndProviderUserId(SocialProvider provider, String providerUserId);

void deleteByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.promsearch.user.application.port.out.social;

/**
* 탈퇴한 사용자의 외부 로그인 연결을 제거하는 출력 포트.
*
* <p>소셜 제공자 측 연결은 유지하되, 우리 서비스의 연결 정보만 제거하여
* 동일한 소셜 계정으로 다시 가입할 수 있게 한다.</p>
*/
public interface DeleteUserSocialAccountsPort {

/** 사용자의 모든 내부 소셜 로그인 연결을 제거한다. */
void deleteByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.promsearch.user.application.port.out.user.SaveUserPort;
import com.promsearch.user.application.port.out.profileimage.ProfileImageDeliveryPort;
import com.promsearch.user.application.port.out.profileimage.ScheduleProfileImageDeletionPort;
import com.promsearch.user.application.port.out.social.DeleteUserSocialAccountsPort;
import com.promsearch.user.application.usecase.BootstrapAdminAccountUseCase;
import com.promsearch.user.application.usecase.ChangePasswordUseCase;
import com.promsearch.user.application.usecase.DeleteUserUseCase;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class UserCommandService implements
private final PasswordEncoder passwordEncoder;
private final ProfileImageDeliveryPort profileImageDeliveryPort;
private final ScheduleProfileImageDeletionPort profileImageDeletionPort;
private final DeleteUserSocialAccountsPort deleteUserSocialAccountsPort;

@Override
public SignupInfo signup(SignupCommand command) {
Expand Down Expand Up @@ -148,6 +150,7 @@ public void changePassword(ChangePasswordCommand command) {
public void delete(Long userId) {
User user = loadUserPort.getById(userId);
saveUserPort.update(user.delete());
deleteUserSocialAccountsPort.deleteByUserId(userId);
profileImageDeletionPort.afterCommit(user.getProfileImageObjectKey());
log.info("user_deleted userId={}", userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class UserCommandServiceTest {

private FakeUserRepository userRepository;
private FakeSaveUserInterestTagPort saveUserInterestTagPort;
private Long deletedSocialAccountUserId;
private UserCommandService userCommandService;

@BeforeEach
Expand All @@ -50,7 +51,8 @@ void setUp() {
new TestPasswordEncoder(),
(externalUrl, objectKey) -> objectKey == null ? externalUrl : "signed:" + objectKey,
objectKey -> {
}
},
userId -> deletedSocialAccountUserId = userId
);
}

Expand Down Expand Up @@ -190,6 +192,7 @@ void deleteMarksUserAsDeletedAndAnonymizesUniqueInformation() {
assertThat(deletedUser.getNickname()).startsWith("deleted_1_").endsWith("_user");
assertThat(deletedUser.getName()).isEqualTo("Deleted User");
assertThat(deletedUser.getProfileImageUrl()).isNull();
assertThat(deletedSocialAccountUserId).isEqualTo(1L);
}

@Test
Expand Down
Loading