Skip to content

Commit

Permalink
fix: LoginHandler 일급 컬렉션 변환 #13
Browse files Browse the repository at this point in the history
  • Loading branch information
kamser0415 committed Oct 26, 2024
1 parent 6c3ae8b commit fc06fc3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
27 changes: 27 additions & 0 deletions src/main/java/shop/sendbox/sendbox/login/LoginHandlers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package shop.sendbox.sendbox.login;

import java.util.List;

import org.springframework.stereotype.Component;

/*
@Component 애노테이션은 해당 클래스가 컴포넌트 스캔 대상을 표시합니다.
컴포넌트 스캔 대상이 스프링 컨테이너에 빈으로 등록되면 동일한 위치와 그 이하 패키지는 모두 스프링 빈으로 등록됩니다.
*/
@Component
public class LoginHandlers {

private final List<LoginHandler> loginHandlers;

public LoginHandlers(List<LoginHandler> loginHandlers) {
this.loginHandlers = List.copyOf(loginHandlers);
}

public LoginHandler getLoginHandler(UserType userType) {
return loginHandlers.stream()
.filter(loginHandler -> loginHandler.supports(userType))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("지원하지 않는 유저 타입입니다."));
}

}
7 changes: 2 additions & 5 deletions src/main/java/shop/sendbox/sendbox/login/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@RequiredArgsConstructor
public class LoginService {

private final List<LoginHandler> loginHandlerList;
private final LoginHandlers loginHandlerList;

/*
JPA는 기본적으로 데이터를 조회하면 스냅샷을 만들고, Dirty Checking을 통해 변경된 데이터를 감지합니다.
Expand All @@ -31,10 +31,7 @@ public LoginResponse login(LoginRequest loginRequest) {
}

private LoginHandler getLoginHandler(UserType userType) {
return loginHandlerList.stream()
.filter(loginHandler -> loginHandler.supports(userType))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("지원하지 않는 유저 타입입니다."));
return loginHandlerList.getLoginHandler(userType);
}

}

0 comments on commit fc06fc3

Please sign in to comment.