Skip to content

Commit

Permalink
Hotfix: 초기 회비 금액 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
KoungQ committed Jul 31, 2024
1 parent 10dc3aa commit a948c8f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/main/java/leets/weeth/domain/account/dto/AccountDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ public class AccountDTO {
public record Response(
Long id,
String description,
Integer total,
Integer totalAmount,
Integer currentAmount,
Integer cardinal,
List<ReceiptDTO.Response> receipts
) {}

public record Save(
String description,
@NotNull Integer total,
@NotNull Integer totalAmount,
@NotNull Integer cardinal
) {}
}
9 changes: 5 additions & 4 deletions src/main/java/leets/weeth/domain/account/entity/Account.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package leets.weeth.domain.account.entity;

import jakarta.persistence.*;
import leets.weeth.domain.account.dto.ReceiptDTO;
import leets.weeth.global.common.entity.BaseEntity;
import lombok.*;

Expand All @@ -22,20 +21,22 @@ public class Account extends BaseEntity {

private String description;

private Integer total;
private Integer totalAmount;

private Integer currentAmount;

private Integer cardinal;

@OneToMany(mappedBy = "account", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<Receipt> receipts = new ArrayList<>();

public void spend(Receipt receipt) {
this.total -= receipt.getAmount();
this.currentAmount -= receipt.getAmount();
this.receipts.add(receipt);
}

public void cancel(Receipt receipt) {
this.total += receipt.getAmount();
this.currentAmount += receipt.getAmount();
this.receipts.remove(receipt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface AccountMapper {
@Mapping(target = "receipts", expression = "java( mapToReceiptDTO(account, receiptMapper) )")
AccountDTO.Response to(Account account, @Context ReceiptMapper receiptMapper);

@Mapping(target = "currentAmount", source = "totalAmount")
Account from(AccountDTO.Save dto);

@Named("mapToReceiptDTO")
Expand Down

0 comments on commit a948c8f

Please sign in to comment.