From 7b77ce2461c923e74eaeaf2182e2ae2c8b649cb8 Mon Sep 17 00:00:00 2001 From: joon Date: Sat, 25 May 2024 04:11:24 +0900 Subject: [PATCH 1/3] =?UTF-8?q?:sparkles:=20feat:=20=EB=B0=B0=EC=86=A1?= =?UTF-8?q?=EC=A7=80,=20=ED=99=98=EB=B6=88=20=EA=B3=84=EC=A2=8C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20page=20=EC=A1=B0=ED=9A=8C=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/member/MemberConverter.java | 57 +++---------- .../OrderService/OrderQueryService.java | 2 +- .../OrderService/OrderQueryServiceImpl.java | 31 -------- .../web/controller/MyPageController.java | 79 ++++++++----------- .../web/dto/member/MemberResponseDTO.java | 37 +++------ 5 files changed, 55 insertions(+), 151 deletions(-) diff --git a/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java b/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java index a0d44ac..112026d 100644 --- a/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java +++ b/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java @@ -169,21 +169,6 @@ public static Auth toEmailAuth(String email, String code, Boolean expired) { .build(); } - public static MemberResponseDTO.EmailAuthConfirmResultDTO toEmailAuthConfirmResultDTO(Boolean checkEmail, String jwt) { - - - return MemberResponseDTO.EmailAuthConfirmResultDTO.builder() - .checkEmail(checkEmail) - .jwt(jwt) - .build(); - } - - public static MemberResponseDTO.SocialLoginResultDTO toSocialLoginResultDTO(String result) { - - return MemberResponseDTO.SocialLoginResultDTO.builder() - .result(result) - .build(); - } public static MemberResponseDTO.SocialJoinResultDTO toSocialJoinResultDTO(String phone, String email) { @@ -307,20 +292,6 @@ public static Member toUpdateProfile(Member member, ProfileImg profileImg, Strin .build(); } - public static MemberResponseDTO.RoleUpdateResultDTO toUpdateRole(Member member) { - - return MemberResponseDTO.RoleUpdateResultDTO.builder() - .role(member.getMemberRole()) - .build(); - } - - public static MemberResponseDTO.PhoneNameUpdateResultDTO toUpdatePhoneName(Member member) { - - return MemberResponseDTO.PhoneNameUpdateResultDTO.builder() - .name(member.getName()) - .phone(member.getPhone()) - .build(); - } public static Address toAddress(MemberRequestDTO.AddressDTO request,Member member){ return Address.builder() @@ -347,6 +318,7 @@ public static Account toAccount(MemberRequestDTO.AccountDTO request, Member memb } + public static MemberResponseDTO.AddressResultDTO toPostAddressDTO(String address){ return MemberResponseDTO.AddressResultDTO.builder() @@ -364,25 +336,6 @@ public static MemberResponseDTO.AccountResultDTO toPostAccountDTO(String account } - public static MemberResponseDTO.MyPageOrderItemDTO toMyPageOrderItemDTO(OrderItem orderItem, Item item){ - - List itemImgResponseDTOList = item.getItemImgList().stream() - .map(ItemConverter::getItemImgDTO) - .filter(ItemResponseDTO.ItemImgResponseDTO::getIsThumbNail).collect(Collectors.toList()); - - List itemOptionList = item.getItemOptionList().stream() - .map(ItemOption::getName).collect(Collectors.toList()); - - return MemberResponseDTO.MyPageOrderItemDTO.builder() - .id(orderItem.getId()) - .imageUrl(itemImgResponseDTOList.get(0).getItemImgUrl()) - .option(itemOptionList) - .name(item.getName()) - .orderStatus(orderItem.getStatus()) - .price(item.getPrice()) - .time(orderItem.getCreatedAt()) - .build(); - } public static List toGetAccountDTO(List account){ @@ -411,6 +364,14 @@ public static List toGetAddressDTO(List
a return addressList; } + public static MemberResponseDTO.AddressAndAccountDTO toGetAddressAndAccountDTO(List
address, List account){ + + + return MemberResponseDTO.AddressAndAccountDTO.builder() + .accountDTO(toGetAccountDTO(account)) + .addressDTO(toGetAddressDTO(address)) + .build(); + } public static Declaration toDeclaration(Member member, MemberRequestDTO.DeclareDTO request){ diff --git a/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryService.java b/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryService.java index df0b030..626b76a 100644 --- a/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryService.java +++ b/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryService.java @@ -25,5 +25,5 @@ public interface OrderQueryService { boolean isExistOrderItem(Long id); - MemberResponseDTO.MyPageOrderItemListDTO getMyPageOrderItemList(Member member, OrderStatus orderStatus, Integer pageIdx); + } diff --git a/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryServiceImpl.java b/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryServiceImpl.java index 2908f81..953434f 100644 --- a/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryServiceImpl.java +++ b/src/main/java/com/umc/TheGoods/service/OrderService/OrderQueryServiceImpl.java @@ -92,37 +92,6 @@ public boolean isExistOrderItem(Long id) { } - @Override - public MemberResponseDTO.MyPageOrderItemListDTO getMyPageOrderItemList(Member member, OrderStatus orderStatus, Integer pageIdx) { - - Page orderItemList; - - - if (orderStatus == null) { // orderStatus 값이 없으면 전체 상태 조회 (필터링X) - orderItemList = orderItemRepository.findAllByOrdersIn(member.getOrdersList(), PageRequest.of(pageIdx, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); - } else { // orderStatus 값에 맞는 내역만 필터링 - orderItemList = orderItemRepository.findAllByStatusAndOrdersIn(orderStatus, member.getOrdersList(), PageRequest.of(pageIdx, pageSize, Sort.by(Sort.Direction.DESC, "createdAt"))); - } - - - List itemList = orderItemList.getContent(); - List itemListDTOList = itemList.stream() - .map(i ->{ - Item item = itemRepository.findItemByOrderItem(i.getId()); - return MemberConverter.toMyPageOrderItemDTO(i,item); - }).collect(Collectors.toList()); - - return MemberResponseDTO.MyPageOrderItemListDTO.builder() - .itemList(itemListDTOList) - .isFirst(orderItemList.isFirst()) - .isLast(orderItemList.isLast()) - .listSize(orderItemList.getSize()) - .totalPage(orderItemList.getTotalPages()) - .totalElements(orderItemList.getTotalElements()) - .build(); - - - } } diff --git a/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java b/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java index d9bfe98..64d6ecd 100644 --- a/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java +++ b/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java @@ -62,6 +62,30 @@ public ApiResponse profileModify(@Requ } + @GetMapping(value = "/profile") + @Operation(summary = "프로필 조회 api", description = "프로필이미지, 닉네임, 주소, 계좌, 팔로잉 수, 찜 수를 조회할 수 있습니다.") + public ApiResponse getProfile(Authentication authentication) { + + + + Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + Optional profileImg = memberQueryService.findProfileImgByMember(member.getId()); + List
address = memberQueryService.findAllAddressById(member.getId()); + List account = memberQueryService.findAllAccountById(member.getId()); + Long following = Long.valueOf(member.getFollowingList().size()); + Long dibs = Long.valueOf(member.getDibsList().size()); + + + + if(profileImg.isEmpty()){ + return ApiResponse.onSuccess(MemberConverter.toProfile(member, null, account, address,following,dibs)); + } + else { + return ApiResponse.onSuccess(MemberConverter.toProfile(member, profileImg.get().getUrl(),account, address,following,dibs)); + } + + + } @@ -163,6 +187,16 @@ public ApiResponse> getAddress(Authentication return ApiResponse.onSuccess(MemberConverter.toGetAddressDTO(addressList)); } + @GetMapping(value = "/address/account") + @Operation(summary = "mypage 배송지, 환불 계좌 조회 page") + public ApiResponse getAddressAndAccount(Authentication authentication){ + Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + List accountList = memberQueryService.findAccountById(member.getId()); + List
addressList = memberQueryService.findAllAddressById(member.getId()); + + return ApiResponse.onSuccess(MemberConverter.toGetAddressAndAccountDTO(addressList,accountList)); + } + @DeleteMapping(value = "/delete") @Operation(summary = "회원 탈퇴 api", description = "request: 회원 탈퇴 사유 번호로 주시면 됩니다") public ApiResponse deleteMember(@RequestBody MemberRequestDTO.WithdrawReasonDTO request, @@ -173,28 +207,6 @@ public ApiResponse deleteMember(@RequestBody MemberRequestDTO.WithdrawReasonD return ApiResponse.of(SuccessStatus.MEMBER_DELETE_SUCCESS, null); } - /** - * 한 페이지에 8개씩 상품정보 가져오기 - * OrderStatus 결제전, 결제 완료, 배송준비, 배송 시작, 배송완료, 주문 취소, 구매 확정, 반품 진행중, 반품 완료 주문 상태 별로 상품 조회 가능해야함 - * 주문시간, 주문상태(결제전, 결제완료), 상품 이름, 상품 옵션, 가격, 사진 - */ - @GetMapping(value = "/item") - @Operation(summary = "mypage 구매관리 조회 api", description = "마이페이지에서 구매관리 페이지에서 상품정보를 가져오는 api입니다.\n" + - "request parameter에 페이지 번호와 주문 상태를 넣어줘야합니다.") - @Parameters(value = { - @Parameter(name = "page", description = "페이지 번호, 1 이상의 숫자를 입력해주세요."), - @Parameter(name = "orderStatus", description = "전체 조회: null, 결제전: PAY_PREV, 결제완료: PAY_COMP, 배송준비: DEL_PREP, 배송시작: DEL_START, 배송완료: DEL_COMP, 주문취소: CANCEL, 구매확정: CONFIRM, 반품 진행중: REFUND_ONGOING, 반품완료: REFUND_COMP") - }) - public ApiResponse getMyPageItemList(@CheckPage @RequestParam Integer page, - @RequestParam(required = false) OrderStatus orderStatus, - Authentication authentication){ - // jwt로 사용자 정보 찾기 - Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - - - - return ApiResponse.onSuccess(orderQueryService.getMyPageOrderItemList(member,orderStatus,page)); - } /** * @@ -274,30 +286,7 @@ public ApiResponse getContact(Authentication authentication){ return ApiResponse.onSuccess(MemberConverter.toContactDTO(contactTime)); } - @GetMapping(value = "/profile") - @Operation(summary = "프로필 조회 api", description = "프로필이미지, 닉네임, 주소, 계좌, 팔로잉 수, 찜 수를 조회할 수 있습니다.") - public ApiResponse getProfile(Authentication authentication) { - - - - Member member = memberQueryService.findMemberById(Long.valueOf(authentication.getName().toString())).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - Optional profileImg = memberQueryService.findProfileImgByMember(member.getId()); - List
address = memberQueryService.findAllAddressById(member.getId()); - List account = memberQueryService.findAllAccountById(member.getId()); - Long following = Long.valueOf(member.getFollowingList().size()); - Long dibs = Long.valueOf(member.getDibsList().size()); - - - if(profileImg.isEmpty()){ - return ApiResponse.onSuccess(MemberConverter.toProfile(member, null, account, address,following,dibs)); - } - else { - return ApiResponse.onSuccess(MemberConverter.toProfile(member, profileImg.get().getUrl(),account, address,following,dibs)); - } - - - } /** * 주문 상세 내역 * 입금처, 입금 은행, 상품 사진, 상품 이름, 상품 옵션, 주문 상태(결제 전, 결제 완료), 주문자명, 주문자 연락처, 주문 번호, 상품 주문 개수, 상품가격 diff --git a/src/main/java/com/umc/TheGoods/web/dto/member/MemberResponseDTO.java b/src/main/java/com/umc/TheGoods/web/dto/member/MemberResponseDTO.java index 9ad1827..b9a8aab 100644 --- a/src/main/java/com/umc/TheGoods/web/dto/member/MemberResponseDTO.java +++ b/src/main/java/com/umc/TheGoods/web/dto/member/MemberResponseDTO.java @@ -221,6 +221,17 @@ public static class AccountResultDTO { String name; } + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class AddressAndAccountDTO{ + + List addressDTO; + List accountDTO; + + } + @Builder @Getter @NoArgsConstructor @@ -246,32 +257,6 @@ public static class NewTokenDTO{ } - @Builder - @Getter - @AllArgsConstructor - @NoArgsConstructor - public static class MyPageOrderItemDTO{ - private Long id; - private String imageUrl; - private Long price; - private OrderStatus orderStatus; - private String name; - private LocalDateTime time; - private List option; - } - - @Builder - @Getter - @NoArgsConstructor - @AllArgsConstructor - public static class MyPageOrderItemListDTO { - List itemList; - Integer listSize; - Integer totalPage; - Long totalElements; - Boolean isFirst; - Boolean isLast; - } @Builder @Getter From 1204972748a076f5f84beb2c0e8fabfe341a3c24 Mon Sep 17 00:00:00 2001 From: joon Date: Mon, 3 Jun 2024 23:28:21 +0900 Subject: [PATCH 2/3] =?UTF-8?q?:recycle:=20refactor:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../converter/member/MemberConverter.java | 14 +++- .../domain/common/BaseDateTimeEntity.java | 1 + .../umc/TheGoods/domain/member/Member.java | 10 ++- .../domain/mypage/WithdrawReason.java | 4 - .../repository/member/MemberRepository.java | 9 +-- .../member/WithdrawReasonRepository.java | 2 +- .../MemberCommandServiceImpl.java | 80 +++++++++---------- .../web/controller/MyPageController.java | 3 +- 8 files changed, 60 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java b/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java index 112026d..c54452e 100644 --- a/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java +++ b/src/main/java/com/umc/TheGoods/converter/member/MemberConverter.java @@ -12,10 +12,7 @@ import com.umc.TheGoods.domain.member.Auth; import com.umc.TheGoods.domain.member.Member; import com.umc.TheGoods.domain.member.Term; -import com.umc.TheGoods.domain.mypage.Account; -import com.umc.TheGoods.domain.mypage.Address; -import com.umc.TheGoods.domain.mypage.ContactTime; -import com.umc.TheGoods.domain.mypage.Declaration; +import com.umc.TheGoods.domain.mypage.*; import com.umc.TheGoods.domain.order.OrderItem; import com.umc.TheGoods.service.ItemService.ItemQueryService; import com.umc.TheGoods.web.dto.item.ItemResponseDTO; @@ -433,4 +430,13 @@ public static MemberResponseDTO.ContactResponseDTO toContactDTO(ContactTime cont .build(); } + public static WithdrawReason toWithdrawReason(MemberRequestDTO.WithdrawReasonDTO request){ + return WithdrawReason.builder() + .reason(request.getReason()) + .caution(request.getCaution()) + .build(); + } + + + } diff --git a/src/main/java/com/umc/TheGoods/domain/common/BaseDateTimeEntity.java b/src/main/java/com/umc/TheGoods/domain/common/BaseDateTimeEntity.java index 0d550f2..98707b2 100644 --- a/src/main/java/com/umc/TheGoods/domain/common/BaseDateTimeEntity.java +++ b/src/main/java/com/umc/TheGoods/domain/common/BaseDateTimeEntity.java @@ -22,4 +22,5 @@ public abstract class BaseDateTimeEntity { @LastModifiedDate private LocalDateTime updatedAt; + } diff --git a/src/main/java/com/umc/TheGoods/domain/member/Member.java b/src/main/java/com/umc/TheGoods/domain/member/Member.java index 5fed63c..2e25ba2 100644 --- a/src/main/java/com/umc/TheGoods/domain/member/Member.java +++ b/src/main/java/com/umc/TheGoods/domain/member/Member.java @@ -28,6 +28,8 @@ import org.hibernate.annotations.DynamicInsert; import javax.persistence.*; +import java.time.LocalDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -112,6 +114,8 @@ public class Member extends BaseDateTimeEntity { @ColumnDefault("false") private Boolean infoTerm; + private LocalDateTime deletedAt; + @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) private List memberTermList = new ArrayList<>(); @@ -134,12 +138,11 @@ public class Member extends BaseDateTimeEntity { @OneToOne(mappedBy = "member") private Revenue revenue; - @OneToOne(mappedBy = "member") - private WithdrawReason withdrawReason; @OneToOne(mappedBy = "member") private ProfileImg profileImg; + //notification 양방향 매핑 @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) private List notification = new ArrayList<>(); @@ -217,7 +220,8 @@ public void setProfileImg(ProfileImg profileImg) { this.profileImg = profileImg; } - public void setMemberStatus(MemberStatus memberStatus){ + public void setMemberStatus(MemberStatus memberStatus, LocalDateTime time){ this.memberStatus = memberStatus; + this.deletedAt = time; } } diff --git a/src/main/java/com/umc/TheGoods/domain/mypage/WithdrawReason.java b/src/main/java/com/umc/TheGoods/domain/mypage/WithdrawReason.java index e093c0d..c8f0825 100644 --- a/src/main/java/com/umc/TheGoods/domain/mypage/WithdrawReason.java +++ b/src/main/java/com/umc/TheGoods/domain/mypage/WithdrawReason.java @@ -32,8 +32,4 @@ public class WithdrawReason extends BaseDateTimeEntity { @Column(nullable = false) private Integer reason; // 탈퇴 사유 - - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id") - private Member member; } diff --git a/src/main/java/com/umc/TheGoods/repository/member/MemberRepository.java b/src/main/java/com/umc/TheGoods/repository/member/MemberRepository.java index 35660c2..5abe059 100644 --- a/src/main/java/com/umc/TheGoods/repository/member/MemberRepository.java +++ b/src/main/java/com/umc/TheGoods/repository/member/MemberRepository.java @@ -9,7 +9,9 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.Date; +import java.util.List; import java.util.Optional; public interface MemberRepository extends JpaRepository { @@ -79,10 +81,5 @@ public interface MemberRepository extends JpaRepository { @Query("UPDATE Member m SET m.infoTerm = :infoTerm WHERE m.id = :memberId") void changeInfoTerm(Long memberId, Boolean infoTerm); - @Transactional - @Modifying(clearAutomatically = true) - @Query("UPDATE Member m SET m.name = :name, m.email = :email, m.phone = :phone, m.birthday = :birthday, m.gender = :gender, m.password = :password, m.nickname = :nickname WHERE m.id = :memberId") - void reregister(Long memberId, String nickname, String name, String password, String email, Date birthday - ,Gender gender, String phone); - + List findAllByDeletedAtBefore(LocalDateTime dateTime); } diff --git a/src/main/java/com/umc/TheGoods/repository/member/WithdrawReasonRepository.java b/src/main/java/com/umc/TheGoods/repository/member/WithdrawReasonRepository.java index 42a4df0..f2f2112 100644 --- a/src/main/java/com/umc/TheGoods/repository/member/WithdrawReasonRepository.java +++ b/src/main/java/com/umc/TheGoods/repository/member/WithdrawReasonRepository.java @@ -7,5 +7,5 @@ import java.util.Optional; public interface WithdrawReasonRepository extends JpaRepository { - Optional findByMember_Id(Long id); + } diff --git a/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java b/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java index 64acb40..5dc3b0b 100644 --- a/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java +++ b/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java @@ -1,6 +1,5 @@ package com.umc.TheGoods.service.MemberService; -import antlr.Token; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.umc.TheGoods.apiPayload.ApiResponse; @@ -10,21 +9,16 @@ import com.umc.TheGoods.config.springSecurity.provider.TokenProvider; import com.umc.TheGoods.converter.member.MemberConverter; import com.umc.TheGoods.domain.enums.ItemStatus; -import com.umc.TheGoods.domain.enums.MemberRole; import com.umc.TheGoods.domain.enums.MemberStatus; import com.umc.TheGoods.domain.images.ProfileImg; -import com.umc.TheGoods.domain.item.Category; import com.umc.TheGoods.domain.item.Item; -import com.umc.TheGoods.domain.item.Tag; import com.umc.TheGoods.domain.mapping.member.MemberTerm; import com.umc.TheGoods.domain.member.Auth; import com.umc.TheGoods.domain.member.Member; import com.umc.TheGoods.domain.member.Term; import com.umc.TheGoods.domain.mypage.*; -import com.umc.TheGoods.domain.types.SocialType; import com.umc.TheGoods.redis.domain.RefreshToken; import com.umc.TheGoods.redis.service.RedisService; -import com.umc.TheGoods.repository.TagRepository; import com.umc.TheGoods.repository.item.ItemRepository; import com.umc.TheGoods.repository.member.*; import com.umc.TheGoods.service.UtilService; @@ -36,6 +30,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; @@ -49,7 +44,7 @@ import javax.servlet.http.HttpServletResponse; import java.time.LocalDateTime; import java.util.*; -import java.util.stream.Collectors; + @@ -76,9 +71,9 @@ public class MemberCommandServiceImpl implements MemberCommandService { private final ContactTimeRepository contactTimeRepository; private final ItemRepository itemRepository; + @Value("${jwt.token.secret}") private String key; // 토큰 만들어내는 key값 - private int expiredMs = 1000 * 60 * 60 * 24 * 5;// 토큰 만료 시간 1일 @Value("${social.kakao.client-id}") private String kakao_client_id; @@ -106,41 +101,24 @@ public class MemberCommandServiceImpl implements MemberCommandService { @Override public Member join(MemberRequestDTO.JoinDTO request) { - Member existingMember = null; + Optional existingNickname = memberRepository.findByNickname(request.getNickname()); if (existingNickname.isPresent()) { - if (!existingNickname.get().getMemberStatus().equals(MemberStatus.INACTIVE)) { - throw new MemberHandler(ErrorStatus.MEMBER_NICKNAME_DUPLICATED); - } else { - //탈퇴한 회원인 경우 - existingMember = existingNickname.get(); - } + throw new MemberHandler(ErrorStatus.MEMBER_NICKNAME_DUPLICATED); + } Optional existingEmail = memberRepository.findByEmail(request.getEmail()); if (existingEmail.isPresent()) { - if (!existingEmail.get().getMemberStatus().equals(MemberStatus.INACTIVE)) { - throw new MemberHandler(ErrorStatus.MEMBER_EMAIL_DUPLICATED); - } else { - //탈퇴한 회원인 경우 - existingMember = existingEmail.get(); - } - } + throw new MemberHandler(ErrorStatus.MEMBER_EMAIL_DUPLICATED); - Member member; - if (existingMember != null) { - //탈퇴한 회원이 다시 회원가입하는 경우 - existingMember.setMemberStatus(MemberStatus.ACTIVE); - memberRepository.reregister(existingMember.getId(),request.getNickname(), - request.getName(), encoder.encode(request.getPassword()), request.getEmail(), - request.getBirthday(), request.getGender(), request.getPhone()); - return existingMember; - } else { - member = MemberConverter.toMember(request, encoder); } + Member member = MemberConverter.toMember(request, encoder); + + // 약관동의 저장 로직 HashMap termMap = new HashMap<>(); for (int i = 0; i < request.getMemberTerm().size(); i++) { @@ -758,29 +736,32 @@ public boolean existMemberById(Long memberId) { return memberRepository.existsById(memberId); } + + /* + 회원 탈퇴시 1주일 동안 기록 남겨두고 1주일 후 완전히 삭제 되도록 구현 + 탈퇴 기록 남기고 회원 db에서 사라져도 member와 연관된 테이블 member_id null로 변경 + 회원 삭제 했을 때 같이 삭제 되어도 되는 것 : 포스트, 댓글, 리뷰, 주소, 계좌, 프로필, 장바구니 + 회원 삭제 했을 때 같이 삭제 되면 안되는 것 : 탈퇴 사유, 아이템, 주문 내역, 결제 기록 + */ @Override @Transactional public void deleteMember(MemberRequestDTO.WithdrawReasonDTO request, Long memberId) { Member member = memberRepository.findById(memberId).orElseThrow(()-> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); - WithdrawReason withdrawReason = WithdrawReason.builder() - .reason(request.getReason()) - .caution(request.getCaution()) - .member(member) - .build(); + WithdrawReason withdrawReason = MemberConverter.toWithdrawReason(request); - //이미 존재하는 탈퇴사유 삭제 - Optional beforereason = withdrawReasonRepository.findByMember_Id(memberId); - if(beforereason.isPresent()){ - withdrawReasonRepository.delete(beforereason.get()); - } withdrawReasonRepository.save(withdrawReason); - member.setMemberStatus(MemberStatus.INACTIVE); + + member.setMemberStatus(MemberStatus.INACTIVE, LocalDateTime.now()); memberRepository.save(member); + + List itemList = itemRepository.findAllByMember(member); itemList.stream().forEach(item -> { item.updateStatus(ItemStatus.INACTIVE); }); + + return; } @@ -875,5 +856,18 @@ public ContactTime getContact(Member member) { return contactTime; } + //@Scheduled(cron = "0 0 0 * * ?") // 매일 자정에 실행 + @Transactional + public void deleteOldMembers() { + LocalDateTime oneWeekAgo = LocalDateTime.now().minusWeeks(1); + List membersToDelete = memberRepository.findAllByDeletedAtBefore(oneWeekAgo); + + for (Member member : membersToDelete) { + Long memberId = member.getId(); + + memberRepository.deleteById(memberId); + } + } + } diff --git a/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java b/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java index 64d6ecd..fe694bd 100644 --- a/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java +++ b/src/main/java/com/umc/TheGoods/web/controller/MyPageController.java @@ -197,12 +197,11 @@ public ApiResponse getAddressAndAccount( return ApiResponse.onSuccess(MemberConverter.toGetAddressAndAccountDTO(addressList,accountList)); } - @DeleteMapping(value = "/delete") + @PostMapping(value = "/delete") @Operation(summary = "회원 탈퇴 api", description = "request: 회원 탈퇴 사유 번호로 주시면 됩니다") public ApiResponse deleteMember(@RequestBody MemberRequestDTO.WithdrawReasonDTO request, Authentication authentication){ - memberCommandService.deleteMember(request, Long.valueOf(authentication.getName().toString())); return ApiResponse.of(SuccessStatus.MEMBER_DELETE_SUCCESS, null); } From 176b741a7b0321bd74eff91641baafda40b90b48 Mon Sep 17 00:00:00 2001 From: joon Date: Fri, 7 Jun 2024 17:02:15 +0900 Subject: [PATCH 3/3] =?UTF-8?q?:recycle:=20refactor:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EA=B4=80=EB=A0=A8=20CASCADE=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/TheGoods/domain/member/Member.java | 6 +++--- .../MemberCommandServiceImpl.java | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/umc/TheGoods/domain/member/Member.java b/src/main/java/com/umc/TheGoods/domain/member/Member.java index 2e25ba2..ef75247 100644 --- a/src/main/java/com/umc/TheGoods/domain/member/Member.java +++ b/src/main/java/com/umc/TheGoods/domain/member/Member.java @@ -148,7 +148,7 @@ public class Member extends BaseDateTimeEntity { private List notification = new ArrayList<>(); // item 양방향 매핑 - @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}) private List itemList = new ArrayList<>(); @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) @@ -167,7 +167,7 @@ public class Member extends BaseDateTimeEntity { private List cartList = new ArrayList<>(); // orders 양방향 매핑 - @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}) private List ordersList = new ArrayList<>(); // tag_search 양방향 매핑 @@ -213,7 +213,7 @@ public class Member extends BaseDateTimeEntity { private List incommingInquiryList = new ArrayList<>(); // Payment 양방향 매핑 - @OneToMany(mappedBy = "member", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "member", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}) private List paymentList = new ArrayList<>(); public void setProfileImg(ProfileImg profileImg) { diff --git a/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java b/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java index 5dc3b0b..9905432 100644 --- a/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java +++ b/src/main/java/com/umc/TheGoods/service/MemberService/MemberCommandServiceImpl.java @@ -748,6 +748,13 @@ public boolean existMemberById(Long memberId) { public void deleteMember(MemberRequestDTO.WithdrawReasonDTO request, Long memberId) { Member member = memberRepository.findById(memberId).orElseThrow(()-> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); + //Order 있으면 계정 삭제 x + + //배송중일때 탈퇴 x + + //판매자가 수익금이 있는 경우 + + WithdrawReason withdrawReason = MemberConverter.toWithdrawReason(request); withdrawReasonRepository.save(withdrawReason); @@ -755,16 +762,22 @@ public void deleteMember(MemberRequestDTO.WithdrawReasonDTO request, Long member member.setMemberStatus(MemberStatus.INACTIVE, LocalDateTime.now()); memberRepository.save(member); - + //판매자가 등록한 Item이 있는경우 INACTIVE로 변경 List itemList = itemRepository.findAllByMember(member); itemList.stream().forEach(item -> { item.updateStatus(ItemStatus.INACTIVE); }); - + //INACTIVE로 바뀐 Item 주문이 있는 경우 주문 취소하고 환불 처리 + + + + + return; } + public boolean checkDeregister(Member member){ if(member.getMemberStatus() == MemberStatus.INACTIVE){ @@ -856,7 +869,7 @@ public ContactTime getContact(Member member) { return contactTime; } - //@Scheduled(cron = "0 0 0 * * ?") // 매일 자정에 실행 + //@Scheduled(cron = "0 0 0 1 * ?") // 매월 1일에 실행 @Transactional public void deleteOldMembers() { LocalDateTime oneWeekAgo = LocalDateTime.now().minusWeeks(1); @@ -867,6 +880,7 @@ public void deleteOldMembers() { memberRepository.deleteById(memberId); } + } }