Skip to content

Commit

Permalink
Feat: 외부 API 핸들러 및 리졸버 추가 (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhk313 authored Oct 29, 2023
1 parent ed1d7a6 commit 6c06da0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
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);
}
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);
}
}
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);
}
}

0 comments on commit 6c06da0

Please sign in to comment.