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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import org.umc.valuedi.domain.goal.enums.GoalStatus;
import org.umc.valuedi.domain.goal.enums.GoalSort;
import org.umc.valuedi.domain.goal.exception.code.GoalSuccessCode;
import org.umc.valuedi.domain.goal.service.GoalLedgerFacade;
import org.umc.valuedi.domain.goal.service.command.GoalAccountCommandService;
import org.umc.valuedi.domain.goal.service.command.GoalCommandService;
import org.umc.valuedi.domain.goal.service.query.GoalAccountQueryService;
import org.umc.valuedi.domain.goal.service.query.GoalLedgerQueryService;
import org.umc.valuedi.domain.goal.service.query.GoalListQueryService;
import org.umc.valuedi.domain.goal.service.query.GoalQueryService;
import org.umc.valuedi.domain.ledger.dto.response.LedgerListResponse;
Expand All @@ -31,7 +31,7 @@ public class GoalController implements GoalControllerDocs{
private final GoalListQueryService goalListQueryService;
private final GoalAccountQueryService goalAccountQueryService;
private final GoalAccountCommandService goalAccountCommandService;
private final GoalLedgerFacade goalLedgerFacade;
private final GoalLedgerQueryService goalLedgerQueryService;

// 목표 추가
@PostMapping
Expand Down Expand Up @@ -158,7 +158,7 @@ public ApiResponse<LedgerListResponse> getGoalLedgers(
) {
return ApiResponse.onSuccess(
GoalSuccessCode.GOAL_LEDGER_LIST_FETCHED,
goalLedgerFacade.getGoalLedgerTransactions(memberId, goalId, page, size)
goalLedgerQueryService.getGoalLedgerTransactions(memberId, goalId, page, size)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

public class GoalConverter {

public static Goal toEntity(Member member,BankAccount bankAccount, GoalCreateRequestDto req, Long startAmount) {
public static Goal toEntity(Member member,BankAccount bankAccount, GoalCreateRequestDto req) {
return Goal.builder()
.member(member)
.bankAccount(bankAccount)
.title(req.title())
.startDate(req.startDate())
.endDate(req.endDate())
.targetAmount(req.targetAmount())
.startAmount(startAmount)
.status(GoalStatus.ACTIVE)
.completedAt(null)
.color(GoalStyleCatalog.normalizeColor(req.colorCode()))
Expand Down Expand Up @@ -82,7 +81,6 @@ public static GoalCreateResponseDto toCreateDto(Goal goal) {
goal.getId(),
goal.getTitle(),
goal.getTargetAmount(),
goal.getStartAmount(),
goal.getStartDate(),
goal.getEndDate(),
remainingDays,
Expand All @@ -93,15 +91,15 @@ public static GoalCreateResponseDto toCreateDto(Goal goal) {

public static GoalListResponseDto.GoalSummaryDto toSummaryDto(
Goal goal,
Long savedAmount,
Long currentBalance,
int achievementRate
) {
Long remainingDays = calcRemainingDays(goal.getEndDate());

return new GoalListResponseDto.GoalSummaryDto(
goal.getId(),
goal.getTitle(),
savedAmount,
currentBalance,
remainingDays,
achievementRate,
goal.getStatus(),
Expand All @@ -110,7 +108,7 @@ public static GoalListResponseDto.GoalSummaryDto toSummaryDto(
);
}

public static GoalDetailResponseDto toDetailDto(Goal goal, Long savedAmount, int achievementRate) {
public static GoalDetailResponseDto toDetailDto(Goal goal, Long currentBalance, int achievementRate) {
long remainingDays = calcRemainingDays(goal.getEndDate());

GoalDetailResponseDto.AccountDto accountDto = null;
Expand All @@ -122,7 +120,7 @@ public static GoalDetailResponseDto toDetailDto(Goal goal, Long savedAmount, int
return new GoalDetailResponseDto(
goal.getId(),
goal.getTitle(),
savedAmount,
currentBalance,
goal.getTargetAmount(),
goal.getStartDate(),
goal.getEndDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ public record GoalCreateResponseDto(
@Schema(description = "목표 금액", example = "1000000")
Long targetAmount,

@Schema(description = "시작 금액", example = "1000")
Long startAmount,

@Schema(description = "시작일", example = "2026-01-01")
LocalDate startDate,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public record GoalDetailResponseDto(
@Schema(description = "목표 제목", example = "여행 자금 모으기")
String title,

@Schema(description = "현재까지 모은 금액", example = "300000")
Long savedAmount,
@Schema(description = "현재 계좌 잔액", example = "300000")
Long currentBalance,

@Schema(description = "목표 금액", example = "1000000")
Long targetAmount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public record GoalSummaryDto(
@Schema(description = "목표 제목", example = "여행 자금 모으기")
String title,

@Schema(description = "모은 금액", example = "700000")
Long savedAmount,
@Schema(description = "현재 계좌 잔액", example = "700000")
Long currentBalance,

@Schema(description = "남은 일수", example = "30")
Long remainingDays,
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/umc/valuedi/domain/goal/entity/Goal.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public class Goal extends BaseEntity {
@Column(name = "target_amount", nullable = false)
private Long targetAmount;

@Column(name = "start_amount", nullable = false)
private Long startAmount;

@Enumerated(EnumType.STRING)
@Column(name = "status", nullable = false, length = 20)
private GoalStatus status;
Expand Down Expand Up @@ -80,7 +77,6 @@ public void changeEndDate(LocalDate endDate) {
public void changeTargetAmount(Long targetAmount) {
this.targetAmount = targetAmount;
}
public void changeStartAmount(Long startAmount) { this.startAmount = startAmount; }

public void changeColor(String color) { this.color = color; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
@Service
public class GoalAchievementRateService {

/**
* @return 0~100 (정수)
*/
public int calculateRate(Long savedAmount, Long targetAmount) {
public int calculateRate(Long currentBalance, Long targetAmount) {
if (targetAmount <= 0) return 0;
if (savedAmount <= 0) return 0;
if (currentBalance <= 0) return 0;

double rate = (savedAmount * 100.0) / targetAmount;
double rate = (currentBalance * 100.0) / targetAmount;
if (rate < 0) rate = 0;
if (rate > 100) rate = 100;
return (int) Math.floor(rate);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package org.umc.valuedi.domain.goal.service;

import jakarta.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.umc.valuedi.domain.asset.entity.BankAccount;
import org.umc.valuedi.domain.asset.service.AssetBalanceService;
import org.umc.valuedi.domain.goal.entity.Goal;
import org.umc.valuedi.domain.goal.enums.GoalStatus;
import org.umc.valuedi.domain.goal.repository.GoalRepository;
Expand All @@ -20,7 +19,6 @@
public class GoalStatusChangeService {

private final GoalRepository goalRepository;
private final AssetBalanceService assetBalanceService;

// 전체 목표 상태 갱신 (스케줄러용)
public void refreshGoalStatuses() {
Expand All @@ -32,24 +30,23 @@ public void refreshGoalStatuses() {
if (account == null || !account.getIsActive()) {
continue;
}
// 최신 잔액 조회 (동기화 포함)
Long currentBalance = assetBalanceService.syncAndGetLatestBalance(goal.getMember().getId(), account.getId());
long savedAmount = currentBalance - goal.getStartAmount();
// DB에 저장된 계좌 잔액 사용
Long currentBalance = account.getBalanceAmount();

checkAndUpdateStatus(goal, savedAmount);
checkAndUpdateStatus(goal, currentBalance);
} catch (Exception e) {
log.error("목표 상태 갱신 중 오류 발생. Goal ID: {}", goal.getId(), e);
}
}
}

// 단일 목표 상태 갱신 (조회 시 호출용)
public void checkAndUpdateStatus(Goal goal, long savedAmount) {
public void checkAndUpdateStatus(Goal goal, long currentBalance) {
if (goal.getStatus() != GoalStatus.ACTIVE) {
return;
}

boolean isTargetReached = savedAmount >= goal.getTargetAmount();
boolean isTargetReached = currentBalance >= goal.getTargetAmount();
// 목표 종료일이 오늘보다 이전이면 만료된 것으로 판단 (종료일 당일까지는 진행 중)
boolean isExpired = goal.getEndDate().isBefore(LocalDate.now());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.umc.valuedi.domain.asset.entity.BankAccount;
import org.umc.valuedi.domain.asset.repository.bank.bankAccount.BankAccountRepository;
import org.umc.valuedi.domain.asset.service.AssetBalanceService;
import org.umc.valuedi.domain.goal.converter.GoalConverter;
import org.umc.valuedi.domain.goal.dto.request.GoalCreateRequestDto;
import org.umc.valuedi.domain.goal.dto.request.GoalUpdateRequestDto;
Expand All @@ -31,7 +30,6 @@ public class GoalCommandService {
private final GoalRepository goalRepository;
private final MemberRepository memberRepository;
private final BankAccountRepository bankAccountRepository;
private final AssetBalanceService assetBalanceService;

// 목표 생성
public GoalCreateResponseDto createGoal(Long memberId, GoalCreateRequestDto req) {
Expand All @@ -51,11 +49,8 @@ public GoalCreateResponseDto createGoal(Long memberId, GoalCreateRequestDto req)
throw new GoalException(GoalErrorCode.ACCOUNT_ALREADY_LINKED_TO_GOAL);
}

// 동기화 후 최신 잔액 가져오기
Long startAmount = assetBalanceService.syncAndGetLatestBalance(memberId, req.bankAccountId());

// Goal 엔티티 생성 시 bankAccount 포함
Goal goal = GoalConverter.toEntity(member, account, req, startAmount);
Goal goal = GoalConverter.toEntity(member, account, req);
Goal saved = goalRepository.save(goal);

return GoalConverter.toCreateDto(saved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ public LedgerListResponse getGoalLedgerTransactions(Long memberId, Long goalId,
throw new GoalException(GoalErrorCode.GOAL_FORBIDDEN);
}

// 시작 시간: 목표 생성 시각 (createdAt)
LocalDateTime from = goal.getCreatedAt();
if (goal.getStartDate().atStartOfDay().isAfter(from)) {
from = goal.getStartDate().atStartOfDay();
}

// 시작 시간: 목표의 시작일(startDate)
LocalDateTime from = goal.getStartDate().atStartOfDay();

// 종료 시간: 목표의 종료일(endDate)
LocalDateTime to = goal.getEndDate().atTime(LocalTime.MAX);

Page<LedgerEntry> result = ledgerQueryRepository.searchByPeriodLatest(
Expand Down
Loading