diff --git a/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java b/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java index 52287e7..3c564f2 100644 --- a/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java +++ b/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java @@ -114,9 +114,11 @@ 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()); @@ -124,14 +126,17 @@ public SpaceWallSaveResponse save(final Long memberId, final SpaceWallStringRequ ArrayNode blockInfoArray = blockJsonProcessor.createArrayNode(); AtomicLong blocksPositionCounter = new AtomicLong(INITIAL_POSITION); + processWallInfoBlock(data, blockInfoArray, blocksPositionCounter); List> 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); @@ -170,7 +175,7 @@ private void processBlocks(final List> blocks, final ArrayNo String strategyName = blockType.getStrategyName(); MoveBlockStrategy blockProcessingStrategy = blockStrategyFactory.findMoveBlockStrategy(strategyName); - blockProcessingStrategy.saveBlocks(block.getSubData(), blockInfoArray, position); + blockProcessingStrategy.saveBlocks(block, blockInfoArray, position); }); } diff --git a/src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java b/src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java index b49da64..ce1101e 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java +++ b/src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java @@ -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; @@ -41,12 +42,12 @@ public T convertValue(final Object fromValue, final Class 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); diff --git a/src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java index 8cb0504..3c40b6f 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java @@ -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 createMoveBlockDTO(List blocksWithSamePosition); diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java index f1831d1..b211671 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java @@ -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; @@ -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 fileBlockRequests = convertSubDataToFileBlockSaveRequests(subData); + List fileBlockRequests = convertSubDataToFileBlockSaveRequests(block.getSubData()); List fileBlocks = convertToFileBlocks(fileBlockRequests); List savedFileBlocks = saveAllFileBlock(fileBlocks); - addToFileBlockInfoArray(savedFileBlocks, blockInfoArray, position); + addToFileBlockInfoArray(savedFileBlocks, blockInfoArray, position, block.getBlockType()); } private List convertSubDataToFileBlockSaveRequests(final List subData) { @@ -62,9 +61,9 @@ private List saveAllFileBlock(final List fileBlocks) { return fileBlockRepository.saveAll(fileBlocks); } - private void addToFileBlockInfoArray (final List savedFileBlocks, final ArrayNode blockInfoArray, final Long position) { + private void addToFileBlockInfoArray (final List 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) ); } diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java index c25ef5b..f388d44 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java @@ -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; @@ -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 freeBlockRequests = convertSubDataToFreeBlockSaveRequests(subData); + List freeBlockRequests = convertSubDataToFreeBlockSaveRequests(block.getSubData()); List freeBlocks = convertToFreeBlocks(freeBlockRequests); List savedFreeBlocks = saveAllFreeBlock(freeBlocks); - addToFreeBlockInfoArray(savedFreeBlocks, blockInfoArray, position); + addToFreeBlockInfoArray(savedFreeBlocks, blockInfoArray, position, block.getBlockUUID()); } private List convertSubDataToFreeBlockSaveRequests(final List subData) { @@ -61,9 +61,9 @@ private List saveAllFreeBlock(final List freeBlocks) { return freeBlockRepository.saveAll(freeBlocks); } - private void addToFreeBlockInfoArray (final List savedFreeBlocks, final ArrayNode blockInfoArray, final Long position) { + private void addToFreeBlockInfoArray (final List 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) ); } diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java index 950e3de..b3048f4 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java @@ -14,6 +14,7 @@ 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; @@ -21,7 +22,6 @@ @Component public class ListBlockStrategy implements MoveBlockStrategy { - private static final String LIST_BLOCK = BlockType.LIST_BLOCK.getEngTitle(); private final BlockJsonProcessor blockJsonProcessor; private final ListBlockRepository listBlockRepository; @@ -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 listBlockRequests = convertSubDataToListBlockSaveRequests(subData); + List listBlockRequests = convertSubDataToListBlockSaveRequests(block.getSubData()); List listBlocks = convertToListBlocks(listBlockRequests); List savedListBlocks = saveAllListBlock(listBlocks); - addToListBlockInfoArray(savedListBlocks, blockInfoArray, position); + addToListBlockInfoArray(savedListBlocks, blockInfoArray, position, block.getBlockUUID()); } private List convertSubDataToListBlockSaveRequests(final List subData) { @@ -62,9 +62,9 @@ private List saveAllListBlock(final List listBlocks) { return listBlockRepository.saveAll(listBlocks); } - private void addToListBlockInfoArray (final List savedListBlocks, final ArrayNode blockInfoArray, final Long position) { + private void addToListBlockInfoArray (final List 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) ); } diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java index cf2aca9..670d904 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java @@ -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; @@ -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; @@ -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 snsBlockRequests = convertSubDataToSNSBlockSaveRequests(subData); + public void saveBlocks(final BlockSaveRequest block, final ArrayNode blockInfoArray, final Long position) { + List snsBlockRequests = convertSubDataToSNSBlockSaveRequests(block.getSubData()); List snsBlocks = convertToSNSBlocks(snsBlockRequests); List savedSNSBlocks = saveAllSNSBlock(snsBlocks); - addToSNSBlockInfoArray(savedSNSBlocks, blockInfoArray, position); + addToSNSBlockInfoArray(savedSNSBlocks, blockInfoArray, position, block.getBlockUUID()); } private List convertSubDataToSNSBlockSaveRequests(final List subData) { @@ -65,9 +65,9 @@ private List saveAllSNSBlock(final List snsBlocks) { return snsBlockRepository.saveAll(snsBlocks); } - private void addToSNSBlockInfoArray (final List savedSNSBlocks, final ArrayNode blockInfoArray, final Long position) { + private void addToSNSBlockInfoArray (final List 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) ); } diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingStrategy.java index c83bb50..3ce5e3d 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingStrategy.java @@ -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; @@ -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){ diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java index 47d1284..041a6a7 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java @@ -15,6 +15,7 @@ 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; @@ -22,7 +23,6 @@ @Component public class TemplateBlockStrategy implements MoveBlockStrategy { - private static final String TEMPLATE_BLOCK = BlockType.TEMPLATE_BLOCK.getEngTitle(); private final BlockJsonProcessor blockJsonProcessor; private final TemplateBlockRepository templateBlockRepository; @@ -32,14 +32,14 @@ public TemplateBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final } @Override - public void saveBlocks(final List subData, final ArrayNode blockInfoArray, final Long position) { - List templateBlockRequests = convertSubDataToTemplateBlockSaveRequests(subData); + public void saveBlocks(final BlockSaveRequest block, final ArrayNode blockInfoArray, final Long position) { + List templateBlockRequests = convertSubDataToTemplateBlockSaveRequests(block.getSubData()); List templateBlocks = convertToTemplateBlocks(templateBlockRequests); List savedTemplateBlocks = saveAllTemplateBlock(templateBlocks); - addToTemplateBlockInfoArray(savedTemplateBlocks, blockInfoArray, position); + addToTemplateBlockInfoArray(savedTemplateBlocks, blockInfoArray, position, block.getBlockUUID()); } private List convertSubDataToTemplateBlockSaveRequests(final List subData) { @@ -62,9 +62,9 @@ private List saveAllTemplateBlock(final List templ return templateBlockRepository.saveAll(templateBlocks); } - private void addToTemplateBlockInfoArray (final List savedTemplateBlocks, final ArrayNode blockInfoArray, final Long position) { + private void addToTemplateBlockInfoArray (final List 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) ); } diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java index 1922ec8..ed7a917 100644 --- a/src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java @@ -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; @@ -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) {