Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] 출금 시 더 이상 목표를 조회할 때 나오지 않도록 수정 #136

Merged
merged 5 commits into from
Aug 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class Target {
@Column(name = "is_done")
private Boolean isDone;

@Column(name = "is_withdrawed")
private Boolean isWithdrawed;

@Column(name = "start_date")
private LocalDate startDate;

Expand All @@ -44,12 +47,13 @@ public class Target {
private Account account;

@Builder
public Target(String description, Integer targetAmount, String targetTitle, Integer currentAmount, Boolean isDone, LocalDate startDate, LocalDate endDate, Account account) {
public Target(String description, Integer targetAmount, String targetTitle, Integer currentAmount, Boolean isDone, Boolean isWithdrawed, LocalDate startDate, LocalDate endDate, Account account) {
this.description = description;
this.targetAmount = targetAmount;
this.targetTitle = targetTitle;
this.currentAmount = currentAmount;
this.isDone = isDone;
this.isWithdrawed = isWithdrawed;
this.startDate = startDate;
this.endDate = endDate;
this.account = account;
Expand All @@ -58,4 +62,8 @@ public Target(String description, Integer targetAmount, String targetTitle, Inte
public Boolean isDone() {
return isDone;
}

public Boolean isWithdrawed() {
return isWithdrawed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public Long createTarget(CreateTargetRequest request, Long memberId) {
.targetAmount(request.getTargetAmount())
.currentAmount(0)
.isDone(false)
.isWithdrawed(false)
.startDate(request.getStartDate())
.endDate(request.getEndDate())
.account(account)
Expand All @@ -57,15 +58,21 @@ public List<TargetResponse> findTargets(Long memberId) {
// memberId로 Target 리스트 조회
List<Target> targets = targetRepository.findAllByMemberId(memberId);

// Target 리스트들 중에서 isWithdrawed가 false인 목표들만 필터링
List<Target> activeTargets = targets.stream()
.filter(target -> !target.isWithdrawed())
.collect(Collectors.toList());

// Target 리스트를 TargetResponse 리스트로 변환하여 반환
return targets.stream()
return activeTargets.stream()
.map(target -> TargetResponse.builder()
.targetId(target.getTargetId())
.description(target.getDescription())
.targetAmount(target.getTargetAmount())
.targetTitle(target.getTargetTitle())
.currentAmount(target.getCurrentAmount())
.isDone(target.isDone())
.isWithdraw(target.getIsWithdrawed())
.startDate(target.getStartDate())
.endDate(target.getEndDate())
.accountId(target.getAccount().getAccountId()) // Account ID 반환
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ public void updateTarget(Long memberId, String userKey, Long targetId) throws Js
if (totalAmount > 0) {
callTransferApi(depositAccountNo, withdrawalAccountNo, totalAmount, userKey); // 재사용
}

// 출금 처리
target.setIsWithdrawed(true);

// 타겟의 현재 금액 0으로 설정
target.setCurrentAmount(0);
}

// 목표 삭제 메소드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class TargetResponse {
private String targetTitle;
private int currentAmount;
private Boolean isDone;
private Boolean isWithdraw;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate startDate;
Expand All @@ -27,13 +28,14 @@ public class TargetResponse {
private Long accountId;

@Builder
public TargetResponse (Long targetId, String description, int targetAmount, String targetTitle, int currentAmount, Boolean isDone, LocalDate startDate, LocalDate endDate, Long accountId) {
public TargetResponse (Long targetId, String description, int targetAmount, String targetTitle, int currentAmount, Boolean isDone, Boolean isWithdraw, LocalDate startDate, LocalDate endDate, Long accountId) {
this.targetId = targetId;
this.description = description;
this.targetAmount = targetAmount;
this.targetTitle = targetTitle;
this.currentAmount = currentAmount;
this.isDone = isDone;
this.isWithdraw = isWithdraw;
this.startDate = startDate;
this.endDate = endDate;
this.accountId = accountId;
Expand Down
Loading