Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor: 프로필 조회 response 수정, 계좌 배송지 다중 등록 가능하게 변경 #152

Merged
merged 1 commit into from
Feb 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -204,62 +204,59 @@ public static ProfileImg toProfileImg(String url, Member member) {
.build();
}

public static MemberResponseDTO.ProfileResultDTO toProfile(Member member, String url, Optional<Account> account, Optional<Address> address) {
public static MemberResponseDTO.ProfileResultDTO toProfile(Member member, String url, List<Account> account, List<Address> address) {

List<MemberResponseDTO.AccountDTO> accountList = account.stream().map(a -> MemberResponseDTO.AccountDTO.builder()
.id(a.getId())
.accountNum(a.getAccountNum())
.bankName(a.getBankName())
.owner(a.getOwner())
.defaultCheck(a.getDefaultCheck())
.build()).collect(Collectors.toList());
List<MemberResponseDTO.AddressDTO> addressList = address.stream().map(a -> MemberResponseDTO.AddressDTO.builder()
.addressName(a.getAddressName())
.addressSpec(a.getAddressSpec())
.deliveryMemo(a.getDeliveryMemo())
.defaultCheck(a.getDefaultCheck())
.recipientName(a.getRecipientName())
.recipientPhone(a.getRecipientPhone())
.id(a.getId())
.zipcode(a.getZipcode()).build()).collect(Collectors.toList());

if (address.isEmpty() && account.isEmpty()){
return MemberResponseDTO.ProfileResultDTO.builder()
.name(member.getName())
.phone(member.getPhone())
.url(url)
.address(null)
.deliveryMemo(null)
.addressDetail(null)
.zipcode(null)
.refundAccount(null)
.refundBank(null)
.refundOwner(null)
.accountList(null)
.addressList(null)
.build();
}
if (account.isEmpty()){
return MemberResponseDTO.ProfileResultDTO.builder()
.name(member.getName())
.phone(member.getPhone())
.url(url)
.address(address.get().getAddressName())
.deliveryMemo(address.get().getDeliveryMemo())
.addressDetail(address.get().getAddressSpec())
.zipcode(address.get().getZipcode())
.refundAccount(null)
.refundBank(null)
.refundOwner(null)
.addressList(addressList)
.accountList(accountList)
.build();
}
if(address.isEmpty()){
return MemberResponseDTO.ProfileResultDTO.builder()
.name(member.getName())
.phone(member.getPhone())
.url(url)
.address(null)
.deliveryMemo(null)
.addressDetail(null)
.zipcode(null)
.refundAccount(account.get().getAccountNum())
.refundBank(account.get().getBankName())
.refundOwner(account.get().getOwner())
.addressList(null)
.accountList(accountList)
.build();
}

return MemberResponseDTO.ProfileResultDTO.builder()
.name(member.getName())
.phone(member.getPhone())
.url(url)
.address(address.get().getAddressName())
.deliveryMemo(address.get().getDeliveryMemo())
.addressDetail(address.get().getAddressSpec())
.zipcode(address.get().getZipcode())
.refundAccount(account.get().getAccountNum())
.refundBank(account.get().getBankName())
.refundOwner(account.get().getOwner())
.addressList(addressList)
.accountList(accountList)
.build();
}

Expand Down Expand Up @@ -322,6 +319,9 @@ public static Address toAddress(MemberRequestDTO.AddressDTO request,Member membe
.addressSpec(request.getAddressSpec())
.deliveryMemo(request.getDeliveryMemo())
.zipcode(request.getZipcode())
.recipientName(request.getRecipientName())
.recipientPhone(request.getRecipientPhone())
.defaultCheck(request.getDefaultCheck())
.member(member)
.build();
}
Expand All @@ -332,6 +332,7 @@ public static Account toAccount(MemberRequestDTO.AccountDTO request, Member memb
.accountNum(request.getAccountNum())
.bankName(request.getBankName())
.owner(request.getOwner())
.defaultCheck(request.getDefaultCheck())
.member(member)
.build();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/umc/TheGoods/domain/mypage/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.umc.TheGoods.domain.common.BaseDateTimeEntity;
import com.umc.TheGoods.domain.member.Member;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;

Expand All @@ -29,6 +30,10 @@ public class Account extends BaseDateTimeEntity {
@Column(columnDefinition = "VARCHAR(16)", nullable = false)
private String accountNum;

@Column(columnDefinition = "BOOLEAN")
@ColumnDefault("false")
private Boolean defaultCheck;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/umc/TheGoods/domain/mypage/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.umc.TheGoods.domain.common.BaseDateTimeEntity;
import com.umc.TheGoods.domain.member.Member;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.*;

Expand Down Expand Up @@ -30,6 +31,17 @@ public class Address extends BaseDateTimeEntity {
@Column(columnDefinition = "VARCHAR(10)", nullable = false)
private String zipcode;

@Column(columnDefinition = "BOOLEAN")
@ColumnDefault("false")
private Boolean defaultCheck;

@Column(columnDefinition = "VARCHAR(20)")
private String recipientPhone;

@Column(columnDefinition = "VARCHAR(10)")
private String recipientName;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

public interface AccountRepository extends JpaRepository<Account, Long> {

Optional<Account> findByMember_Id(Long id);
List<Account> findAllByMember_Id(Long id);

@Transactional
@Modifying(clearAutomatically = true)
@Query("UPDATE Account a SET a.accountNum = :accountNum, a.bankName = :bankName, a.owner = :owner WHERE a.id = :accountId")
void changeAccount(Long accountId, String accountNum,String bankName, String owner);
@Query("UPDATE Account a SET a.accountNum = :accountNum, a.bankName = :bankName, a.owner = :owner, a.defaultCheck = :defaultCheck WHERE a.id = :accountId")
void changeAccount(Long accountId, String accountNum,String bankName, String owner, Boolean defaultCheck);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

public interface AddressRepository extends JpaRepository<Address, Long> {

Optional<Address> findByMember_Id(Long id);
List<Address> findAllByMember_Id(Long id);

@Transactional
@Modifying(clearAutomatically = true)
@Query("UPDATE Address a SET a.addressName = :addressName, a.addressSpec = :addressSpec, a.deliveryMemo = :deliveryMemo, a.zipcode = :zipcode WHERE a.id = :addressId")
void changeAddress(Long addressId, String addressName, String addressSpec,String deliveryMemo,String zipcode);
@Query("UPDATE Address a SET a.addressName = :addressName, a.addressSpec = :addressSpec, a.deliveryMemo = :deliveryMemo, a.zipcode = :zipcode, a.defaultCheck = :defaultCheck, a.recipientName = :recipientName, a.recipientPhone = :recipientPhone WHERE a.id = :addressId")
void changeAddress(Long addressId, String addressName, String addressSpec,String deliveryMemo,String zipcode, Boolean defaultCheck, String recipientPhone, String recipientName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ public Account postAccount(MemberRequestDTO.AccountDTO request, Member member) {
public void updateAddress(MemberRequestDTO.AddressDTO request, Long addressId) {

Address address = addressRepository.findById(addressId).orElseThrow(()-> new MemberHandler(ErrorStatus.MEMBER_ADDRESS_NOT_FOUND));
addressRepository.changeAddress(addressId, request.getAddressName(),request.getAddressSpec(), request.getDeliveryMemo(), request.getZipcode());
addressRepository.changeAddress(addressId, request.getAddressName(),request.getAddressSpec(), request.getDeliveryMemo(), request.getZipcode(), request.getDefaultCheck(),request.getRecipientName(),request.getRecipientPhone());


}
Expand All @@ -606,8 +606,7 @@ public void updateAddress(MemberRequestDTO.AddressDTO request, Long addressId) {
public void updateAccount(MemberRequestDTO.AccountDTO request, Long accountId) {

Account account = accountRepository.findById(accountId).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_ACCOUNT_NOT_FOUND));
accountRepository.changeAccount(accountId, request.getAccountNum(),request.getBankName(),request.getOwner());

accountRepository.changeAccount(accountId, request.getAccountNum(),request.getBankName(),request.getOwner(),request.getDefaultCheck());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.umc.TheGoods.domain.mypage.Account;
import com.umc.TheGoods.domain.mypage.Address;

import java.util.List;
import java.util.Optional;

public interface MemberQueryService {
Expand All @@ -16,7 +17,7 @@ public interface MemberQueryService {

Optional<Member> findMemberByEmail(String email);

Optional<Address> findAddressById(Long id);
List<Address> findAllAddressById(Long id);

Optional<Account> findAccountById(Long id);
List<Account> findAllAccountById(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
Expand Down Expand Up @@ -48,16 +49,16 @@ public Optional<Member> findMemberByEmail(String email) {
}

@Override
public Optional<Address> findAddressById(Long id) {
public List<Address> findAllAddressById(Long id) {

Optional<Address> address = addressRepository.findByMember_Id(id);
List<Address> address = addressRepository.findAllByMember_Id(id);
return address;
}

@Override
public Optional<Account> findAccountById(Long id) {
public List<Account> findAllAccountById(Long id) {

Optional<Account> account = accountRepository.findByMember_Id(id);
List<Account> account = accountRepository.findAllByMember_Id(id);
return account;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;
import java.util.Optional;

@RestController
Expand Down Expand Up @@ -225,8 +226,10 @@ public ApiResponse<MemberResponseDTO.ProfileResultDTO> getProfile(Authentication
MemberDetail memberDetail = (MemberDetail) authentication.getPrincipal();
Member member = memberQueryService.findMemberById(memberDetail.getMemberId()).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND));
Optional<ProfileImg> profileImg = memberQueryService.findProfileImgByMember(member.getId());
Optional<Address> address = memberQueryService.findAddressById(member.getId());
Optional<Account> account = memberQueryService.findAccountById(member.getId());
List<Address> address = memberQueryService.findAllAddressById(member.getId());
List<Account> account = memberQueryService.findAllAccountById(member.getId());



if(profileImg.isEmpty()){
return ApiResponse.onSuccess(MemberConverter.toProfile(member, null, account, address));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public static class AddressDTO {
private String addressSpec;
private String deliveryMemo;
private String zipcode;
private String recipientName;
private String recipientPhone;
private Boolean defaultCheck;
}

@Getter
Expand All @@ -126,5 +129,6 @@ public static class AccountDTO {
private String owner;
private String bankName;
private String accountNum;
private Boolean defaultCheck;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.umc.TheGoods.web.dto.member;

import com.umc.TheGoods.domain.enums.MemberRole;
import com.umc.TheGoods.domain.mypage.Account;
import com.umc.TheGoods.domain.mypage.Address;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;
import java.util.List;

public class MemberResponseDTO {

Expand Down Expand Up @@ -135,13 +143,8 @@ public static class ProfileResultDTO {
String name;
String url;
String phone;
String zipcode;
String address;
String addressDetail;
String deliveryMemo;
String refundBank;
String refundAccount;
String refundOwner;
List<MemberResponseDTO.AddressDTO> addressList;
List<MemberResponseDTO.AccountDTO> accountList;

}

Expand Down Expand Up @@ -170,6 +173,22 @@ public static class AddressResultDTO {
String name;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class AddressDTO {

Long id;
String addressName;
String addressSpec;
String deliveryMemo;
String zipcode;
Boolean defaultCheck;
String recipientPhone;
String recipientName;
}

@Builder
@Getter
@NoArgsConstructor
Expand All @@ -178,5 +197,18 @@ public static class AccountResultDTO {
String name;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class AccountDTO {

Long id;
String owner;
String bankName;
String accountNum;
Boolean defaultCheck;
}


}
Loading