Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refac] 로그인 로직 리팩토링 #252

Merged
merged 20 commits into from
Jan 13, 2025
Merged

[refac] 로그인 로직 리팩토링 #252

merged 20 commits into from
Jan 13, 2025

Conversation

kgy1008
Copy link
Member

@kgy1008 kgy1008 commented Jan 12, 2025

Related Issue 📌

close #247

Description ✔️

  • 전략 패턴과 템플릿 메서드 패턴을 이용해서 OCP와 DIP 원칙을 지키도록 수정
  • 로그인 시, 이름이 공백으로 들어오면 "한끼"로 디폴트 이름이 들어가도록 수정

To Reviewers

변경 사항이 많은건 패키지를 바꿔서 그렇습니다.
중점적으로는 OAuthProvider 인터페이스 만든거랑 각 구현체인 Kakao/AppleOAuthProvider 클래스, AuthService, OAuthProviderFactory만 보면 될 것 같습니다.


고민이 있는데, OAuthProvider라는 인터페이스를 만들었지만 각 구현체 별로 필요로 하는 파라미터 개수나 타입이 달라서 어떻게 해야할지 고민입니다.
대표적인 예가 AuthService의 withdraw 로직에 주석으로 적혀있듯이

oAuthProvider.requestRevoke(code, user.getSerialId());

애플 로그인은 code만 필요하고 카카오 로그인은 후자만 필요한데, 인터페이스로 처리하려다 보니 불필요하게 파라미터를 둘 다 받아야하는 문제점이 생겨버림..

그래서 각 OAuth마다 필요로 하는 응답을 또 만들어주는 클래스를 만들까 고민도 했지만 그렇게 되면 응답으로 넘기는 데이터를 클래스로 감싸야하고 또 그 위에 인터페이스도 둬야하고.... 너무 과분리 같기도 하고 고민입니둥

@kgy1008 kgy1008 added enhancement New feature or request api labels Jan 12, 2025
@kgy1008 kgy1008 self-assigned this Jan 12, 2025
Comment on lines 1 to 8
package org.hankki.hankkiserver.external.openfeign.oauth;

public interface OAuthProvider {

SocialInfoDto getUserInfo(String token, String name);

void requestRevoke(String code, String Id);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인터페이스 위치는 api의 서비스가 적절하지 않을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구현체인 Kakao/AppleOAuthProvider 클래스가 external 패키지에 위치하기 때문에 같은 패키지에 위치시키는 것이 맞다고 생각했습니다. 실제로 해당 인터페이스는 외부 서버와 통신할 때 사용하는 인터페이스이기 때문에 api보다는 external에 위치시키는것이 더 나을것 같다고 생각했어요

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저희 앞으로 구조를 바꿀텐데, 서비스에서의 의존성들을 최소화하고 구현체들을 갈아끼우는 형태로 바꾸려면 service에서 interface를 정의하는게 맞지 않을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 이해를 못했는데, 현재 서비스에서도 직접적으로 구현체에 의존하고 있지 않고 OAuthProvider라는 인터페이스에만 의존하고 있기 때문에 괜찮지 않나요? 무엇보다 저는 구현체인 클래스들과 그 상위 인터페이스를 다른 페키지에 위치시키는 것이 오히려 응집도가 떨어진다고 생각해요. 인터페이스와 구현체가 같은 맥락에서 관리되어야 유지보수와 가독성이 더 높아질 수 있다고 생각합니다.

Copy link
Contributor

@Parkjyun Parkjyun Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금구조에서는 service 패키지가 다른 패키지들에 많은 의존성을 지니지만, 앞으로 service의 의존성들을 없애는 방향으로 개발을 한다면, 외부와 통신하는 인터페이스를 service에 두어 external이 반대로 service에 의존하게 한다는 의미에서 말씀드린겁니다.
물론 말씀하신 것처럼 지금도 구현체에 의존하는 것은 아니지만 어쨌든 service에서 external에 대한 의존성이 생기는 것은 맞으니까용

Comment on lines 15 to 18

private final KakaoOAuthProvider kakaoOAuthProvider;
private final AppleOAuthProvider appleOAuthProvider;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그냥 List나 map으로 oauthProvider로 바로 주입 받는 방식이 ocp에는 더 좋을 거 같아요
이렇게 하면 결국 새로운 구현체가 추가되었을 때 코드를 수정해야하니까요

Comment on lines 19 to 24
public OAuthProvider findProvider(final Platform platform) {
if (KAKAO == platform) {
return kakaoOAuthProvider;
}
return appleOAuthProvider;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빈이름 사용해도 좋을거 같아요

Copy link
Member Author

@kgy1008 kgy1008 Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에 남겨주신 리뷰까지 모두 반영하여 수정했습니당

@Service
@Transactional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 외부 통신 트랜잭션 분리는 안 하신거죠?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넹 이건 따로 이슈 파서 진행할 예정입니다~

@kgy1008 kgy1008 merged commit 4333445 into develop Jan 13, 2025
1 check passed
@kgy1008 kgy1008 deleted the refac/247 branch January 13, 2025 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[refac] 로그인 로직 리팩토링
2 participants