Skip to content

Commit 05987df

Browse files
Merge pull request #52 from woorifisa-projects-3rd/card-remove-api
feat:카드 해지 api 구현
2 parents 5cc4f9f + e1089b9 commit 05987df

File tree

8 files changed

+60
-10
lines changed

8 files changed

+60
-10
lines changed

src/main/java/org/baas/baascore/controller/CardController.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
import org.baas.baascore.dto.request.CardReissuedRequest;
55
import org.baas.baascore.dto.request.CommonRequest;
66
import org.baas.baascore.dto.response.CardIssuedResponse;
7+
import org.baas.baascore.dto.response.MessageResponse;
78
import org.baas.baascore.service.CardService;
89
import org.springframework.http.ResponseEntity;
9-
import org.springframework.web.bind.annotation.PostMapping;
10-
import org.springframework.web.bind.annotation.RequestBody;
11-
import org.springframework.web.bind.annotation.RequestMapping;
12-
import org.springframework.web.bind.annotation.RestController;
10+
import org.springframework.web.bind.annotation.*;
1311

1412
@RequiredArgsConstructor
1513
@RestController
@@ -22,6 +20,11 @@ public ResponseEntity<CardIssuedResponse> cardIssued(@RequestBody CommonRequest
2220
return ResponseEntity.ok().body(cardService.cardIssued(commonRequest));
2321
}
2422

23+
@DeleteMapping
24+
public ResponseEntity<MessageResponse> cardRemove(@RequestBody CardReissuedRequest cardReissuedRequest){
25+
return ResponseEntity.ok().body(cardService.cardRemove(cardReissuedRequest));
26+
}
27+
2528
@PostMapping("/reissue")
2629
public ResponseEntity<CardIssuedResponse> cardReissued(@RequestBody CardReissuedRequest cardReissuedRequest){
2730
return ResponseEntity.ok().body(cardService.cardReissued(cardReissuedRequest));

src/main/java/org/baas/baascore/dto/response/AccountInitResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class AccountInitResponse {
2323
private LocalDate createdAt;
2424
private LocalDate updatedAt;
2525

26-
public static AccountInitResponse from(Account account, int index) {
26+
public static AccountInitResponse of(Account account, int index) {
2727
return AccountInitResponse.builder()
2828
.index(index)
2929
.customerName(account.getCustomer().getName())
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.baas.baascore.dto.response;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
@Getter
9+
@NoArgsConstructor
10+
@AllArgsConstructor
11+
@Builder
12+
public class MessageResponse {
13+
14+
private String message;
15+
}

src/main/java/org/baas/baascore/model/Customer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Customer extends BaseTimeEntity {
3838
@Column(name = "name", nullable = false)
3939
private String name;
4040

41-
@Column(name = "ci",length = 88)
41+
@Column(name = "ci",length = 88, nullable = false, unique = true)
4242
private String ci;
4343

4444
// 한 고객이 여러 계좌를 소유할 수 있도록 양방향 매핑 추가

src/main/java/org/baas/baascore/model/Subscribe.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class Subscribe extends BaseTimeEntity {
3333
private Bank bank;
3434

3535
// 구독상품명
36+
@Column(name = "product_name", nullable = false)
3637
private String productName;
3738

3839
// 사업자 등록 번호

src/main/java/org/baas/baascore/model/TransactionHistory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class TransactionHistory extends BaseTimeEntity {
4545
private BigDecimal afterBalanceAmt;
4646

4747
// 출금 상대 이름
48-
@Column(name = "counterparty_Name", nullable = false)
48+
@Column(name = "counterparty_name", nullable = false)
4949
private String counterpartyName;
5050

5151
// 출금 상대 계좌 번호
@@ -62,7 +62,7 @@ public class TransactionHistory extends BaseTimeEntity {
6262

6363
// CoreTransaction과의 다대일 관계 설정
6464
@ManyToOne(fetch = FetchType.LAZY)
65-
@JoinColumn(name = "core_transaction_id", nullable = false)
65+
@JoinColumn(name = "transaction_id", nullable = false)
6666
private CoreTransaction coreTransaction;
6767

6868
public TransactionHistory() {

src/main/java/org/baas/baascore/service/AccountService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Random;
2222
import java.util.UUID;
2323
import java.util.concurrent.atomic.AtomicInteger;
24-
import java.util.stream.Collectors;
2524
import java.util.stream.IntStream;
2625

2726
@Service
@@ -192,7 +191,7 @@ public AccountsInfoResponse findAccountInfo(MemberInitRequest memberInitRequest)
192191

193192
AtomicInteger index = new AtomicInteger(1);
194193
List<AccountInitResponse> accountInfoList = accountRepository.findByCustomerId(customer.getId()).stream()
195-
.map(account -> AccountInitResponse.from(account, index.getAndIncrement()))
194+
.map(account -> AccountInitResponse.of(account, index.getAndIncrement()))
196195
.toList();
197196

198197
return new AccountsInfoResponse(accountInfoList.size(), accountInfoList);

src/main/java/org/baas/baascore/service/CardService.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.baas.baascore.dto.request.CardReissuedRequest;
55
import org.baas.baascore.dto.request.CommonRequest;
66
import org.baas.baascore.dto.response.CardIssuedResponse;
7+
import org.baas.baascore.dto.response.MessageResponse;
78
import org.baas.baascore.exception.CustomException;
89
import org.baas.baascore.exception.ErrorCode;
910
import org.baas.baascore.model.Account;
@@ -118,4 +119,35 @@ private String createNumber(int count, String prefix) {
118119
}
119120
return randomNum.toString();
120121
}
122+
123+
@Transactional
124+
public MessageResponse cardRemove(CardReissuedRequest cardReissuedRequest) {
125+
Card card = cardRepository.findByCardNumberAndCardStatusTrueAndExpiredAtGreaterThan(
126+
cardReissuedRequest.getCardNumber(), LocalDateTime.now())
127+
.orElseThrow(
128+
() -> new CustomException(ErrorCode.CARDNUMBER_NOT_FOUND)
129+
);
130+
131+
Customer customer = customerRepository.findByCi(cardReissuedRequest.getCi()).orElseThrow(
132+
() -> new CustomException(ErrorCode.IDENTITYCODE_NOT_FOUND)
133+
);
134+
135+
if (!card.getCustomer().equals(customer)) {
136+
throw new CustomException(ErrorCode.CARD_OWNER_MISMATCH);
137+
}
138+
139+
Account account = accountRepository.findByFintechUseNum(cardReissuedRequest.getFintechUseNum())
140+
.orElseThrow(
141+
() -> new CustomException(ErrorCode.FINTECHCODE_NOT_FOUND)
142+
);
143+
144+
if (!card.getAccount().equals(account)) {
145+
throw new CustomException(ErrorCode.ACCOUNT_MISMATCH_WITH_CARD);
146+
} else if (!card.getAccount().getBank().getBankCode().equals(BANK_CODE)) {
147+
throw new CustomException(ErrorCode.CARD_NOT_FROM_WOORI_BANK);
148+
}
149+
150+
card.changeCardStatus(false);
151+
return MessageResponse.builder().message("카드가 정상적으로 삭제 되었습니다.").build();
152+
}
121153
}

0 commit comments

Comments
 (0)