Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class MemberController {

private final MemberService memberService;

@GetMapping("/member/oauth/{logintype}")
public void oauthLogin(@PathVariable("logintype") String loginType) {
@GetMapping("/member/oauth/{loginType}")
public void oauthLogin(@PathVariable("loginType") String loginType) {
memberService.oauthLogin(loginType);
}

@PostMapping("/member/oauth/{loginType}")
public void oauthRegister(@PathVariable("logintype") String loginType) {
public void oauthRegister(@PathVariable("loginType") String loginType) {
memberService.oauthRegister(loginType);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package com.recordit.server.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.recordit.server.service.oauth.OauthService;
import com.recordit.server.service.oauth.OauthServiceLocator;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class MemberService {
private final List<OauthService> oauthServices;
private final OauthServiceLocator oauthServiceLocator;

@Transactional
public void oauthLogin(String loginType) {

OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType);
}

@Transactional
public void oauthRegister(String loginType) {

OauthService oauthService = oauthServiceLocator.getOauthServiceByLoginType(loginType);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.recordit.server.service.oauth;

import org.springframework.stereotype.Service;

import com.recordit.server.constant.LoginType;

@Service
public class GoogleOauthService implements OauthService {
@Override
public LoginType getLoginType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.recordit.server.service.oauth;

import org.springframework.stereotype.Service;

import com.recordit.server.constant.LoginType;

@Service
public class KakaoOauthService implements OauthService {
@Override
public LoginType getLoginType() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.recordit.server.service.oauth;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class OauthServiceLocator {
private final List<OauthService> oauthServices;

public OauthService getOauthServiceByLoginType(String loginType) {
if (!StringUtils.hasText(loginType)) {
throw new NullPointerException("로그인 타입이 없습니다.");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'로그인 타입이 없습니다.' 보다는 '로그인 타입이 입력되지 않았습니다.' 이렇게 조금 더 명시적으로 하는게 어떨까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

좋습니다!!

}
for (OauthService service : oauthServices) {
Copy link
Copy Markdown
Contributor

@Jaeyeop-Jung Jaeyeop-Jung Dec 21, 2022

Choose a reason for hiding this comment

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

return oauthServices.stream() .filter(oauthService -> oauthService.getLoginType().name().equals(loginType)) .findAny() .orElseThrow(() -> new NullPointerException("일치하는 로그인 타입이 없습니다."));
여기 로직을 이렇게 하는건 어떨까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

굳 감사합니다 훨씬 깔끔하네요

if (loginType.equals(service.getLoginType().name())) {
return service;
}
}
throw new NullPointerException("일치하는 로그인 타입이 없습니다.");
}
}