Skip to content

Commit

Permalink
feat: 회원 탈퇴 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachneee committed Nov 18, 2024
1 parent 3f399aa commit c8379ff
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package haengdong.common.infrastructure;
package haengdong.common.auth.infrastructure;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -10,7 +10,6 @@
import haengdong.common.auth.application.AuthService;
import haengdong.common.exception.AuthenticationException;
import haengdong.common.exception.HaengdongErrorCode;
import haengdong.common.auth.infrastructure.AuthenticationExtractor;

@Slf4j
public class AdminInterceptor implements HandlerInterceptor {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package haengdong.common.infrastructure;
package haengdong.common.auth.infrastructure;

import static haengdong.common.infrastructure.AdminInterceptor.LOGIN_MEMBER_REQUEST;
import static haengdong.common.auth.infrastructure.AdminInterceptor.LOGIN_MEMBER_REQUEST;

import haengdong.common.auth.Login;
import jakarta.servlet.http.HttpServletRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import haengdong.common.auth.application.AuthService;
import haengdong.common.auth.infrastructure.AuthenticationExtractor;
import haengdong.common.auth.infrastructure.JwtTokenProvider;
import haengdong.common.infrastructure.AdminInterceptor;
import haengdong.common.auth.infrastructure.AdminInterceptor;
import haengdong.common.properties.CorsProperties;
import haengdong.common.properties.JwtProperties;
import haengdong.event.application.EventService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public String findNicknameById(Long id) {
return user.getNickname();
}

@Transactional
public void withdraw(Long id) {
userRepository.deleteById(id);
}

private User getUser(Long id) {
return userRepository.findById(id)
.orElseThrow(() -> new HaengdongException(HaengdongErrorCode.PASSWORD_INVALID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.ResponseCookie;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -63,6 +64,12 @@ public ResponseEntity<Void> kakaoLogin(
.build();
}

@DeleteMapping("/api/admin/users")
public ResponseEntity<Void> deleteUser(@Login Long userId) {
userService.withdraw(userId);
return ResponseEntity.ok().build();
}

private ResponseCookie createResponseCookie(String token) {
return ResponseCookie.from(authService.getTokenName(), token)
.httpOnly(cookieProperties.httpOnly())
Expand All @@ -73,5 +80,4 @@ private ResponseCookie createResponseCookie(String token) {
.maxAge(cookieProperties.maxAge())
.build();
}

}

0 comments on commit c8379ff

Please sign in to comment.