diff --git a/src/main/java/com/sopterm/makeawish/domain/user/AccountInfo.java b/src/main/java/com/sopterm/makeawish/domain/user/AccountInfo.java index fda75ec..4832411 100644 --- a/src/main/java/com/sopterm/makeawish/domain/user/AccountInfo.java +++ b/src/main/java/com/sopterm/makeawish/domain/user/AccountInfo.java @@ -16,16 +16,8 @@ public class AccountInfo { private String name; private String bank; private String account; - private String kakaoPayCode; - private boolean forPayCode; - public AccountInfo updateInfo(String name, String bank, String account, String kakaoPayCode) { - if(nonNull(account) && !this.account.equals(account)) { - this.forPayCode = false; - } - if(nonNull(kakaoPayCode) && !this.kakaoPayCode.equals(kakaoPayCode)) { - this.forPayCode = true; - } + public AccountInfo updateInfo(String name, String bank, String account) { if (nonNull(name)) { this.name = name; } @@ -33,14 +25,9 @@ public AccountInfo updateInfo(String name, String bank, String account, String k this.bank = bank; } if (nonNull(account)) { - this.forPayCode = false; this.account = account; } - if(nonNull(kakaoPayCode)) { - this.forPayCode = true; - this.kakaoPayCode = kakaoPayCode; - } return this; } } diff --git a/src/main/java/com/sopterm/makeawish/domain/user/TransferInfo.java b/src/main/java/com/sopterm/makeawish/domain/user/TransferInfo.java new file mode 100644 index 0000000..25b432c --- /dev/null +++ b/src/main/java/com/sopterm/makeawish/domain/user/TransferInfo.java @@ -0,0 +1,31 @@ +package com.sopterm.makeawish.domain.user; + +import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; +import jakarta.persistence.Embeddable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Embeddable +@NoArgsConstructor +@AllArgsConstructor +public class TransferInfo { + private AccountInfo accountInfo; + private String kakaoPayCode; + private boolean forPayCode; + + public void updateTransferInfo(AccountInfo accountInfo, String kakaoPayCode, boolean forPayCode){ + this.accountInfo = accountInfo; + this.kakaoPayCode = kakaoPayCode; + this.forPayCode = forPayCode; + } + + @Builder + public TransferInfo(UserAccountRequestDTO userAccountRequestDTO){ + this.accountInfo = userAccountRequestDTO.accountInfo(); + this.forPayCode = userAccountRequestDTO.forPayCode(); + this.kakaoPayCode = userAccountRequestDTO.kakaoPayCode(); + } +} diff --git a/src/main/java/com/sopterm/makeawish/domain/user/User.java b/src/main/java/com/sopterm/makeawish/domain/user/User.java index af2095d..5eb8a9b 100644 --- a/src/main/java/com/sopterm/makeawish/domain/user/User.java +++ b/src/main/java/com/sopterm/makeawish/domain/user/User.java @@ -2,18 +2,15 @@ import com.sopterm.makeawish.domain.wish.Wish; import com.sopterm.makeawish.dto.auth.AuthSignInRequestDTO; +import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import static jakarta.persistence.GenerationType.IDENTITY; -import static java.util.Objects.*; @Entity @Getter @@ -48,7 +45,7 @@ public class User { private LocalDateTime createdAt; @Embedded - private AccountInfo account; + private TransferInfo transferInfo; @OneToMany(mappedBy = "wisher") private final List wishes = new ArrayList<>(); @@ -60,21 +57,19 @@ public User(AuthSignInRequestDTO authSignInRequestDto) { this.socialId = authSignInRequestDto.socialId(); this.nickname = authSignInRequestDto.nickname(); this.createdAt = authSignInRequestDto.createdAt(); - this.account = new AccountInfo(null, null, null, null, false); + val account = new AccountInfo(null, null, null); + this.transferInfo = new TransferInfo(account, null, false); } public void updateRefreshToken(String refreshToken) { this.refreshToken = refreshToken; } - public void updateProfile(String name, String bank, String account, String kakaoPayCode) { - updateAccount(name, bank, account, kakaoPayCode); + public void updateProfile(TransferInfo userTransferInfo) { + updateTransferInfo(userTransferInfo); } - public void updateAccount(String name, String bank, String account, String kakaoPayCode) { - if (isNull(this.account)) { - this.account = new AccountInfo(null, null, null, null, false); - } - this.account.updateInfo(name, bank, account, kakaoPayCode); + public void updateTransferInfo(TransferInfo transferInfo){ + this.transferInfo.updateTransferInfo(transferInfo.getAccountInfo(), transferInfo.getKakaoPayCode(), transferInfo.isForPayCode()); } } \ No newline at end of file diff --git a/src/main/java/com/sopterm/makeawish/dto/user/UserAccountRequestDTO.java b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountRequestDTO.java index e225529..b05eaa6 100644 --- a/src/main/java/com/sopterm/makeawish/dto/user/UserAccountRequestDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountRequestDTO.java @@ -3,7 +3,8 @@ import com.sopterm.makeawish.domain.user.AccountInfo; public record UserAccountRequestDTO( - AccountInfo accountInfo, - String phone + AccountInfo accountInfo, + String kakaoPayCode, + boolean forPayCode ) { } diff --git a/src/main/java/com/sopterm/makeawish/dto/user/UserAccountResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountResponseDTO.java index 5de2a75..2230d40 100644 --- a/src/main/java/com/sopterm/makeawish/dto/user/UserAccountResponseDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/user/UserAccountResponseDTO.java @@ -1,24 +1,24 @@ package com.sopterm.makeawish.dto.user; -import static java.util.Objects.*; - -import com.sopterm.makeawish.domain.user.AccountInfo; +import com.sopterm.makeawish.domain.user.TransferInfo; import com.sopterm.makeawish.domain.user.User; import lombok.Builder; +import static java.util.Objects.nonNull; + @Builder public record UserAccountResponseDTO( - Long id, - AccountInfo accountInfo + Long id, + TransferInfo transferInfo ) { - public static UserAccountResponseDTO of(User user) { - return UserAccountResponseDTO.builder() - .id(user.getId()) - .accountInfo(getUserAccount(user)) - .build(); - } + public static UserAccountResponseDTO of(User user) { + return UserAccountResponseDTO.builder() + .id(user.getId()) + .transferInfo(getUserTransferInfo(user)) + .build(); + } - private static AccountInfo getUserAccount(User user) { - return nonNull(user.getAccount()) ? user.getAccount() : null; - } + private static TransferInfo getUserTransferInfo(User user) { + return nonNull(user.getTransferInfo()) ? user.getTransferInfo() : null; + } } diff --git a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java index e35b39a..a765780 100644 --- a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateRequestDTO.java @@ -1,17 +1,16 @@ package com.sopterm.makeawish.dto.wish; +import com.sopterm.makeawish.domain.user.TransferInfo; import lombok.Builder; @Builder public record UserWishUpdateRequestDTO( String startDate, String endDate, - String name, - String bankName, - String account, String imageUrl, String title, boolean wantsGift, - String kakaoPayCode + String hint, + TransferInfo transferInfo ) { } diff --git a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java index 489da3f..0eb6b5c 100644 --- a/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/wish/UserWishUpdateResponseDTO.java @@ -1,31 +1,34 @@ package com.sopterm.makeawish.dto.wish; -import static java.util.Objects.*; - -import com.sopterm.makeawish.domain.user.AccountInfo; import com.sopterm.makeawish.domain.user.User; +import com.sopterm.makeawish.domain.user.TransferInfo; import com.sopterm.makeawish.domain.wish.Wish; import com.sopterm.makeawish.domain.wish.WishStatus; - import lombok.Builder; +import static java.util.Objects.nonNull; + @Builder public record UserWishUpdateResponseDTO( - String startDate, - String endDate, - AccountInfo accountInfo, - String imageUrl, - String title, - WishStatus status + String startDate, + String endDate, + TransferInfo transferInfo, + String imageUrl, + String title, + WishStatus status, + String hint, + boolean wantsGift ) { - public static UserWishUpdateResponseDTO of(User user, Wish wish) { - return UserWishUpdateResponseDTO.builder() - .startDate(wish.getStartAt().toString()) - .endDate(wish.getEndAt().toString()) - .accountInfo(nonNull(user.getAccount()) ? user.getAccount() : null) - .imageUrl(wish.getPresentImageUrl()) - .title(wish.getTitle()) - .status(wish.getStatus(0)) - .build(); - } + public static UserWishUpdateResponseDTO of(User user, Wish wish) { + return UserWishUpdateResponseDTO.builder() + .startDate(wish.getStartAt().toString()) + .endDate(wish.getEndAt().toString()) + .transferInfo(nonNull(user.getTransferInfo()) ? user.getTransferInfo() : null) + .imageUrl(wish.getPresentImageUrl()) + .title(wish.getTitle()) + .status(wish.getStatus(0)) + .hint(wish.getHint()) + .wantsGift(wish.isWantsGift()) + .build(); + } } diff --git a/src/main/java/com/sopterm/makeawish/dto/wish/WishResponseDTO.java b/src/main/java/com/sopterm/makeawish/dto/wish/WishResponseDTO.java index 595a5fe..61ef721 100644 --- a/src/main/java/com/sopterm/makeawish/dto/wish/WishResponseDTO.java +++ b/src/main/java/com/sopterm/makeawish/dto/wish/WishResponseDTO.java @@ -1,41 +1,37 @@ package com.sopterm.makeawish.dto.wish; -import static com.sopterm.makeawish.common.message.ErrorMessage.*; -import static java.util.Objects.*; +import com.sopterm.makeawish.domain.user.TransferInfo; +import com.sopterm.makeawish.domain.wish.Wish; +import lombok.Builder; +import lombok.val; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; -import com.sopterm.makeawish.domain.wish.Wish; - -import lombok.*; -import org.apache.commons.lang3.StringUtils; +import static com.sopterm.makeawish.common.message.ErrorMessage.EXPIRE_WISH; @Builder -public record WishResponseDTO(String name, long dayCount, String title, String hint, String bank, String accountNumber, boolean wantsGift, String presentImageUrl, String kakaoPayCode, boolean forPayCode) { +public record WishResponseDTO(long dayCount, String title, String hint, boolean wantsGift, String presentImageUrl, TransferInfo transferInfo) { public static WishResponseDTO from(Wish wish) { - val name = nonNull(wish.getWisher().getAccount()) - ? wish.getWisher().getAccount().getName() - : wish.getWisher().getNickname(); - - val account = nonNull(wish.getWisher().getAccount()) - ? wish.getWisher().getAccount().getAccount() - : StringUtils.EMPTY; - val bank = nonNull(wish.getWisher().getAccount()) - ? wish.getWisher().getAccount().getBank() - : StringUtils.EMPTY; - - val kakaoPayCode = nonNull(wish.getWisher().getAccount().getKakaoPayCode()) - ? wish.getWisher().getAccount().getKakaoPayCode() - : StringUtils.EMPTY; +// UserTransferInfo userTransferInfo = wish.getWisher().getUserTransferInfo(); +// val name = nonNull(userTransferInfo.getAccountInfo().getName()) +// ? userTransferInfo.getAccountInfo().getName() +// : wish.getWisher().getNickname(); +// +// val account = nonNull(wish.getWisher().getUserTransferInfo().getAccountInfo().getAccount()) +// ? userTransferInfo.getAccountInfo().getAccount() +// : StringUtils.EMPTY; +// val bank = nonNull(wish.getWisher().getUserTransferInfo().) +// ? userTransferInfo.getAccount().getBank() +// : StringUtils.EMPTY; +// +// val kakaoPayCode = nonNull(wish.getWisher().getAccount().getKakaoPayCode()) +// ? userTransferInfo.getKakaoPayCode() +// : StringUtils.EMPTY; return WishResponseDTO.builder() - .name(name) - .accountNumber(account) - .bank(bank) - .kakaoPayCode(kakaoPayCode) - .forPayCode(wish.getWisher().getAccount().isForPayCode()) + .transferInfo(wish.getWisher().getTransferInfo()) .dayCount(getRemainDayCount(wish.getEndAt())) .title(wish.getTitle()) .hint(wish.getHint()) diff --git a/src/main/java/com/sopterm/makeawish/service/UserService.java b/src/main/java/com/sopterm/makeawish/service/UserService.java index 44d39ee..f8c12f2 100644 --- a/src/main/java/com/sopterm/makeawish/service/UserService.java +++ b/src/main/java/com/sopterm/makeawish/service/UserService.java @@ -3,6 +3,7 @@ import com.popbill.api.AccountCheckService; import com.popbill.api.PopbillException; import com.sopterm.makeawish.domain.abuse.AbuseLog; +import com.sopterm.makeawish.domain.user.TransferInfo; import com.sopterm.makeawish.domain.user.User; import com.sopterm.makeawish.dto.user.UserAccountRequestDTO; import com.sopterm.makeawish.dto.user.UserAccountResponseDTO; @@ -39,20 +40,16 @@ public class UserService { public UserAccountResponseDTO getUserAccount(Long userId) { val wisher = getUser(userId); - return nonNull(wisher.getAccount()) ? UserAccountResponseDTO.of(wisher) : null; + return nonNull(wisher.getTransferInfo().getAccountInfo()) || nonNull(wisher.getTransferInfo().getKakaoPayCode()) ? UserAccountResponseDTO.of(wisher) : null; } @Transactional public UserAccountResponseDTO updateUserAccount(Long userId, UserAccountRequestDTO requestDTO) { val wisher = getUser(userId); - if (isNull(requestDTO.accountInfo())) { + if (isNull(requestDTO.kakaoPayCode()) && isNull(requestDTO.accountInfo())) { throw new IllegalArgumentException(NO_EXIST_USER_ACCOUNT.getMessage()); } - wisher.updateAccount( - requestDTO.accountInfo().getName(), - requestDTO.accountInfo().getBank(), - requestDTO.accountInfo().getAccount(), - requestDTO.accountInfo().getKakaoPayCode()); + wisher.updateTransferInfo(new TransferInfo(requestDTO)); return UserAccountResponseDTO.of(wisher); } diff --git a/src/main/java/com/sopterm/makeawish/service/WishService.java b/src/main/java/com/sopterm/makeawish/service/WishService.java index 948ea79..e3934cf 100644 --- a/src/main/java/com/sopterm/makeawish/service/WishService.java +++ b/src/main/java/com/sopterm/makeawish/service/WishService.java @@ -129,7 +129,8 @@ public UserWishUpdateResponseDTO updateUserMainWish(Long userId, UserWishUpdateR } if (status.equals(BEFORE) || status.equals(WHILE)) { wish.updateContent(request.imageUrl(), request.title(), request.wantsGift()); - wisher.updateProfile(request.name(), request.bankName(), request.account(), request.kakaoPayCode()); + wisher.updateProfile(request.transferInfo()); + } return UserWishUpdateResponseDTO.of(wisher, wish);