diff --git a/src/main/java/beforespring/socialfeed/content/service/ExternalApiHandler.java b/src/main/java/beforespring/socialfeed/content/service/ExternalApiHandler.java new file mode 100644 index 0000000..1c30ea1 --- /dev/null +++ b/src/main/java/beforespring/socialfeed/content/service/ExternalApiHandler.java @@ -0,0 +1,11 @@ +package beforespring.socialfeed.content.service; + +import beforespring.socialfeed.content.domain.ContentSourceType; +/** + * 외부 API 핸들러를 정의하는 인터페이스 + */ +public interface ExternalApiHandler { + ContentSourceType getSourceType(); + void like(String contentSourceId); + void share(String contentSourceId); +} diff --git a/src/main/java/beforespring/socialfeed/content/service/ExternalApiHandlerResolver.java b/src/main/java/beforespring/socialfeed/content/service/ExternalApiHandlerResolver.java new file mode 100644 index 0000000..42c3a32 --- /dev/null +++ b/src/main/java/beforespring/socialfeed/content/service/ExternalApiHandlerResolver.java @@ -0,0 +1,29 @@ +package beforespring.socialfeed.content.service; + +import beforespring.socialfeed.content.domain.ContentSourceType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +public class ExternalApiHandlerResolver { + private final Map handlerMap = new HashMap<>(); + + @Autowired + public ExternalApiHandlerResolver(List handlers) { + handlers.forEach(handler -> handlerMap.put(handler.getSourceType(), handler)); + } + /** + * 핸들러를 검색하여 반환. + * + * @param sourceType sourceType + * @return 해당 sourceType 에 대응하는 핸들러 + */ + + public ExternalApiHandler resolveHandler(ContentSourceType sourceType) { + return handlerMap.get(sourceType); + } +} diff --git a/src/main/java/beforespring/socialfeed/content/service/FacebookApiHandler.java b/src/main/java/beforespring/socialfeed/content/service/FacebookApiHandler.java new file mode 100644 index 0000000..f8de06b --- /dev/null +++ b/src/main/java/beforespring/socialfeed/content/service/FacebookApiHandler.java @@ -0,0 +1,24 @@ +package beforespring.socialfeed.content.service; + +import beforespring.socialfeed.content.domain.ContentSourceType; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class FacebookApiHandler implements ExternalApiHandler{ + @Override + public ContentSourceType getSourceType() { + return ContentSourceType.FACEBOOK; + } + + @Override + public void like(String contentSourceId) { + log.info("Facebook like contentSourceId: {}", contentSourceId); + } + + @Override + public void share(String contentSourceId) { + log.info("Facebook share contentSourceId: {}", contentSourceId); + } +}