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

Feat/회원탈퇴 #261 #263

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -5,7 +5,6 @@

import org.springframework.stereotype.Component;

import kr.co.wingle.common.util.AES256Util;
import kr.co.wingle.community.util.CommunityUtil;
import kr.co.wingle.community.util.ProcessedPersonalInformation;
import kr.co.wingle.profile.ProfileService;
Expand All @@ -25,25 +24,24 @@ public ArticleResponseDto toResponseDto(Article article, List<String> images) {

ArticleResponseDto.ArticleResponseDtoBuilder articleResponseDto = ArticleResponseDto.builder();

if (article != null) {
articleResponseDto.articleId(article.getId());
articleResponseDto.createdTime(article.getCreatedTime());
articleResponseDto.updatedTime(article.getUpdatedTime());
articleResponseDto.content(article.getContent());
articleResponseDto.likeCount(article.getLikeCount());
}
articleResponseDto.articleId(article.getId());
articleResponseDto.createdTime(article.getCreatedTime());
articleResponseDto.updatedTime(article.getUpdatedTime());
articleResponseDto.content(article.getContent());
articleResponseDto.likeCount(article.getLikeCount());

articleResponseDto.userNickname(processedPersonalInformation.getNickname());
List<String> list = images;
if (list != null) {
articleResponseDto.images(new ArrayList<String>(list));
}
articleResponseDto.isMine(processedPersonalInformation.isMine());
articleResponseDto.userId(
AES256Util.encrypt(article.getMember().getId().toString(), article.getId().toString()));
articleResponseDto.userId(processedPersonalInformation.getProcessedMemberId());
articleResponseDto.userImage(profileService.getProfileByMemberId(article.getMember().getId()).getImageUrl());
articleResponseDto.userNation(profileService.getProfileByMemberId(article.getMember().getId()).getNation());
articleResponseDto.userSchoolName(processedPersonalInformation.getSchoolName());

articleResponseDto.forumId(article.getForum().getId());
articleResponseDto.isMine(processedPersonalInformation.isMine());

return articleResponseDto.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.springframework.stereotype.Component;

import kr.co.wingle.common.util.AES256Util;
import kr.co.wingle.community.util.CommunityUtil;
import kr.co.wingle.community.util.ProcessedPersonalInformation;
import kr.co.wingle.profile.ProfileService;
Expand All @@ -22,8 +21,7 @@ public CommentResponseDto toResponseDto(Comment comment) {
CommentResponseDto.CommentResponseDtoBuilder commentResponseDto = CommentResponseDto.builder();

commentResponseDto.id(comment.getId());
commentResponseDto.userId(
AES256Util.encrypt(comment.getMember().getId().toString(), comment.getArticle().getId().toString()));
commentResponseDto.userId(processedPersonalInformation.getProcessedMemberId());
commentResponseDto.userNickname(processedPersonalInformation.getNickname());
commentResponseDto.userImage(profileService.getProfileByMemberId(comment.getMember().getId()).getImageUrl());
commentResponseDto.userNation(profileService.getProfileByMemberId(comment.getMember().getId()).getNation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import kr.co.wingle.common.constants.ErrorCode;
import kr.co.wingle.common.exception.NotFoundException;
import kr.co.wingle.common.util.AES256Util;
import kr.co.wingle.community.article.Article;
import kr.co.wingle.community.comment.Comment;
import kr.co.wingle.community.forum.Forum;
import kr.co.wingle.community.forum.ForumCode;
import kr.co.wingle.community.forum.ForumService;
import kr.co.wingle.member.entity.Member;
import kr.co.wingle.member.service.AuthService;
Expand All @@ -32,20 +34,26 @@ public ProcessedPersonalInformation processPersonalInformation(Writing writing)
Profile profile = profileService.getProfileByMemberId(writing.getMember().getId());

Forum forum;
Article article;
if (writing instanceof Article) {
forum = ((Article)writing).getForum();
article = (Article)writing;
} else if (writing instanceof Comment) {
forum = ((Comment)writing).getArticle().getForum();
article = ((Comment)writing).getArticle();
} else {
throw new NotFoundException(ErrorCode.BAD_PARAMETER_TYPE);
}

// 게시판별 작성자명
String nickname = forumService.getNicknameByForum(forum, profile);
// 게시판별 멤버id
Long processedMemberId = forumService.processMemberIdByForum(forum,
writing.getMember().getId());
String processedMemberId = ForumCode.from(forum.getName()).equals(ForumCode.EXCHANGE) ?
AES256Util.encrypt(writing.getMember().getId().toString()) :
AES256Util.encrypt(writing.getMember().getId().toString(), article.getId().toString());
// 게시판별 작성자 학교이름
String schoolName = forumService.getSchoolNameByForum(forum, writing.getMember().getSchool());
String schoolName = writing.getMember().isDeleted() ? "(알수없음)" :
forumService.getSchoolNameByForum(forum, writing.getMember().getSchool());
boolean isMine = writingUtil.isMine(writing);
return ProcessedPersonalInformation.of(nickname, processedMemberId, schoolName, isMine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class ProcessedPersonalInformation {
private String nickname;
private Long processedMemberId;
private String processedMemberId;
private String schoolName;
private boolean isMine;

public static ProcessedPersonalInformation of(String nickname, Long processedMemberId, String schoolName,
public static ProcessedPersonalInformation of(String nickname, String processedMemberId, String schoolName,
boolean isMine) {
return new ProcessedPersonalInformation(nickname, processedMemberId, schoolName, isMine);
}
Expand Down
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() ? null : profileService.getProfile(recipient.getMemberId()).getImage(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가급적 반영해 주세요!
클린코드에서 값이 없을때 null을 보내는 것보다는 "", 빈 배열, 빈 리스트 등의 빈 값을 보내는 것을 더 지향합니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeeJE20 반영했습니다!
null 대신 "", 빈 배열, 빈 리스트 등을 사용하는 이유는 NullPointerException이 발생할 가능성이 있기 때문인가요?!

recipient.isDeleted() ? "(알수없음)" : recipient.getSchoolName(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영해도 좋고 안 해도 좋습니다.
"(알수없음)"을 여러 군데에서 쓰고 있네요. 상수화 해서 사용해도 좋을 것 같습니다.

Copy link
Member Author

@Lightieey Lightieey Aug 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeeJE20 상수화하고 싶었는데 어느 위치에 만들어 놓아야 할지 애매해서 일단 literal string으로 썼습니다,,🥲

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;
}
}