Skip to content

Commit

Permalink
여러 BlockStrategy의 saveBlocks 메서드 매개변수 변경 및 blockUUID 추출 방식 수정 완료 (Fas…
Browse files Browse the repository at this point in the history
…tcampus-Final-Team3#195)

* refactor : MoveBlockStrategy 인터페이스에 saveBlocks 매개변수 수정 (Fastcampus-Final-Team3#194)

* refactor : saveBlocks 메서드의 매개변수 변경 및 UUID 추출 방식 수정 (Fastcampus-Final-Team3#194)

* refactor : processBlocks 메서드 매개변수 수정 (Fastcampus-Final-Team3#194)

* refactor : addBlockInfoToArray 매개변수 blockType String에서 ENUM 타입으로 수정(Fastcampus-Final-Team3#194)

* refactor : blockType ENUM으로 수정 (Fastcampus-Final-Team3#194)
  • Loading branch information
dpdmstjs authored Oct 25, 2023
1 parent 9c30e56 commit 3b196be
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,29 @@ public SpaceWallSaveResponse save(final Long memberId, final SpaceWallStringRequ
Member member = memberRepository.findMember(memberId);

DataStringSaveRequest data = spaceWallRequest.getData();

AddSpace addSpace = addSpaceRepository.findAddSpace(data.getSpaceId());

validateSpaceOwnership(member, addSpace);

validateAddSpaceId(addSpace.getId());

SpaceWallCategoryType spaceWallCategoryType = SpaceWallCategoryType.findSpaceWallCategoryTypeByString(data.getCategory());

ArrayNode blockInfoArray = blockJsonProcessor.createArrayNode();

AtomicLong blocksPositionCounter = new AtomicLong(INITIAL_POSITION);

processWallInfoBlock(data, blockInfoArray, blocksPositionCounter);

List<BlockSaveRequest<?>> blocks = data.getBlocks();

processBlocks(blocks, blockInfoArray, blocksPositionCounter);

processStyleSettingBlock(data, blockInfoArray, blocksPositionCounter);

String shareURL = spaceWallRequest.getData().getShareURL();

Long spaceWallId = saveSpaceWall(spaceWallCategoryType, member, addSpace, shareURL, flagType, blockInfoArray);

return new SpaceWallSaveResponse(spaceWallId);
Expand Down Expand Up @@ -170,7 +175,7 @@ private void processBlocks(final List<BlockSaveRequest<?>> blocks, final ArrayNo
String strategyName = blockType.getStrategyName();
MoveBlockStrategy blockProcessingStrategy = blockStrategyFactory.findMoveBlockStrategy(strategyName);

blockProcessingStrategy.saveBlocks(block.getSubData(), blockInfoArray, position);
blockProcessingStrategy.saveBlocks(block, blockInfoArray, position);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.javajober.spaceWall.domain.BlockType;

import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -41,12 +42,12 @@ public <T> T convertValue(final Object fromValue, final Class<T> toValueType) {
}
}

public void addBlockInfoToArray(final ArrayNode blockInfoArray, final Long position, final String blockType, final Long blockId, final String blockUUID) {
public void addBlockInfoToArray(final ArrayNode blockInfoArray, final Long position, final BlockType blockType, final Long blockId, final String blockUUID) {

ObjectNode blockInfoObject = jsonMapper.createObjectNode();

blockInfoObject.put("position", position);
blockInfoObject.put("block_type", blockType);
blockInfoObject.put("block_type", blockType.name());
blockInfoObject.put("block_id", blockId);
blockInfoObject.put("block_uuid", blockUUID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.javajober.core.util.response.CommonResponse;
import com.javajober.spaceWall.dto.request.BlockSaveRequest;

import java.util.List;

public interface MoveBlockStrategy {
void saveBlocks(final List<?> subData, final ArrayNode blockInfoArray, final Long position);
void saveBlocks(final BlockSaveRequest<?> block, final ArrayNode blockInfoArray, final Long position);

List<CommonResponse> createMoveBlockDTO(List<JsonNode> blocksWithSamePosition);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
import com.javajober.blocks.fileBlock.dto.request.FileBlockStringSaveRequest;
import com.javajober.blocks.fileBlock.repository.FileBlockRepository;
import com.javajober.spaceWall.domain.BlockType;
import com.javajober.spaceWall.dto.request.BlockSaveRequest;
import com.javajober.spaceWall.strategy.BlockJsonProcessor;
import com.javajober.spaceWall.strategy.BlockStrategyName;
import com.javajober.spaceWall.strategy.MoveBlockStrategy;

@Component
public class FileBlockStrategy implements MoveBlockStrategy {

private static final String FILE_BLOCK = BlockType.FILE_BLOCK.getEngTitle();
private final BlockJsonProcessor blockJsonProcessor;
private final FileBlockRepository fileBlockRepository;

Expand All @@ -31,15 +30,15 @@ public FileBlockStrategy(BlockJsonProcessor blockJsonProcessor, FileBlockReposit
}

@Override
public void saveBlocks(final List<?> subData, final ArrayNode blockInfoArray, final Long position) {
public void saveBlocks(final BlockSaveRequest<?> block, final ArrayNode blockInfoArray, final Long position) {

List<FileBlockStringSaveRequest> fileBlockRequests = convertSubDataToFileBlockSaveRequests(subData);
List<FileBlockStringSaveRequest> fileBlockRequests = convertSubDataToFileBlockSaveRequests(block.getSubData());

List<FileBlock> fileBlocks = convertToFileBlocks(fileBlockRequests);

List<FileBlock> savedFileBlocks = saveAllFileBlock(fileBlocks);

addToFileBlockInfoArray(savedFileBlocks, blockInfoArray, position);
addToFileBlockInfoArray(savedFileBlocks, blockInfoArray, position, block.getBlockType());
}

private List<FileBlockStringSaveRequest> convertSubDataToFileBlockSaveRequests(final List<?> subData) {
Expand All @@ -62,9 +61,9 @@ private List<FileBlock> saveAllFileBlock(final List<FileBlock> fileBlocks) {
return fileBlockRepository.saveAll(fileBlocks);
}

private void addToFileBlockInfoArray (final List<FileBlock> savedFileBlocks, final ArrayNode blockInfoArray, final Long position) {
private void addToFileBlockInfoArray (final List<FileBlock> savedFileBlocks, final ArrayNode blockInfoArray, final Long position, final String fileBlockUUID) {
savedFileBlocks.forEach(savedFileBlock ->
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, FILE_BLOCK, savedFileBlock.getId(), "")
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, BlockType.FILE_BLOCK, savedFileBlock.getId(), fileBlockUUID)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

import com.javajober.blocks.freeBlock.repository.FreeBlockRepository;
import com.javajober.spaceWall.domain.BlockType;
import com.javajober.spaceWall.dto.request.BlockSaveRequest;
import com.javajober.spaceWall.strategy.BlockJsonProcessor;
import com.javajober.spaceWall.strategy.BlockStrategyName;
import com.javajober.spaceWall.strategy.MoveBlockStrategy;

@Component
public class FreeBlockStrategy implements MoveBlockStrategy {
private static final String FREE_BLOCK = BlockType.FREE_BLOCK.getEngTitle();
private final BlockJsonProcessor blockJsonProcessor;
private final FreeBlockRepository freeBlockRepository;

Expand All @@ -30,15 +30,15 @@ public FreeBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final Free
}

@Override
public void saveBlocks(final List<?> subData, final ArrayNode blockInfoArray, final Long position) {
public void saveBlocks(final BlockSaveRequest<?> block, final ArrayNode blockInfoArray, final Long position) {

List<FreeBlockSaveRequest> freeBlockRequests = convertSubDataToFreeBlockSaveRequests(subData);
List<FreeBlockSaveRequest> freeBlockRequests = convertSubDataToFreeBlockSaveRequests(block.getSubData());

List<FreeBlock> freeBlocks = convertToFreeBlocks(freeBlockRequests);

List<FreeBlock> savedFreeBlocks = saveAllFreeBlock(freeBlocks);

addToFreeBlockInfoArray(savedFreeBlocks, blockInfoArray, position);
addToFreeBlockInfoArray(savedFreeBlocks, blockInfoArray, position, block.getBlockUUID());
}

private List<FreeBlockSaveRequest> convertSubDataToFreeBlockSaveRequests(final List<?> subData) {
Expand All @@ -61,9 +61,9 @@ private List<FreeBlock> saveAllFreeBlock(final List<FreeBlock> freeBlocks) {
return freeBlockRepository.saveAll(freeBlocks);
}

private void addToFreeBlockInfoArray (final List<FreeBlock> savedFreeBlocks, final ArrayNode blockInfoArray, final Long position) {
private void addToFreeBlockInfoArray (final List<FreeBlock> savedFreeBlocks, final ArrayNode blockInfoArray, final Long position, final String freeBlockUUID) {
savedFreeBlocks.forEach(savedFreeBlock ->
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, FREE_BLOCK, savedFreeBlock.getId(), "")
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, BlockType.FREE_BLOCK, savedFreeBlock.getId(), freeBlockUUID)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import com.javajober.blocks.listBlock.dto.request.ListBlockSaveRequest;
import com.javajober.blocks.listBlock.repository.ListBlockRepository;
import com.javajober.spaceWall.domain.BlockType;
import com.javajober.spaceWall.dto.request.BlockSaveRequest;
import com.javajober.spaceWall.strategy.BlockJsonProcessor;
import com.javajober.spaceWall.strategy.BlockStrategyName;
import com.javajober.spaceWall.strategy.MoveBlockStrategy;

@Component
public class ListBlockStrategy implements MoveBlockStrategy {

private static final String LIST_BLOCK = BlockType.LIST_BLOCK.getEngTitle();
private final BlockJsonProcessor blockJsonProcessor;
private final ListBlockRepository listBlockRepository;

Expand All @@ -31,15 +31,15 @@ public ListBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final List
}

@Override
public void saveBlocks(final List<?> subData, final ArrayNode blockInfoArray, final Long position) {
public void saveBlocks(final BlockSaveRequest<?> block, final ArrayNode blockInfoArray, final Long position) {

List<ListBlockSaveRequest> listBlockRequests = convertSubDataToListBlockSaveRequests(subData);
List<ListBlockSaveRequest> listBlockRequests = convertSubDataToListBlockSaveRequests(block.getSubData());

List<ListBlock> listBlocks = convertToListBlocks(listBlockRequests);

List<ListBlock> savedListBlocks = saveAllListBlock(listBlocks);

addToListBlockInfoArray(savedListBlocks, blockInfoArray, position);
addToListBlockInfoArray(savedListBlocks, blockInfoArray, position, block.getBlockUUID());
}

private List<ListBlockSaveRequest> convertSubDataToListBlockSaveRequests(final List<?> subData) {
Expand All @@ -62,9 +62,9 @@ private List<ListBlock> saveAllListBlock(final List<ListBlock> listBlocks) {
return listBlockRepository.saveAll(listBlocks);
}

private void addToListBlockInfoArray (final List<ListBlock> savedListBlocks, final ArrayNode blockInfoArray, final Long position) {
private void addToListBlockInfoArray (final List<ListBlock> savedListBlocks, final ArrayNode blockInfoArray, final Long position, final String listBlockUUID) {
savedListBlocks.forEach(savedListBlock ->
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, LIST_BLOCK, savedListBlock.getId(), savedListBlock.getListUUID())
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, BlockType.LIST_BLOCK, savedListBlock.getId(), listBlockUUID)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.javajober.blocks.snsBlock.dto.request.SNSBlockSaveRequest;
import com.javajober.blocks.snsBlock.repository.SNSBlockRepository;
import com.javajober.spaceWall.domain.BlockType;
import com.javajober.spaceWall.dto.request.BlockSaveRequest;
import com.javajober.spaceWall.strategy.BlockJsonProcessor;
import com.javajober.spaceWall.strategy.BlockStrategyName;
import com.javajober.spaceWall.strategy.MoveBlockStrategy;
Expand All @@ -25,7 +26,6 @@
@Slf4j
public class SNSBlockStrategy implements MoveBlockStrategy {

private static final String SNS_BLOCK = BlockType.SNS_BLOCK.getEngTitle();
private final BlockJsonProcessor blockJsonProcessor;
private final SNSBlockRepository snsBlockRepository;

Expand All @@ -35,14 +35,14 @@ public SNSBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final SNSBl
}

@Override
public void saveBlocks(final List<?> subData, final ArrayNode blockInfoArray, final Long position) {
List<SNSBlockSaveRequest> snsBlockRequests = convertSubDataToSNSBlockSaveRequests(subData);
public void saveBlocks(final BlockSaveRequest<?> block, final ArrayNode blockInfoArray, final Long position) {
List<SNSBlockSaveRequest> snsBlockRequests = convertSubDataToSNSBlockSaveRequests(block.getSubData());

List<SNSBlock> snsBlocks = convertToSNSBlocks(snsBlockRequests);

List<SNSBlock> savedSNSBlocks = saveAllSNSBlock(snsBlocks);

addToSNSBlockInfoArray(savedSNSBlocks, blockInfoArray, position);
addToSNSBlockInfoArray(savedSNSBlocks, blockInfoArray, position, block.getBlockUUID());
}

private List<SNSBlockSaveRequest> convertSubDataToSNSBlockSaveRequests(final List<?> subData) {
Expand All @@ -65,9 +65,9 @@ private List<SNSBlock> saveAllSNSBlock(final List<SNSBlock> snsBlocks) {
return snsBlockRepository.saveAll(snsBlocks);
}

private void addToSNSBlockInfoArray (final List<SNSBlock> savedSNSBlocks, final ArrayNode blockInfoArray, final Long position) {
private void addToSNSBlockInfoArray (final List<SNSBlock> savedSNSBlocks, final ArrayNode blockInfoArray, final Long position, String snsBlockUUID) {
savedSNSBlocks.forEach(savedSNSBlock ->
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, SNS_BLOCK, savedSNSBlock.getId(), "")
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, BlockType.SNS_BLOCK, savedSNSBlock.getId(), snsBlockUUID)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
@Component
public class StyleSettingStrategy implements FixBlockStrategy {

private static final String STYLE_SETTING = BlockType.STYLE_SETTING.getEngTitle();
private final BlockJsonProcessor blockJsonProcessor;
private final StyleSettingRepository styleSettingRepository;
private final BackgroundSettingRepository backgroundSettingRepository;
Expand All @@ -54,7 +53,7 @@ public void saveBlocks(final DataStringSaveRequest data, ArrayNode blockInfoArra
StyleSettingStringSaveRequest request = data.getStyleSetting();

Long styleSettingId = saveStyleSetting(request);
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, STYLE_SETTING, styleSettingId, "");
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, BlockType.STYLE_SETTING, styleSettingId, "");
}

private Long saveStyleSetting(final StyleSettingStringSaveRequest request){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import com.javajober.blocks.templateBlock.dto.request.TemplateBlockSaveRequest;
import com.javajober.blocks.templateBlock.repository.TemplateBlockRepository;
import com.javajober.spaceWall.domain.BlockType;
import com.javajober.spaceWall.dto.request.BlockSaveRequest;
import com.javajober.spaceWall.strategy.BlockJsonProcessor;
import com.javajober.spaceWall.strategy.BlockStrategyName;
import com.javajober.spaceWall.strategy.MoveBlockStrategy;

@Component
public class TemplateBlockStrategy implements MoveBlockStrategy {

private static final String TEMPLATE_BLOCK = BlockType.TEMPLATE_BLOCK.getEngTitle();
private final BlockJsonProcessor blockJsonProcessor;
private final TemplateBlockRepository templateBlockRepository;

Expand All @@ -32,14 +32,14 @@ public TemplateBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final
}

@Override
public void saveBlocks(final List<?> subData, final ArrayNode blockInfoArray, final Long position) {
List<TemplateBlockSaveRequest> templateBlockRequests = convertSubDataToTemplateBlockSaveRequests(subData);
public void saveBlocks(final BlockSaveRequest<?> block, final ArrayNode blockInfoArray, final Long position) {
List<TemplateBlockSaveRequest> templateBlockRequests = convertSubDataToTemplateBlockSaveRequests(block.getSubData());

List<TemplateBlock> templateBlocks = convertToTemplateBlocks(templateBlockRequests);

List<TemplateBlock> savedTemplateBlocks = saveAllTemplateBlock(templateBlocks);

addToTemplateBlockInfoArray(savedTemplateBlocks, blockInfoArray, position);
addToTemplateBlockInfoArray(savedTemplateBlocks, blockInfoArray, position, block.getBlockUUID());
}

private List<TemplateBlockSaveRequest> convertSubDataToTemplateBlockSaveRequests(final List<?> subData) {
Expand All @@ -62,9 +62,9 @@ private List<TemplateBlock> saveAllTemplateBlock(final List<TemplateBlock> templ
return templateBlockRepository.saveAll(templateBlocks);
}

private void addToTemplateBlockInfoArray (final List<TemplateBlock> savedTemplateBlocks, final ArrayNode blockInfoArray, final Long position) {
private void addToTemplateBlockInfoArray (final List<TemplateBlock> savedTemplateBlocks, final ArrayNode blockInfoArray, final Long position, String templateBlockUUID) {
savedTemplateBlocks.forEach(savedTemplateBlock ->
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, TEMPLATE_BLOCK, savedTemplateBlock.getId(), "")
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, BlockType.TEMPLATE_BLOCK, savedTemplateBlock.getId(), templateBlockUUID)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

@Component
public class WallInfoBlockStrategy implements FixBlockStrategy {
private static final String WALL_INFO_BLOCK = BlockType.WALL_INFO_BLOCK.getEngTitle();
private final BlockJsonProcessor blockJsonProcessor;
private final WallInfoBlockRepository wallInfoBlockRepository;

Expand All @@ -33,7 +32,7 @@ public WallInfoBlockStrategy(BlockJsonProcessor blockJsonProcessor, WallInfoBloc
public void saveBlocks(final DataStringSaveRequest data, ArrayNode blockInfoArray, Long position) {
WallInfoBlockStringSaveRequest request = data.getWallInfoBlock();
Long wallInfoBlockId = saveWallInfoBlock(request);
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, WALL_INFO_BLOCK, wallInfoBlockId,"");
blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, BlockType.WALL_INFO_BLOCK, wallInfoBlockId,"");
}

private Long saveWallInfoBlock(WallInfoBlockStringSaveRequest request) {
Expand Down

0 comments on commit 3b196be

Please sign in to comment.