From 6c06da00ce02591215e91d8eef1a33a4154a7eeb Mon Sep 17 00:00:00 2001 From: yhk313 <75387909+yhk313@users.noreply.github.com> Date: Sun, 29 Oct 2023 16:41:21 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=99=B8=EB=B6=80=20API=20=ED=95=B8?= =?UTF-8?q?=EB=93=A4=EB=9F=AC=20=EB=B0=8F=20=EB=A6=AC=EC=A1=B8=EB=B2=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#65)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content/service/ExternalApiHandler.java | 11 +++++++ .../service/ExternalApiHandlerResolver.java | 29 +++++++++++++++++++ .../content/service/FacebookApiHandler.java | 24 +++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/main/java/beforespring/socialfeed/content/service/ExternalApiHandler.java create mode 100644 src/main/java/beforespring/socialfeed/content/service/ExternalApiHandlerResolver.java create mode 100644 src/main/java/beforespring/socialfeed/content/service/FacebookApiHandler.java 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); + } +}