-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/beforespring/socialfeed/content/service/ExternalApiHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/beforespring/socialfeed/content/service/ExternalApiHandlerResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ContentSourceType, ExternalApiHandler> handlerMap = new HashMap<>(); | ||
|
||
@Autowired | ||
public ExternalApiHandlerResolver(List<ExternalApiHandler> handlers) { | ||
handlers.forEach(handler -> handlerMap.put(handler.getSourceType(), handler)); | ||
} | ||
/** | ||
* 핸들러를 검색하여 반환. | ||
* | ||
* @param sourceType sourceType | ||
* @return 해당 sourceType 에 대응하는 핸들러 | ||
*/ | ||
|
||
public ExternalApiHandler resolveHandler(ContentSourceType sourceType) { | ||
return handlerMap.get(sourceType); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/beforespring/socialfeed/content/service/FacebookApiHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |