Skip to content

Commit e563641

Browse files
authored
[FEATURE/#68] 은행 금융사 연동 삭제 시 연결된 목표 삭제 로직 보완 (#69)
## 🔗 Related Issue <!-- 이슈 번호를 작성하여 종료시켜주세요 --> - Closes #68 ## 📝 Summary <!-- 작업한 기능을 설명해주세요 --> 은행 금융사 연동 삭제 시 계좌와 연결된 목표도 삭제되도록 보완했습니다. ## 🔄 Changes <!-- 구체적으로 어떤 파일/로직이 변경되었는지 체크해주세요 --> - [X] API 변경 (추가/수정) - [ ] 데이터 및 도메인 변경 (DB, 비즈니스 로직) - [ ] 설정 또는 인프라 관련 변경 - [ ] 리팩토링 ## 💬 Questions & Review Points <!-- 리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요 --> ## 📸 API Test Results (Swagger) <!-- API 테스트 스크린샷 첨부 --> ## ✅ Checklist - [x] API 테스트 완료 - [ ] 테스트 결과 사진 첨부 - [x] 빌드 성공 확인 (./gradlew build)
1 parent d0ebd48 commit e563641

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

src/main/java/org/umc/valuedi/domain/connection/service/ConnectionCommandService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import org.springframework.transaction.annotation.Transactional;
77
import org.umc.valuedi.domain.connection.dto.req.ConnectionReqDTO;
88
import org.umc.valuedi.domain.connection.entity.CodefConnection;
9+
import org.umc.valuedi.domain.connection.enums.BusinessType;
910
import org.umc.valuedi.domain.connection.exception.ConnectionException;
1011
import org.umc.valuedi.domain.connection.exception.code.ConnectionErrorCode;
1112
import org.umc.valuedi.domain.connection.repository.CodefConnectionRepository;
13+
import org.umc.valuedi.domain.goal.repository.GoalRepository;
1214
import org.umc.valuedi.global.external.codef.service.CodefAccountService;
1315

1416
@Slf4j
@@ -19,6 +21,7 @@ public class ConnectionCommandService {
1921

2022
private final CodefAccountService codefAccountService;
2123
private final CodefConnectionRepository codefConnectionRepository;
24+
private final GoalRepository goalRepository;
2225

2326
/**
2427
* 금융사 계정 연동
@@ -45,10 +48,12 @@ public void disconnect(Long memberId, Long connectionId) {
4548
connection.getBusinessType()
4649
);
4750

48-
// connection Soft Delete (Cascade에 의해 하위 계좌/카드도 Soft Delete 됨)
51+
//하위 계좌/카드도 Soft Delete
4952
codefConnectionRepository.delete(connection);
5053

51-
// TODO: [추후 구현] 은행 계좌와 연결된 목표(Goal) Soft Delete 처리 로직 추가 필요
52-
// if (connection.getBusinessType() == BusinessType.BANK) { ... }
54+
if (connection.getBusinessType() == BusinessType.BK) {
55+
// 은행 계좌와 연결된 목표 Soft Delete 처리 (서브쿼리 사용)
56+
goalRepository.softDeleteGoalsByConnectionId(connection.getId());
57+
}
5358
}
5459
}

src/main/java/org/umc/valuedi/domain/goal/entity/Goal.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,4 @@ public void Fail() {
9999
this.completedAt = LocalDateTime.now();
100100
}
101101

102-
public void setBankAccount(BankAccount bankAccount) { this.bankAccount = bankAccount;}
103102
}

src/main/java/org/umc/valuedi/domain/goal/repository/GoalRepository.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.umc.valuedi.domain.goal.repository;
22

33
import org.springframework.data.jpa.repository.JpaRepository;
4+
import org.springframework.data.jpa.repository.Modifying;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.data.repository.query.Param;
47
import org.umc.valuedi.domain.goal.entity.Goal;
58
import org.umc.valuedi.domain.goal.enums.GoalStatus;
69
import org.springframework.data.domain.Pageable;
@@ -21,4 +24,13 @@ public interface GoalRepository extends JpaRepository<Goal, Long>, GoalRepositor
2124
List<Goal> findAllByMember_IdAndStatus(Long memberId, GoalStatus status, Pageable pageable);
2225
List<Goal> findAllByMember_IdAndStatusIn(Long memberId, List<GoalStatus> statuses, Pageable pageable);
2326

27+
List<Goal> findAllByBankAccountId(Long bankAccountId);
28+
29+
@Modifying(clearAutomatically = true)
30+
@Query("UPDATE Goal g SET g.deletedAt = CURRENT_TIMESTAMP " +
31+
"WHERE g.bankAccount.id IN (" +
32+
" SELECT ba.id FROM BankAccount ba " +
33+
" WHERE ba.codefConnection.id = :connectionId" +
34+
")")
35+
void softDeleteGoalsByConnectionId(@Param("connectionId") Long connectionId);
2436
}

0 commit comments

Comments
 (0)