Skip to content

Commit

Permalink
fix: user_sync_dto 내부 sync_oauth dto 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
psychology50 committed Aug 20, 2024
1 parent 06d545e commit 6c9e614
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package kr.co.pennyway.api.apis.auth.dto;

import kr.co.pennyway.domain.domains.oauth.domain.Oauth;
import kr.co.pennyway.domain.domains.oauth.type.Provider;

import java.time.LocalDateTime;

/**
* 전화번호 검증 후, 시나리오 분기 정보를 위한 DTO
*/
Expand All @@ -13,59 +8,31 @@ public record UserSyncDto(
boolean isSignUpAllowed,
boolean isExistAccount,
Long userId,
String username,
/* 계정과 연동하기 위한 oauth 정보. 없다면 null */
OauthSync oauthSync
String username
) {
/**
* @param isSignUpAllowed boolean : 회원가입 시나리오 가능 여부 (true: 회원가입 혹은 계정 연동 가능, false: 불가능)
* @param isExistAccount boolean : 이미 존재하는 계정 여부
* @param userId Long : 사용자 ID. 없다면 null
* @param username String : 사용자 이름. 없다면 null
* @param oauthSync {@link OauthSync} : 연동할 Oauth 정보. 없다면 null
*/
public static UserSyncDto of(boolean isSignUpAllowed, boolean isExistAccount, Long userId, String username, OauthSync oauthSync) {
return new UserSyncDto(isSignUpAllowed, isExistAccount, userId, username, oauthSync);
public static UserSyncDto of(boolean isSignUpAllowed, boolean isExistAccount, Long userId, String username) {
return new UserSyncDto(isSignUpAllowed, isExistAccount, userId, username);
}

/**
* 이미 회원이 존재하는 경우 사용하는 편의용 메서드. <br/>
* 내부에서 {@link UserSyncDto#of(boolean, boolean, Long, String, OauthSync)}를 호출한다.
* 내부에서 {@link UserSyncDto#of(boolean, boolean, Long, String)}를 호출한다.
*/
public static UserSyncDto abort(Long userId, String username) {
return UserSyncDto.of(false, true, userId, username, null);
return UserSyncDto.of(false, true, userId, username);
}

/**
* 회원 가입 이력이 없는 경우 사용하는 편의용 메서드. <br/>
* 내부에서 {@link UserSyncDto#of(boolean, boolean, Long, String, OauthSync)}를 호출한다.
* 내부에서 {@link UserSyncDto#of(boolean, boolean, Long, String)}를 호출한다.
*/
public static UserSyncDto signUpAllowed() {
return UserSyncDto.of(true, false, null, null, null);
}

/**
* 기존의 soft delete된 Oauth 정보가 있는지 확인한다.
*/
public boolean isExistOauthAccount() {
return oauthSync != null;
}

public record OauthSync(
Long id,
String oauthId,
Provider provider,
LocalDateTime deletedAt
) {
/**
* Oauth 정보를 OauthSync로 변환한다. <br/>
* Oauth 정보가 없는 경우 null을 반환한다.
*/
public static OauthSync from(Oauth oauth) {
if (oauth == null) {
return null;
}
return new OauthSync(oauth.getId(), oauth.getOauthId(), oauth.getProvider(), oauth.getDeletedAt());
}
return UserSyncDto.of(true, false, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ public UserSyncDto isSignUpAllowed(Provider provider, String phone) {
return UserSyncDto.signUpAllowed();
}

Optional<Oauth> oauth = oauthService.readOauthByUserIdAndProvider(user.get().getId(), provider);

if (oauth.isPresent() && !oauth.get().isDeleted()) {
if (oauthService.isExistOauthByUserIdAndProvider(user.get().getId(), provider)) {
log.info("이미 동일한 Provider로 가입된 사용자입니다. phone: {}, provider: {}", phone, provider);
return UserSyncDto.abort(user.get().getId(), user.get().getUsername());
}

log.info("소셜 회원가입 사용자입니다. user: {}", user.get());
return UserSyncDto.of(true, true, user.get().getId(), user.get().getUsername(), UserSyncDto.OauthSync.from(oauth.orElse(null)));
return UserSyncDto.of(true, true, user.get().getId(), user.get().getUsername());
}

/**
Expand All @@ -78,7 +76,7 @@ public UserSyncDto isLinkAllowed(Long userId, String oauthId, Provider provider)

User user = userService.readUser(userId).orElseThrow(() -> new UserErrorException(UserErrorCode.NOT_FOUND));

return UserSyncDto.of(true, true, user.getId(), user.getUsername(), UserSyncDto.OauthSync.from(null));
return UserSyncDto.of(true, true, user.getId(), user.getUsername());
}

/**
Expand Down

0 comments on commit 6c9e614

Please sign in to comment.