diff --git a/server/src/main/java/haengdong/common/infrastructure/AdminInterceptor.java b/server/src/main/java/haengdong/common/auth/infrastructure/AdminInterceptor.java similarity index 95% rename from server/src/main/java/haengdong/common/infrastructure/AdminInterceptor.java rename to server/src/main/java/haengdong/common/auth/infrastructure/AdminInterceptor.java index 1de325a3..a28faea6 100644 --- a/server/src/main/java/haengdong/common/infrastructure/AdminInterceptor.java +++ b/server/src/main/java/haengdong/common/auth/infrastructure/AdminInterceptor.java @@ -1,4 +1,4 @@ -package haengdong.common.infrastructure; +package haengdong.common.auth.infrastructure; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -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 { diff --git a/server/src/main/java/haengdong/common/infrastructure/AuthenticationPrincipalArgumentResolver.java b/server/src/main/java/haengdong/common/auth/infrastructure/AuthenticationPrincipalArgumentResolver.java similarity index 88% rename from server/src/main/java/haengdong/common/infrastructure/AuthenticationPrincipalArgumentResolver.java rename to server/src/main/java/haengdong/common/auth/infrastructure/AuthenticationPrincipalArgumentResolver.java index 03fa3555..f2427a5b 100644 --- a/server/src/main/java/haengdong/common/infrastructure/AuthenticationPrincipalArgumentResolver.java +++ b/server/src/main/java/haengdong/common/auth/infrastructure/AuthenticationPrincipalArgumentResolver.java @@ -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; diff --git a/server/src/main/java/haengdong/common/config/WebMvcConfig.java b/server/src/main/java/haengdong/common/config/WebMvcConfig.java index c421ba64..7b0e422b 100644 --- a/server/src/main/java/haengdong/common/config/WebMvcConfig.java +++ b/server/src/main/java/haengdong/common/config/WebMvcConfig.java @@ -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; diff --git a/server/src/main/java/haengdong/user/application/KakaoClient.java b/server/src/main/java/haengdong/user/application/KakaoClient.java index 6aa0757c..b6c5c7ab 100644 --- a/server/src/main/java/haengdong/user/application/KakaoClient.java +++ b/server/src/main/java/haengdong/user/application/KakaoClient.java @@ -1,6 +1,11 @@ package haengdong.user.application; +import haengdong.common.exception.HaengdongErrorCode; +import haengdong.common.exception.HaengdongException; +import haengdong.user.application.response.KakaoTokenResponse; +import haengdong.user.config.KakaoProperties; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -8,11 +13,8 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestClient; -import haengdong.user.application.response.KakaoTokenResponse; -import haengdong.user.config.KakaoProperties; -import haengdong.common.exception.HaengdongErrorCode; -import haengdong.common.exception.HaengdongException; +@Slf4j @RequiredArgsConstructor @EnableConfigurationProperties(KakaoProperties.class) @Component @@ -36,6 +38,7 @@ public KakaoTokenResponse join(String code, String redirectUri) { .retrieve() .body(KakaoTokenResponse.class); } catch (Exception e) { + log.info("로그인 실패 : {}", code); throw new HaengdongException(HaengdongErrorCode.KAKAO_LOGIN_FAIL, e); } } diff --git a/server/src/main/java/haengdong/user/application/KakaoUserService.java b/server/src/main/java/haengdong/user/application/KakaoUserService.java index 21c1919d..59f744c3 100644 --- a/server/src/main/java/haengdong/user/application/KakaoUserService.java +++ b/server/src/main/java/haengdong/user/application/KakaoUserService.java @@ -3,9 +3,11 @@ import com.auth0.jwt.JWT; import com.auth0.jwt.interfaces.DecodedJWT; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import haengdong.user.application.response.KakaoTokenResponse; +@Slf4j @RequiredArgsConstructor @Service public class KakaoUserService { @@ -23,6 +25,8 @@ public Long joinByKakao(String code, String redirectUri) { String memberNumber = decodedJWT.getSubject(); String nickname = decodedJWT.getClaim(NICKNAME_KEY).asString(); + log.info("로그인 성공 : {}, {}", code, nickname); + return userService.join(memberNumber, nickname); } diff --git a/server/src/main/java/haengdong/user/application/UserService.java b/server/src/main/java/haengdong/user/application/UserService.java index 9c466501..411ed8f0 100644 --- a/server/src/main/java/haengdong/user/application/UserService.java +++ b/server/src/main/java/haengdong/user/application/UserService.java @@ -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)); diff --git a/server/src/main/java/haengdong/user/presentation/UserController.java b/server/src/main/java/haengdong/user/presentation/UserController.java index 845a5f58..84608c81 100644 --- a/server/src/main/java/haengdong/user/presentation/UserController.java +++ b/server/src/main/java/haengdong/user/presentation/UserController.java @@ -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; @@ -63,6 +64,12 @@ public ResponseEntity kakaoLogin( .build(); } + @DeleteMapping("/api/admin/users") + public ResponseEntity 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()) @@ -73,5 +80,4 @@ private ResponseCookie createResponseCookie(String token) { .maxAge(cookieProperties.maxAge()) .build(); } - }