Skip to content

Commit

Permalink
[FIX] User 회원 탈퇴 로직 변경 (#160)
Browse files Browse the repository at this point in the history
* fix: SignUp, SignIn Security Context Holder 올리는 과정 제거

* fix: User 탈퇴 DELETE -> PATCH & 소프트 delete로 변경

* fix: 중복 URL 제거
  • Loading branch information
sejineer authored Nov 22, 2023
1 parent 9571772 commit c50ffcc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ public AuthRes signUp(final SignUpReq signUpReq) {
)
);

SecurityContextHolder.getContext().setAuthentication(authentication);

TokenMapping tokenMapping = customTokenProviderService.createToken(authentication);
Token token = Token.builder()
.refreshToken(tokenMapping.getRefreshToken())
Expand Down Expand Up @@ -102,13 +100,12 @@ public AuthRes signIn(final SignInReq signInReq) {
)
);

SecurityContextHolder.getContext().setAuthentication(authentication);

TokenMapping tokenMapping = customTokenProviderService.createToken(authentication);
Token token = Token.builder()
.refreshToken(tokenMapping.getRefreshToken())
.userEmail(tokenMapping.getUserEmail())
.build();

tokenRepository.save(token);

return AuthRes.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public interface UserService {

UserDetailRes getCurrentUser(UserPrincipal userPrincipal);
DeleteUserRes deleteCurrentUser(UserPrincipal userPrincipal);
DeleteUserRes inactiveCurrentUser(UserPrincipal userPrincipal);
SignUpUserRes signUpCurrentUser(UserPrincipal userPrincipal, SignUpUserReq signUpUserReq);
List<SendGiftDetailRes> findSendGiftsByUser(UserPrincipal userPrincipal);
List<ReceiveGiftDetailRes> findReceiveGiftsByUser(UserPrincipal userPrincipal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.shallwe.domain.auth.domain.Token;
import com.shallwe.domain.auth.domain.repository.TokenRepository;
import com.shallwe.domain.common.Status;
import com.shallwe.domain.reservation.domain.Reservation;
import com.shallwe.domain.reservation.domain.ReservationStatus;
import com.shallwe.domain.reservation.domain.repository.ReservationRepository;
Expand Down Expand Up @@ -36,12 +37,12 @@ public UserDetailRes getCurrentUser(final UserPrincipal userPrincipal) {

@Override
@Transactional
public DeleteUserRes deleteCurrentUser(final UserPrincipal userPrincipal) {
public DeleteUserRes inactiveCurrentUser(final UserPrincipal userPrincipal) {
User user = userRepository.findById(userPrincipal.getId()).orElseThrow(InvalidUserException::new);

Token token = tokenRepository.findByUserEmail(user.getEmail())
.orElseThrow(InvalidTokenException::new);
userRepository.delete(user);
user.updateStatus(Status.DELETE);
tokenRepository.delete(token);

return DeleteUserRes.toDto();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public ResponseCustom<UserDetailRes> getCurrentUser(
return ResponseCustom.OK(userServiceImpl.getCurrentUser(userPrincipal));
}

@Operation(summary = "유저 정보 삭제", description = "현제 접속된 유저정보를 삭제합니다.")
@Operation(summary = "유저 탈퇴", description = "현재 유저를 탈퇴 처리 합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "유저 삭제 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = DeleteUserRes.class))}),
@ApiResponse(responseCode = "400", description = "유저 삭제 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(responseCode = "200", description = "유저 탈퇴 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = DeleteUserRes.class))}),
@ApiResponse(responseCode = "400", description = "유저 탈퇴 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@DeleteMapping
public ResponseCustom<DeleteUserRes> deleteCurrentUser(
@PatchMapping("/inactive")
public ResponseCustom<DeleteUserRes> inactiveCurrentUser(
@Parameter(description = "AccessToken 을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal
) {
return ResponseCustom.OK(userServiceImpl.deleteCurrentUser(userPrincipal));
return ResponseCustom.OK(userServiceImpl.inactiveCurrentUser(userPrincipal));
}

@Operation(summary = "유저 정보 입력", description = "마켓팅 정보 동의와 나이, 성별 정보를 입력받습니다.")
Expand Down

0 comments on commit c50ffcc

Please sign in to comment.