Skip to content

Commit

Permalink
Merge pull request #210 from Make-A-Wish-Sopt/feature/jiyoung-#208
Browse files Browse the repository at this point in the history
[FIX] 추가 수정사항 반영
  • Loading branch information
wlwpfh authored Nov 24, 2024
2 parents a459b1d + ba9f91d commit c7088fa
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 35 deletions.
16 changes: 15 additions & 1 deletion src/main/java/com/sopterm/makeawish/domain/user/AccountInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,31 @@ 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) {
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;
}
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;
}
}
21 changes: 6 additions & 15 deletions src/main/java/com/sopterm/makeawish/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class User {
@Embedded
private AccountInfo account;

private String phoneNumber;

@OneToMany(mappedBy = "wisher")
private final List<Wish> wishes = new ArrayList<>();

Expand All @@ -62,28 +60,21 @@ public User(AuthSignInRequestDTO authSignInRequestDto) {
this.socialId = authSignInRequestDto.socialId();
this.nickname = authSignInRequestDto.nickname();
this.createdAt = authSignInRequestDto.createdAt();
this.account = new AccountInfo(null, null, null);
this.account = new AccountInfo(null, null, null, null, false);
}

public void updateRefreshToken(String refreshToken) {
this.refreshToken = refreshToken;
}

public void updateProfile(String name, String bank, String account, String phoneNumber) {
updatePhoneNumber(phoneNumber);
updateAccount(name, bank, account);
}

public void updatePhoneNumber(String phoneNumber) {
if (nonNull(phoneNumber)) {
this.phoneNumber = phoneNumber;
}
public void updateProfile(String name, String bank, String account, String kakaoPayCode) {
updateAccount(name, bank, account, kakaoPayCode);
}

public void updateAccount(String name, String bank, String account) {
public void updateAccount(String name, String bank, String account, String kakaoPayCode) {
if (isNull(this.account)) {
this.account = new AccountInfo(null, null, null);
this.account = new AccountInfo(null, null, null, null, false);
}
this.account.updateInfo(name, bank, account);
this.account.updateInfo(name, bank, account, kakaoPayCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
@Builder
public record UserAccountResponseDTO(
Long id,
AccountInfo accountInfo,
String phone
AccountInfo accountInfo
) {
public static UserAccountResponseDTO of(User user) {
return UserAccountResponseDTO.builder()
.id(user.getId())
.accountInfo(getUserAccount(user))
.phone(user.getPhoneNumber())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static UserWishResponseDTO of(Wish wish) {
.title(wish.getTitle())
.startAt(wish.getStartAt().toString())
.endAt(wish.getEndAt().toString())

.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public record UserWishUpdateRequestDTO(
String name,
String bankName,
String account,
String phone,
String imageUrl,
String title,
boolean wantsGift
boolean wantsGift,
String kakaoPayCode
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
public record UserWishUpdateResponseDTO(
String startDate,
String endDate,
String phone,
AccountInfo accountInfo,
String imageUrl,
String title,
Expand All @@ -23,7 +22,6 @@ public static UserWishUpdateResponseDTO of(User user, Wish wish) {
return UserWishUpdateResponseDTO.builder()
.startDate(wish.getStartAt().toString())
.endDate(wish.getEndAt().toString())
.phone(user.getPhoneNumber())
.accountInfo(nonNull(user.getAccount()) ? user.getAccount() : null)
.imageUrl(wish.getPresentImageUrl())
.title(wish.getTitle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ public record WishRequestDTO(
String title,
String startDate,
String endDate,
String phone,
boolean wantsGift,
String hint
) {

public Wish toEntity(User wisher) {
wisher.updatePhoneNumber(phone);
return Wish.builder()
.presentImageUrl(imageUrl)
.hint(hint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.apache.commons.lang3.StringUtils;

@Builder
public record WishResponseDTO(String name, long dayCount, String title, String hint, String bank, String accountNumber, boolean wantsGift, String presentImageUrl) {
public record WishResponseDTO(String name, long dayCount, String title, String hint, String bank, String accountNumber, boolean wantsGift, String presentImageUrl, String kakaoPayCode, boolean forPayCode) {

public static WishResponseDTO from(Wish wish) {
val name = nonNull(wish.getWisher().getAccount())
Expand All @@ -26,10 +26,16 @@ public static WishResponseDTO from(Wish wish) {
? wish.getWisher().getAccount().getBank()
: StringUtils.EMPTY;

val kakaoPayCode = nonNull(wish.getWisher().getAccount().getKakaoPayCode())
? wish.getWisher().getAccount().getKakaoPayCode()
: StringUtils.EMPTY;

return WishResponseDTO.builder()
.name(name)
.accountNumber(account)
.bank(bank)
.kakaoPayCode(kakaoPayCode)
.forPayCode(wish.getWisher().getAccount().isForPayCode())
.dayCount(getRemainDayCount(wish.getEndAt()))
.title(wish.getTitle())
.hint(wish.getHint())
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/sopterm/makeawish/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public UserAccountResponseDTO updateUserAccount(Long userId, UserAccountRequestD
wisher.updateAccount(
requestDTO.accountInfo().getName(),
requestDTO.accountInfo().getBank(),
requestDTO.accountInfo().getAccount());
wisher.updatePhoneNumber(requestDTO.phone());
requestDTO.accountInfo().getAccount(),
requestDTO.accountInfo().getKakaoPayCode());
return UserAccountResponseDTO.of(wisher);
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/sopterm/makeawish/service/WishService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public Long createWish(Long userId, WishRequestDTO requestDTO) {
} catch (RuntimeException e) {
log.error(SlackErrorMessage.POST_REQUEST_ERROR.getMessage() + e.getMessage());
}
Long wishId = wishRepository.save(wish).getId();
presentRepository.save(Present.initAdminPresent(wish));
return wishId;
return wishRepository.save(wish).getId();
}

public WishResponseDTO findWish(Long wishId) throws AccessDeniedException {
Expand Down Expand Up @@ -131,7 +129,7 @@ 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.phone());
wisher.updateProfile(request.name(), request.bankName(), request.account(), request.kakaoPayCode());
}

return UserWishUpdateResponseDTO.of(wisher, wish);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/sopterm/makeawish/config/CacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private String getLocalDateTime(int plusDays) {


private User createUser() {
AccountInfo accountInfo = new AccountInfo("김아무", "bank", "account");
AccountInfo accountInfo = new AccountInfo("김아무", "bank", "account", "kakaoPayCode", true);
return User.builder()
.email("kim@email.com")
.socialType(SocialType.KAKAO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private String getLocalDateTime(int plusDays){


private User createUser(){
AccountInfo accountInfo = new AccountInfo("김아무", "bank", "account");
AccountInfo accountInfo = new AccountInfo("김아무", "bank", "account", "kakaoPayCode", false);
return User.builder()
.email("kim@email.com")
.socialType(SocialType.KAKAO)
Expand Down

0 comments on commit c7088fa

Please sign in to comment.