Skip to content

Commit

Permalink
✨ Feat: 회원탈퇴 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed Aug 23, 2024
1 parent 8aea392 commit 1faa528
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import treehouse.server.api.member.presentation.dto.MemberRequestDTO;
import treehouse.server.api.member.presentation.dto.MemberResponseDTO;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.User.UserStatus;
import treehouse.server.global.entity.branch.Branch;
import treehouse.server.global.entity.member.Member;
import treehouse.server.global.entity.treeHouse.TreeHouse;
Expand Down Expand Up @@ -40,9 +41,13 @@ public static MemberResponseDTO.registerMember toRegister(Member member) {
}

public static MemberResponseDTO.getWriterProfile toGetWriterProfile(Member member, Member writer, List<Branch> branches) {
String writerName = writer.getName();
if (writer.getUser().getStatus() == UserStatus.WITHDRAWAL) {
writerName = "탈퇴한 회원";
}
return MemberResponseDTO.getWriterProfile.builder()
.memberId(writer.getId())
.memberName(writer.getName())
.memberName(writerName)
.memberProfileImageUrl(writer.getProfileImageUrl())
.memberBranch(BranchUtil.calculateBranchDegree(branches, member.getId(), writer.getId()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class UserMapper {

private final UserService userService;
private static UserService staticUserService;

@PostConstruct
public void init(){
this.staticUserService = this.userService;
Expand Down Expand Up @@ -73,4 +74,10 @@ public static UserResponseDTO.loginMember toLogin(User user, String accessToken,
.treehouseIdList(treehouseIdList)
.build();
}

public static UserResponseDTO.withdraw toWithdraw(User user) {
return UserResponseDTO.withdraw.builder()
.userId(user.getId())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import treehouse.server.api.invitation.implement.InvitationQueryAdapter;
import treehouse.server.api.user.implement.UserCommandAdapter;
import treehouse.server.api.user.implement.UserQueryAdapter;
import treehouse.server.api.user.persistence.UserRepository;
import treehouse.server.api.user.presentation.dto.UserRequestDTO;
import treehouse.server.api.user.presentation.dto.UserResponseDTO;
import treehouse.server.global.entity.User.User;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class UserService {
private final RedisService redisService;

private final InvitationQueryAdapter invitationQueryAdapter;
private final UserRepository userRepository;

@Transactional(readOnly = true)
public UserResponseDTO.checkName checkName(UserRequestDTO.checkName request){
Expand Down Expand Up @@ -88,4 +90,11 @@ public UserResponseDTO.checkUserStatus checkUserStatus(UserRequestDTO.checkUserS

return UserMapper.toCheckUserStatus(isNewUser, isInvited);
}

@Transactional
public UserResponseDTO.withdraw withdraw(User user) {
userCommandAdapter.withdraw(user);

return UserMapper.toWithdraw(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ public TokenDTO reissueToken(User user, RefreshToken refreshToken){
.refreshToken(newRefreshToken.getRefreshToken())
.build();
}

public void withdraw(User user) {
userRepository.delete(user);
}
}
16 changes: 12 additions & 4 deletions src/main/java/treehouse/server/api/user/presentation/UserApi.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package treehouse.server.api.user.presentation;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import treehouse.server.api.user.business.UserService;
import treehouse.server.api.user.presentation.dto.UserRequestDTO;
import treehouse.server.api.user.presentation.dto.UserResponseDTO;
import treehouse.server.global.common.CommonResponse;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.security.handler.annotation.AuthMember;

@RestController
@RequiredArgsConstructor
Expand Down Expand Up @@ -63,4 +63,12 @@ public CommonResponse<UserResponseDTO.checkUserStatus> checkPhoneAuth(
){
return CommonResponse.onSuccess(userService.checkUserStatus(request));
}

@DeleteMapping("/withdraw")
@Operation(summary = "회원탈퇴 🔑✅", description = "회원탈퇴를 진행합니다.")
public CommonResponse<UserResponseDTO.withdraw> withdraw(
@AuthMember @Parameter(hidden = true) User user
){
return CommonResponse.onSuccess(userService.withdraw(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ public static class loginMember {
private String refreshToken;
private List<Long> treehouseIdList;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class withdraw {
private Long userId;
}
}
3 changes: 3 additions & 0 deletions src/main/java/treehouse/server/global/entity/User/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

import org.hibernate.annotations.SQLDelete;
import treehouse.server.global.entity.common.BaseDateTimeEntity;
import treehouse.server.global.entity.member.Member;

Expand All @@ -19,6 +20,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "user")
@SQLDelete(sql = "UPDATE user SET inactivated_at = NOW(), status = 'WITHDRAWAL' WHERE id = ?")
public class User extends BaseDateTimeEntity {

@Id
Expand All @@ -31,6 +33,7 @@ public class User extends BaseDateTimeEntity {

private String profileImageUrl; //프로필 이미지

@Enumerated(EnumType.STRING)
private UserStatus status;

@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Where;
import treehouse.server.global.entity.Invitation.Invitation;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.comment.Comment;
Expand Down

0 comments on commit 1faa528

Please sign in to comment.