Skip to content

Commit

Permalink
[Fix] 전략 패턴이 제대로 동작하지 않던 문제를 해결함 #58
Browse files Browse the repository at this point in the history
  • Loading branch information
NARUBROWN committed Jul 13, 2024
1 parent 93b1b55 commit de120ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package server.inuappcenter.kr.service.boardService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import server.inuappcenter.kr.data.dto.response.BoardResponseDto;
Expand All @@ -11,14 +13,16 @@

@Component
public class AdditionalBoardStrategyProviderImpl implements AdditionalBoardStrategyProvider {
private static final Logger log = LoggerFactory.getLogger(AdditionalBoardStrategyProviderImpl.class);
private final Map<String, AdditionalBoardService> boardStrategyMap;

@Autowired
public AdditionalBoardStrategyProviderImpl(List<AdditionalBoardService> additionalBoardServices) {
this.boardStrategyMap = new HashMap<>();
for (AdditionalBoardService additionalBoardService : additionalBoardServices) {
String key = additionalBoardService.getClass().getSimpleName().toLowerCase();
this.boardStrategyMap.put(key, additionalBoardService);
int index = key.indexOf("$");
this.boardStrategyMap.put(key.substring(0, index), additionalBoardService);
}
}

Expand All @@ -31,7 +35,9 @@ public List<BoardResponseDto> findBoardList(String boardName, String topic) {

@Override
public List<BoardResponseDto> findBoardList(String boardName) {
log.info("getTest");
AdditionalBoardService additionalBoardService = boardStrategyMap.get(boardName.toLowerCase());
System.out.println(additionalBoardService.getClass().getSimpleName());
return additionalBoardService.findBoardList(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;
import java.util.stream.Collectors;

@Service
@Service("FaqBoardServiceImpl")
@RequiredArgsConstructor
@Slf4j
public class FaqBoardServiceImpl implements AdditionalBoardService {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server.inuappcenter.kr.service.boardService.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import server.inuappcenter.kr.data.domain.board.Board;
Expand All @@ -11,15 +12,17 @@
import java.util.ArrayList;
import java.util.List;

@Service
@Service("IntroBoardServiceImpl")
@RequiredArgsConstructor
@Slf4j
public class IntroBoardServiceImpl implements AdditionalBoardService {
private final IntroBoardRepository introBoardRepository;
private final HttpServletRequest request;

@Override
@Transactional(readOnly = true)
public List<BoardResponseDto> findBoardList(String topic) {
log.info("findBoardList");
List<BoardResponseDto> responseDtoList = new ArrayList<>();
for (Board board : introBoardRepository.findAll()) {
responseDtoList.add(board.createResponse(request));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.ArrayList;
import java.util.List;

@Service
@Service("PhotoBoardServiceImpl")
@RequiredArgsConstructor
@Slf4j
public class PhotoBoardServiceImpl implements AdditionalBoardService {
Expand Down

0 comments on commit de120ed

Please sign in to comment.