Skip to content

Commit

Permalink
[DEV-38] 회원탈퇴 오류 수정 (#278)
Browse files Browse the repository at this point in the history
* feat: deleteAllByUserJpaEntity 구현

* feat: DeleteCompletedCreditPort 구현

* fix: 유저 탈퇴 오류 수정 - deleteUserCompletedCredits 로직 추가
  • Loading branch information
5uhwann authored Jun 30, 2024
1 parent 784eb0a commit a87c889
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.plzgraduate.myongjigraduatebe.completedcredit.application.port;

import com.plzgraduate.myongjigraduatebe.user.domain.model.User;

public interface DeleteCompletedCreditPort {

void deleteAllCompletedCredits(User user);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence;

import org.springframework.transaction.annotation.Transactional;

import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.DeleteCompletedCreditPort;
import com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.repository.CompletedCreditRepository;
import com.plzgraduate.myongjigraduatebe.core.meta.PersistenceAdapter;
import com.plzgraduate.myongjigraduatebe.user.domain.model.User;
import com.plzgraduate.myongjigraduatebe.user.infrastructure.adapter.persistence.mapper.UserMapper;

import lombok.RequiredArgsConstructor;

@PersistenceAdapter
@Transactional
@RequiredArgsConstructor
public class DeletedCompletedCreditAdapter implements DeleteCompletedCreditPort {

private final CompletedCreditRepository completedCreditRepository;
private final UserMapper userMapper;

@Override
public void deleteAllCompletedCredits(User user) {
completedCreditRepository.deleteAllByUserJpaEntity(userMapper.mapToJpaEntity(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface CompletedCreditRepository extends JpaRepository<CompletedCredit

List<CompletedCreditJpaEntity> findAllByUserJpaEntity(UserJpaEntity userJpaEntity);

void deleteAllByUserJpaEntity(UserJpaEntity userJpaEntity);

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.transaction.annotation.Transactional;

import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.DeleteCompletedCreditPort;
import com.plzgraduate.myongjigraduatebe.core.meta.UseCase;
import com.plzgraduate.myongjigraduatebe.parsing.application.port.DeleteParsingTextHistoryPort;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase;
Expand All @@ -22,6 +23,7 @@ class WithDrawUserService implements WithDrawUserUseCase {
private final DeleteTakenLectureUseCase deleteTakenLectureByUserUseCase;
private final DeleteParsingTextHistoryPort deleteParsingTextHistoryPort;
private final DeleteUserPort deleteUserPort;
private final DeleteCompletedCreditPort deleteCompletedCreditPort;
private final PasswordEncoder passwordEncoder;

@Override
Expand All @@ -30,6 +32,7 @@ public void withDraw(Long userId, String password) {
user.matchPassword(passwordEncoder, password);
deleteTakenLectureByUserUseCase.deleteAllTakenLecturesByUser(user);
deleteParsingTextHistoryPort.deleteUserParsingTextHistory(user);
deleteCompletedCreditPort.deleteAllCompletedCredits(user);
deleteUserPort.deleteUser(user);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.plzgraduate.myongjigraduatebe.completedcredit.infrastructure.persistence.repository;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -50,9 +51,43 @@ void findAllByUserJpaEntity() {
userJpaEntity);

//then
Assertions.assertThat(foundCompletedCredits).hasSize(2)
assertThat(foundCompletedCredits).hasSize(2)
.extracting("userJpaEntity.authId")
.contains(userJpaEntity.getAuthId());
}

@DisplayName("유저의 모든 이수학점 내역을 삭제한다.")
@Test
void deleteAllByUserJpaEntity() {
//given
UserJpaEntity userJpaEntity = UserJpaEntity.builder()
.authId("test1234")
.password("test")
.studentNumber("60191112").build();
userRepository.save(userJpaEntity);

CompletedCreditJpaEntity commonCultureCompletedCreditJpaEntity = CompletedCreditJpaEntity.builder()
.userJpaEntity(userJpaEntity)
.graduationCategory(GraduationCategory.COMMON_CULTURE)
.totalCredit(10)
.takenCredit(10).build();

CompletedCreditJpaEntity coreCultureCompletedCreditJpaEntity = CompletedCreditJpaEntity.builder()
.userJpaEntity(userJpaEntity)
.graduationCategory(GraduationCategory.CORE_CULTURE)
.totalCredit(10)
.takenCredit(10).build();

completedCreditRepository.saveAll(
List.of(commonCultureCompletedCreditJpaEntity, coreCultureCompletedCreditJpaEntity));

//when
completedCreditRepository.deleteAllByUserJpaEntity(userJpaEntity);

//then
List<CompletedCreditJpaEntity> foundCompletedCredits = completedCreditRepository.findAllByUserJpaEntity(
userJpaEntity);
assertThat(foundCompletedCredits).isEmpty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import com.plzgraduate.myongjigraduatebe.completedcredit.application.port.DeleteCompletedCreditPort;
import com.plzgraduate.myongjigraduatebe.parsing.application.port.DeleteParsingTextHistoryPort;
import com.plzgraduate.myongjigraduatebe.takenlecture.application.usecase.delete.DeleteTakenLectureUseCase;
import com.plzgraduate.myongjigraduatebe.user.application.port.DeleteUserPort;
Expand All @@ -32,6 +33,8 @@ class WithDrawUserServiceTest {
@Mock
private DeleteUserPort deleteUserPort;
@Mock
private DeleteCompletedCreditPort deleteCompletedCreditPort;
@Mock
private PasswordEncoder passwordEncoder;

@InjectMocks
Expand All @@ -53,6 +56,7 @@ void withDraw() {
withDrawUserService.withDraw(user.getId(), password);
then(deleteTakenLectureByUserUseCase).should().deleteAllTakenLecturesByUser(user);
then(deleteParsingTextHistoryPort).should().deleteUserParsingTextHistory(user);
then(deleteCompletedCreditPort).should().deleteAllCompletedCredits(user);
then(deleteUserPort).should().deleteUser(user);
}

Expand Down

0 comments on commit a87c889

Please sign in to comment.