Skip to content

Commit

Permalink
Merge pull request #212 from Make-A-Wish-Sopt/feature/jioyung-#211-de…
Browse files Browse the repository at this point in the history
…velop

[FEAT] 계좌 구조 수정
  • Loading branch information
wlwpfh authored Nov 27, 2024
2 parents c7088fa + 97c5cc8 commit a47851d
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 102 deletions.
15 changes: 1 addition & 14 deletions src/main/java/com/sopterm/makeawish/domain/user/AccountInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,18 @@ 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;
}
if (nonNull(bank)) {
this.bank = bank;
}
if (nonNull(account)) {
this.forPayCode = false;
this.account = account;
}

if(nonNull(kakaoPayCode)) {
this.forPayCode = true;
this.kakaoPayCode = kakaoPayCode;
}
return this;
}
}
31 changes: 31 additions & 0 deletions src/main/java/com/sopterm/makeawish/domain/user/TransferInfo.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
23 changes: 9 additions & 14 deletions src/main/java/com/sopterm/makeawish/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,7 +45,7 @@ public class User {
private LocalDateTime createdAt;

@Embedded
private AccountInfo account;
private TransferInfo transferInfo;

@OneToMany(mappedBy = "wisher")
private final List<Wish> wishes = new ArrayList<>();
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.sopterm.makeawish.domain.user.AccountInfo;

public record UserAccountRequestDTO(
AccountInfo accountInfo,
String phone
AccountInfo accountInfo,
String kakaoPayCode,
boolean forPayCode
) {
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
48 changes: 22 additions & 26 deletions src/main/java/com/sopterm/makeawish/dto/wish/WishResponseDTO.java
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/sopterm/makeawish/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/sopterm/makeawish/service/WishService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a47851d

Please sign in to comment.