Skip to content

Commit

Permalink
Merge pull request #263 from Wingle-SMWU/feat/회원탈퇴-#261
Browse files Browse the repository at this point in the history
Feat/회원탈퇴 #261
  • Loading branch information
Lightieey authored Aug 21, 2023
2 parents ab0169d + cfc73f9 commit d444708
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 14 deletions.
7 changes: 7 additions & 0 deletions wingle/src/main/java/kr/co/wingle/member/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.validation.Valid;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -78,6 +79,12 @@ public ApiResponse<Object> logout(@RequestBody @Valid LogoutRequestDto logoutReq
return ApiResponse.success(SuccessCode.LOGOUT_SUCCESS, null);
}

@DeleteMapping("/withdrawal")
public ApiResponse<Object> withdrawal() {
authService.withdrawal();
return ApiResponse.success(SuccessCode.LOGOUT_SUCCESS, null);
}

@PostMapping("/email")
public ApiResponse<EmailResponseDto> sendCodeMail(@RequestBody @Valid EmailRequestDto emailRequestDto) {
EmailResponseDto response = authService.sendCodeMail(emailRequestDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ public void logout(LogoutRequestDto logoutRequestDto) {
redisUtil.setDataExpire(RedisUtil.PREFIX_LOGOUT + accessToken, "logout", TokenInfo.ACCESS_TOKEN_EXPIRE_TIME);
}

@Transactional
public void withdrawal() {
Member member = findAcceptedLoggedInMember();
member.softDelete();
}

public EmailResponseDto sendCodeMail(EmailRequestDto emailRequestDto) {
String to = emailRequestDto.getEmail();
if (!isSignupAvailableEmail(to)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public class RoomMemberDto {
private String email;
private int permission;
private String schoolName;
private boolean isDeleted;

public static RoomMemberDto of(Long roomId, OriginType originType, Long memberId, String name, String email,
int permission, String schoolName) {
int permission, String schoolName, boolean isDeleted) {
return RoomMemberDto.builder()
.roomId(roomId)
.originType(originType)
Expand All @@ -27,6 +28,7 @@ public static RoomMemberDto of(Long roomId, OriginType originType, Long memberId
.email(email)
.permission(permission)
.schoolName(schoolName)
.isDeleted(isDeleted)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public MessageResponseDto toResponseDto(Message message) {
boolean isMine = writingUtil.isMine(message);
Member member = authService.findAcceptedLoggedInMember();

Profile profile = profileService.getProfileByMemberId(message.getMember().getId());
Profile profile = message.getMember().isDeleted() ? Profile.createDummyProfile(message.getMember()) :
profileService.getProfileByMemberId(message.getMember().getId());

// 메세지 송신자가 나 자신일 경우 닉네임 대신 null 반환
return MessageResponseDto.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import kr.co.wingle.message.mapper.MessageMapper;
import kr.co.wingle.message.repository.MessageRepository;
import kr.co.wingle.profile.ProfileService;
import kr.co.wingle.profile.dto.ProfileGetResponseDto;
import kr.co.wingle.writing.WritingService;
import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -56,8 +55,6 @@ public MessageResponseWithRecipentDto getListByRoom(Long roomId, int page, int s
Pageable pageable = PageRequest.of(page, size);
List<Message> pages = messageRepository.findByRoomIdAndIsDeletedOrderByCreatedTimeDesc(roomId, false, pageable);

ProfileGetResponseDto profile = profileService.getProfile(recipient.getMemberId());

if (pages.isEmpty()) {
return MessageResponseWithRecipentDto.of();
}
Expand All @@ -68,8 +65,8 @@ public MessageResponseWithRecipentDto getListByRoom(Long roomId, int page, int s

return MessageResponseWithRecipentDto.of(
AES256Util.encrypt(recipient.getMemberId().toString()),
profile.getImage(),
recipient.getSchoolName(),
recipient.isDeleted() ? "" : profileService.getProfile(recipient.getMemberId()).getImage(),
recipient.isDeleted() ? "(알수없음)" : recipient.getSchoolName(),
messages
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public List<RoomResponseDto> getMyList(int page, int size) {
Member otherMember = roomMemberRepository.findAllByRoomIdAndIsDeleted(room.getId(), false)
.stream().filter(x -> x.getMember().getId() != member.getId()).collect(Collectors.toList())
.get(0).getMember();
Profile otherProfile = profileService.getProfileByMemberId(otherMember.getId());
Profile otherProfile = otherMember.isDeleted() ? Profile.createDummyProfile(otherMember) :
profileService.getProfileByMemberId(otherMember.getId());
MessageResponseDto recent = null;
// messageService.getListByRoom 이용하고 싶은데 순환구조 생김
// List<MessageResponseDto> messages = messageService.getListByRoom(room.getId(), 0, 1);
Expand All @@ -170,7 +171,8 @@ public List<RoomResponseDto> getMyList(int page, int size) {
if (messages.size() > 0)
recent = messages.get(0);
result.add(
RoomResponseDto.roomPreview(room.getId(), otherProfile, recent, otherMember.getSchool().getName()));
RoomResponseDto.roomPreview(room.getId(), otherProfile, recent,
otherMember.isDeleted() ? "(알수없음)" : otherMember.getSchool().getName()));
}

// 최신메시지순
Expand All @@ -191,7 +193,8 @@ public RoomMemberDto getRecipient(Long roomId, Long userId) {
dto = RoomMemberDto.of(room.getId(), room.getOriginType(), member.getId(), member.getName(),
member.getEmail(),
member.getPermission(),
member.getSchool().getName());
member.getSchool().getName(),
member.isDeleted());
}
}

Expand Down
13 changes: 9 additions & 4 deletions wingle/src/main/java/kr/co/wingle/profile/ProfileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import kr.co.wingle.common.constants.ErrorCode;
import kr.co.wingle.common.exception.DuplicateException;
import kr.co.wingle.common.exception.NotFoundException;
import kr.co.wingle.common.util.AES256Util;
import kr.co.wingle.common.util.S3Util;
import kr.co.wingle.member.entity.Member;
import kr.co.wingle.member.service.AuthService;
Expand Down Expand Up @@ -47,7 +46,6 @@ public class ProfileService {
private final InterestRepository interestRepository;
private final SnsRepository snsRepository;
private final S3Util s3Util;
private final AES256Util aes;
private final ProfileUtil profileUtil;

@Transactional
Expand Down Expand Up @@ -147,9 +145,15 @@ private Profile getProfileEntity(Member member) {
}

public Profile getProfileByMemberId(Long memberId) {
return profileRepository.findByMemberId(memberId)
Profile profile = profileRepository.findByMemberId(memberId)
.orElseThrow(() -> new NotFoundException(
ErrorCode.NO_PROFILE));

if (profile.getMember().isDeleted()) {
return Profile.createDummyProfile(profile.getMember());
} else {
return profile;
}
}

private String uploadProfileImage(MultipartFile profileImage) {
Expand Down Expand Up @@ -197,9 +201,10 @@ public ProfileGetResponseDto getProfile(Member member) {

public ProfileGetResponseDto getProfile(Long id) {
Member member = memberService.findMemberByMemberId(id);
if (member.isDeleted())
throw new NotFoundException(ErrorCode.ALREADY_WITHDRAWN);

ProfileGetResponseDto response = getProfile(member);

return response;
}

Expand Down
7 changes: 7 additions & 0 deletions wingle/src/main/java/kr/co/wingle/profile/entity/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ public static Profile copyProfile(Profile from, Profile to) {
return to;
}

public static Profile createDummyProfile(Member member) {
Profile profile = new Profile();
profile.member = member;
profile.nickname = "(알수없음)";
profile.nation = "(알수없음)";
return profile;
}
}

0 comments on commit d444708

Please sign in to comment.