From 36afecaf22b5483fe57640925af22b9d25efd9cc Mon Sep 17 00:00:00 2001 From: YeEun Sun Date: Sun, 22 Oct 2023 10:25:33 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B3=B5=EC=9C=A0=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5=20API=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=20(#180)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor : FixBlockStrategy 인터페이스 생성 (#179) * refactor : MoveBlockStrategy 인터페이스 생성 (#179) * refactor : 다양한 블록 전략 유형을 위한 BlockStrategyName 생성 (#179) * refactor : MoveBlockStrategy 인터페이스에 saveBlocks와 getStrategyName 메서드 정의 (#179) * refactor : FileBlockStrategy 클래스에 saveBlocks 메서드 구현 (#179) * refactor : FreeBlockStrategy 클래스에 saveBlocks 메서드 구현 (#179) * refactor : ListBlockStrategy 클래스에 saveBlocks 메서드 구현 (#179) * refactor : SNSBlockStrategy 클래스에 saveBlocks 메서드 구현 (#179) * refactor : TemplateBlockStrategy 클래스에 saveBlocks 메서드 구현 (#179) * refactor : BlockStrategyFactory 클래스 추가 및 구현 (#179) - MoveBlockStrategy와 FixBlockStrategy 인터페이스를 구현하는 여러 전략들을 관리하고, 필요한 전략을 찾아 반환합니다. * refactor : SpaceWallService save 메서드 리팩토링 (#179) * refactor : BlockJsonHandler 클래스 생성 및 ObjectMapper 활용 개선 (#179) * refactor : blockJsonHandler를 활용하여 메서드 변경 (#179) * refactor : blockJsonHandler를 활용하여 메서드 변경 및 매개변수 수정 (#179) * refactor : toEntity 메서드를 static factory method로 변경 (#179) * refactor : FixBlockStrategy 인터페이스에 saveBlocks와 getStrategyName 메서드 정의 (#179) * refactor : WallInfoBlockStrategy 클래스에 saveBlocks 메서드 구현 (#179) * refactor : StyleSettingBlockStrategy 클래스에 saveBlocks 메서드 구현 (#179) * refactor : FixBlockStrategy 전략 패턴을 활용한 SpaceWall 저장 메서드 변경 (#179) * refactor : 불필요한 클래스 및 import, 변수, 메서드 제거 (#179) * refactor : strategyName 필드 추가 (#179) * refactor : StyleSettingBlockStrategy 이름 수정 및 공백 제거 (#179) * refactor : processWallInfoBlock, processStyleSettingBlock 메서드 분리 (#179) - save 메서드 내 WallInfoBlock 저장 로직을 processWallInfoBlock 메서드로 분리 - save 메서드 내 saveStyleSettingBlock 정보 블록 저장 로직을 processStyleSettingBlock 메서드로 분리 * refactor : 변수 위치 변경 및 Style Setting 문자열을 BlockType Enum에서 가져오도록 변경 (#179) * refactor : ResponseEntity 반환 형식을 ApiResponse로 변경 (#179) * refactor : saveSpaceWall 메서드 분리 (#179) - save 메서드 내 spaceWall 저장 로직을 saveSpaceWall 메서드로 분리 * refactor : 클래스명 변경 (#179) - BlockJsonHandler -> BlockJsonProcessor --- ...> BackgroundSettingStringSaveRequest.java} | 14 +- .../filedto/BackgroundSettingSaveRequest.java | 6 +- .../dto/request/BlockSettingSaveRequest.java | 10 +- .../service/BlockSettingService.java | 25 --- .../StyleSettingStringSaveRequest.java | 4 +- .../dto/request/ThemeSettingSaveRequest.java | 4 +- .../controller/SpaceWallController.java | 9 +- .../javajober/spaceWall/domain/BlockType.java | 26 +-- .../spaceWall/service/FileUploadService.java | 23 ++- .../spaceWall/service/SpaceWallService.java | 180 +++++------------- .../strategy/BlockJsonProcessor.java | 53 ++++++ .../strategy/BlockStrategyFactory.java | 51 +++++ .../spaceWall/strategy/BlockStrategyName.java | 11 ++ .../spaceWall/strategy/FixBlockStrategy.java | 9 + .../spaceWall/strategy/MoveBlockStrategy.java | 10 + .../strategy/impl/FileBlockStrategy.java | 43 +++++ .../strategy/impl/FreeBlockStrategy.java | 43 +++++ .../strategy/impl/ListBlockStrategy.java | 46 +++++ .../strategy/impl/SNSBlockStrategy.java | 45 +++++ .../impl/StyleSettingBlockStrategy.java | 65 +++++++ .../strategy/impl/TemplateBlockStrategy.java | 45 +++++ .../strategy/impl/WallInfoBlockStrategy.java | 36 ++++ 22 files changed, 558 insertions(+), 200 deletions(-) rename src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/dto/request/{BackgroundStringSaveRequest.java => BackgroundSettingStringSaveRequest.java} (50%) delete mode 100644 src/main/java/com/javajober/blocks/styleSetting/blockSetting/service/BlockSettingService.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/BlockStrategyFactory.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/BlockStrategyName.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/FixBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java create mode 100644 src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java diff --git a/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/dto/request/BackgroundStringSaveRequest.java b/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/dto/request/BackgroundSettingStringSaveRequest.java similarity index 50% rename from src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/dto/request/BackgroundStringSaveRequest.java rename to src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/dto/request/BackgroundSettingStringSaveRequest.java index 4cbfb21..a7a07be 100644 --- a/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/dto/request/BackgroundStringSaveRequest.java +++ b/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/dto/request/BackgroundSettingStringSaveRequest.java @@ -1,24 +1,26 @@ package com.javajober.blocks.styleSetting.backgroundSetting.dto.request; import com.javajober.blocks.styleSetting.backgroundSetting.domain.BackgroundSetting; + import lombok.Getter; @Getter -public class BackgroundStringSaveRequest { +public class BackgroundSettingStringSaveRequest { private String solidColor; private Boolean gradation; private String styleImgURL; - public BackgroundStringSaveRequest() { + public BackgroundSettingStringSaveRequest() { } - public BackgroundSetting toEntity() { + public static BackgroundSetting toEntity(final BackgroundSettingStringSaveRequest request) { + return BackgroundSetting.builder() - .solidColor(this.getSolidColor()) - .gradation(this.getGradation()) - .styleImageURL(this.getStyleImgURL()) + .solidColor(request.getSolidColor()) + .gradation(request.getGradation()) + .styleImageURL(request.getStyleImgURL()) .build(); } } \ No newline at end of file diff --git a/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/filedto/BackgroundSettingSaveRequest.java b/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/filedto/BackgroundSettingSaveRequest.java index 6a617b5..fb490dd 100644 --- a/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/filedto/BackgroundSettingSaveRequest.java +++ b/src/main/java/com/javajober/blocks/styleSetting/backgroundSetting/filedto/BackgroundSettingSaveRequest.java @@ -13,10 +13,10 @@ public BackgroundSettingSaveRequest() { } - public BackgroundSetting toEntity(final String styleImgName) { + public static BackgroundSetting toEntity(final BackgroundSettingSaveRequest request, final String styleImgName) { return BackgroundSetting.builder() - .solidColor(this.getSolidColor()) - .gradation(this.getGradation()) + .solidColor(request.getSolidColor()) + .gradation(request.getGradation()) .styleImageURL(styleImgName) .build(); } diff --git a/src/main/java/com/javajober/blocks/styleSetting/blockSetting/dto/request/BlockSettingSaveRequest.java b/src/main/java/com/javajober/blocks/styleSetting/blockSetting/dto/request/BlockSettingSaveRequest.java index ae95765..a2fb8c3 100644 --- a/src/main/java/com/javajober/blocks/styleSetting/blockSetting/dto/request/BlockSettingSaveRequest.java +++ b/src/main/java/com/javajober/blocks/styleSetting/blockSetting/dto/request/BlockSettingSaveRequest.java @@ -16,12 +16,12 @@ public BlockSettingSaveRequest(){ } - public BlockSetting toEntity() { + public static BlockSetting toEntity(final BlockSettingSaveRequest request) { return BlockSetting.builder() - .shape(this.getShape()) - .style(this.getStyle()) - .styleColor(this.getStyleColor()) - .gradation(this.getGradation()) + .shape(request.getShape()) + .style(request.getStyle()) + .styleColor(request.getStyleColor()) + .gradation(request.getGradation()) .build(); } } \ No newline at end of file diff --git a/src/main/java/com/javajober/blocks/styleSetting/blockSetting/service/BlockSettingService.java b/src/main/java/com/javajober/blocks/styleSetting/blockSetting/service/BlockSettingService.java deleted file mode 100644 index 8fb1bb7..0000000 --- a/src/main/java/com/javajober/blocks/styleSetting/blockSetting/service/BlockSettingService.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.javajober.blocks.styleSetting.blockSetting.service; - -import com.javajober.blocks.styleSetting.blockSetting.dto.request.BlockSettingSaveRequest; -import com.javajober.blocks.styleSetting.blockSetting.repository.BlockSettingRepository; -import com.javajober.blocks.styleSetting.blockSetting.domain.BlockSetting; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -public class BlockSettingService { - - private final BlockSettingRepository blockSettingRepository; - - public BlockSettingService(final BlockSettingRepository blockSettingRepository) { - this.blockSettingRepository = blockSettingRepository; - } - - @Transactional - public void save(final BlockSettingSaveRequest saveRequest){ - - BlockSetting blockSetting = saveRequest.toEntity(); - - blockSettingRepository.save(blockSetting); - } -} \ No newline at end of file diff --git a/src/main/java/com/javajober/blocks/styleSetting/dto/request/StyleSettingStringSaveRequest.java b/src/main/java/com/javajober/blocks/styleSetting/dto/request/StyleSettingStringSaveRequest.java index 4742627..4bc9dc7 100644 --- a/src/main/java/com/javajober/blocks/styleSetting/dto/request/StyleSettingStringSaveRequest.java +++ b/src/main/java/com/javajober/blocks/styleSetting/dto/request/StyleSettingStringSaveRequest.java @@ -1,7 +1,7 @@ package com.javajober.blocks.styleSetting.dto.request; import com.javajober.blocks.styleSetting.backgroundSetting.domain.BackgroundSetting; -import com.javajober.blocks.styleSetting.backgroundSetting.dto.request.BackgroundStringSaveRequest; +import com.javajober.blocks.styleSetting.backgroundSetting.dto.request.BackgroundSettingStringSaveRequest; import com.javajober.blocks.styleSetting.blockSetting.domain.BlockSetting; import com.javajober.blocks.styleSetting.blockSetting.dto.request.BlockSettingSaveRequest; import com.javajober.blocks.styleSetting.domain.StyleSetting; @@ -12,7 +12,7 @@ @Getter public class StyleSettingStringSaveRequest { - private BackgroundStringSaveRequest backgroundSetting; + private BackgroundSettingStringSaveRequest backgroundSetting; private BlockSettingSaveRequest blockSetting; private ThemeSettingSaveRequest themeSetting; diff --git a/src/main/java/com/javajober/blocks/styleSetting/themeSetting/dto/request/ThemeSettingSaveRequest.java b/src/main/java/com/javajober/blocks/styleSetting/themeSetting/dto/request/ThemeSettingSaveRequest.java index 6a5fd89..f32b98e 100644 --- a/src/main/java/com/javajober/blocks/styleSetting/themeSetting/dto/request/ThemeSettingSaveRequest.java +++ b/src/main/java/com/javajober/blocks/styleSetting/themeSetting/dto/request/ThemeSettingSaveRequest.java @@ -13,9 +13,9 @@ public ThemeSettingSaveRequest(){ } - public ThemeSetting toEntity() { + public static ThemeSetting toEntity(ThemeSettingSaveRequest request) { return ThemeSetting.builder() - .theme(this.getTheme()) + .theme(request.getTheme()) .build(); } } \ No newline at end of file diff --git a/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java b/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java index 0a508e5..51a0114 100644 --- a/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java +++ b/src/main/java/com/javajober/spaceWall/controller/SpaceWallController.java @@ -34,12 +34,11 @@ public SpaceWallController(final SpaceWallService spaceWallService, final SpaceW } @PostMapping("/wall") - public ResponseEntity> save( - @RequestBody final SpaceWallStringRequest spaceWallRequest) { + public ResponseEntity> save(@RequestBody final SpaceWallStringRequest spaceWallRequest) { SpaceWallSaveResponse data = spaceWallService.save(spaceWallRequest, FlagType.SAVED); - return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.SPACE_WALL_SAVE_SUCCESS, data)); + return ApiResponse.response(ApiStatus.OK, "공유페이지 저장이 완료되었습니다.", data); } @PostMapping(path = "/wall-temporary") @@ -87,11 +86,11 @@ public ResponseEntity> findByShareURL(@P } @GetMapping("/wall/has-duplicate/{shareURL}") - public ResponseEntity> hasDuplicateShareURL (@PathVariable final String shareURL) { + public ResponseEntity> hasDuplicateShareURL (@PathVariable final String shareURL) { DuplicateURLResponse data = spaceWallFindService.hasDuplicateShareURL(shareURL); - return ResponseEntity.ok(ApiUtils.success(HttpStatus.OK, SuccessMessage.SUCCESS, data)); + return ApiResponse.response(ApiStatus.OK, "", data); } @PutMapping("/wall") diff --git a/src/main/java/com/javajober/spaceWall/domain/BlockType.java b/src/main/java/com/javajober/spaceWall/domain/BlockType.java index 84ec049..b9812f7 100644 --- a/src/main/java/com/javajober/spaceWall/domain/BlockType.java +++ b/src/main/java/com/javajober/spaceWall/domain/BlockType.java @@ -10,27 +10,29 @@ @Getter public enum BlockType { - WALL_INFO_BLOCK("wallInfoBlock", "공유페이지 소개 블록"), - LIST_BLOCK("listBlock", "리스트 블록"), - FREE_BLOCK("freeBlock", "자유 블록"), - TEMPLATE_BLOCK("templateBlock", "템플릿 블록"), - SNS_BLOCK("snsBlock", "소셜 블록"), - FILE_BLOCK("fileBlock", "파일 블록"), - STYLE_SETTING("styleSetting", "스타일 블록"), - EMPTY("empty", "없음"); + FILE_BLOCK("fileBlock", "파일 블록","FileBlockStrategy"), + FREE_BLOCK("freeBlock", "자유 블록", "FreeBlockStrategy"), + LIST_BLOCK("listBlock", "리스트 블록", "ListBlockStrategy"), + SNS_BLOCK("snsBlock", "소셜 블록", "SNSBlockStrategy"), + STYLE_SETTING("styleSetting","스타일 블록","StyleSettingBlockStrategy"), + TEMPLATE_BLOCK("templateBlock", "템플릿 블록", "TemplateBlockStrategy"), + WALL_INFO_BLOCK("wallInfoBlock", "공유페이지 소개 블록", "WallInfoBlockStrategy"), + EMPTY("empty","없음",""); private final String engTitle; private final String korTitle; + private final String strategyName; - BlockType(final String engTitle, final String korTitle) { + BlockType(String engTitle, String korTitle, String strategyName) { this.engTitle = engTitle; this.korTitle = korTitle; + this.strategyName = strategyName; } public static BlockType findBlockTypeByString(final String type) { return Arrays.stream(values()) - .filter(blockType -> blockType.getEngTitle().equals(type)) - .findAny() - .orElseThrow(() -> new ApplicationException(ApiStatus.INVALID_DATA,"유효하지 않은 블록 타입입니다")); + .filter(blockType -> blockType.getEngTitle().equals(type)) + .findAny() + .orElseThrow(() -> new ApplicationException(ApiStatus.INVALID_DATA, "유효하지 않은 블록 타입입니다.")); } } \ No newline at end of file diff --git a/src/main/java/com/javajober/spaceWall/service/FileUploadService.java b/src/main/java/com/javajober/spaceWall/service/FileUploadService.java index 5af0141..45c04aa 100644 --- a/src/main/java/com/javajober/spaceWall/service/FileUploadService.java +++ b/src/main/java/com/javajober/spaceWall/service/FileUploadService.java @@ -5,11 +5,16 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.javajober.blocks.styleSetting.backgroundSetting.domain.BackgroundSetting; +import com.javajober.blocks.styleSetting.backgroundSetting.dto.request.BackgroundSettingStringSaveRequest; +import com.javajober.blocks.styleSetting.backgroundSetting.filedto.BackgroundSettingSaveRequest; import com.javajober.blocks.styleSetting.backgroundSetting.filedto.BackgroundSettingUpdateRequest; import com.javajober.blocks.styleSetting.backgroundSetting.repository.BackgroundSettingRepository; import com.javajober.blocks.styleSetting.blockSetting.domain.BlockSetting; +import com.javajober.blocks.styleSetting.blockSetting.dto.request.BlockSettingSaveRequest; import com.javajober.blocks.styleSetting.blockSetting.dto.request.BlockSettingUpdateRequest; import com.javajober.blocks.styleSetting.blockSetting.repository.BlockSettingRepository; +import com.javajober.blocks.styleSetting.dto.request.StyleSettingStringSaveRequest; +import com.javajober.blocks.styleSetting.themeSetting.dto.request.ThemeSettingSaveRequest; import com.javajober.core.util.file.FileImageService; import com.javajober.blocks.fileBlock.domain.FileBlock; import com.javajober.blocks.fileBlock.filedto.FileBlockSaveRequest; @@ -320,19 +325,19 @@ private List saveListBlocks(final List subData) { return listBlockIds; } - private Long saveStyleSetting(final StyleSettingSaveRequest saveRequest, MultipartFile styleImgURL){ + private Long saveStyleSetting(final StyleSettingSaveRequest request, MultipartFile styleImgURL){ + BackgroundSettingSaveRequest backgroundRequest = request.getBackgroundSetting(); String styleImgName = fileImageService.uploadFile(styleImgURL); + BackgroundSetting backgroundSetting = backgroundSettingRepository.save(BackgroundSettingSaveRequest.toEntity(backgroundRequest, styleImgName)); - BackgroundSetting savedBackgroundSetting = backgroundSettingRepository.save(saveRequest.getBackgroundSetting().toEntity(styleImgName)); - BlockSetting savedBlockSetting = blockSettingRepository.save(saveRequest.getBlockSetting().toEntity()); - ThemeSetting savedThemeSetting = themeSettingRepository.save(saveRequest.getThemeSetting().toEntity()); + BlockSettingSaveRequest blockSettingRequest = request.getBlockSetting(); + BlockSetting blockSetting = blockSettingRepository.save(BlockSettingSaveRequest.toEntity(blockSettingRequest)); - StyleSetting styleSetting = StyleSetting.builder() - .backgroundSetting(savedBackgroundSetting) - .blockSetting(savedBlockSetting) - .themeSetting(savedThemeSetting) - .build(); + ThemeSettingSaveRequest themeSettingRequest = request.getThemeSetting(); + ThemeSetting themeSetting = themeSettingRepository.save(ThemeSettingSaveRequest.toEntity(themeSettingRequest)); + + StyleSetting styleSetting = request.toEntity(backgroundSetting, blockSetting, themeSetting); return styleSettingRepository.save(styleSetting).getId(); } diff --git a/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java b/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java index 3ec6cf3..0693f62 100644 --- a/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java +++ b/src/main/java/com/javajober/spaceWall/service/SpaceWallService.java @@ -7,7 +7,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.javajober.blocks.styleSetting.backgroundSetting.dto.request.BackgroundStringUpdateRequest; import com.javajober.blocks.styleSetting.blockSetting.dto.request.BlockSettingUpdateRequest; -import com.javajober.blocks.fileBlock.dto.request.FileBlockStringSaveRequest; import com.javajober.blocks.fileBlock.dto.request.FileBlockStringUpdateRequest; import com.javajober.blocks.freeBlock.dto.request.FreeBlockUpdateRequest; import com.javajober.blocks.listBlock.dto.request.ListBlockUpdateRequest; @@ -19,10 +18,8 @@ import com.javajober.blocks.fileBlock.domain.FileBlock; import com.javajober.blocks.fileBlock.repository.FileBlockRepository; import com.javajober.blocks.freeBlock.domain.FreeBlock; -import com.javajober.blocks.freeBlock.dto.request.FreeBlockSaveRequest; import com.javajober.blocks.freeBlock.repository.FreeBlockRepository; import com.javajober.blocks.listBlock.domain.ListBlock; -import com.javajober.blocks.listBlock.dto.request.ListBlockSaveRequest; import com.javajober.blocks.listBlock.repository.ListBlockRepository; import com.javajober.member.domain.Member; import com.javajober.member.repository.MemberRepository; @@ -32,7 +29,6 @@ import com.javajober.spaceWall.dto.response.SpaceWallSaveResponse; import com.javajober.spaceWall.filedto.SpaceWallSaveRequest; import com.javajober.blocks.styleSetting.domain.StyleSetting; -import com.javajober.blocks.styleSetting.dto.request.StyleSettingStringSaveRequest; import com.javajober.blocks.styleSetting.dto.request.StyleSettingStringUpdateRequest; import com.javajober.blocks.templateBlock.dto.request.TemplateBlockUpdateRequest; import com.javajober.blocks.styleSetting.themeSetting.domain.ThemeSetting; @@ -42,7 +38,6 @@ import com.javajober.blocks.styleSetting.themeSetting.dto.request.ThemeSettingUpdateRequest; import com.javajober.blocks.styleSetting.themeSetting.repository.ThemeSettingRepository; import com.javajober.blocks.snsBlock.domain.SNSBlock; -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.domain.FlagType; @@ -50,19 +45,20 @@ import com.javajober.spaceWall.spaceWallCategory.domain.SpaceWallCategoryType; import com.javajober.spaceWall.repository.SpaceWallRepository; import com.javajober.blocks.templateBlock.domain.TemplateBlock; -import com.javajober.blocks.templateBlock.dto.request.TemplateBlockSaveRequest; import com.javajober.blocks.templateBlock.repository.TemplateBlockRepository; import com.javajober.blocks.wallInfoBlock.domain.WallInfoBlock; -import com.javajober.blocks.wallInfoBlock.dto.request.WallInfoBlockStringSaveRequest; import com.javajober.blocks.wallInfoBlock.dto.request.WallInfoBlockStringUpdateRequest; import com.javajober.blocks.wallInfoBlock.repository.WallInfoBlockRepository; +import com.javajober.spaceWall.strategy.BlockJsonProcessor; +import com.javajober.spaceWall.strategy.BlockStrategyFactory; +import com.javajober.spaceWall.strategy.FixBlockStrategy; +import com.javajober.spaceWall.strategy.MoveBlockStrategy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @Service @@ -81,6 +77,8 @@ public class SpaceWallService { private final ThemeSettingRepository themeSettingRepository; private final MemberRepository memberRepository; private final AddSpaceRepository addSpaceRepository; + private final BlockStrategyFactory blockStrategyFactory; + private final BlockJsonProcessor blockJsonProcessor; public SpaceWallService(final SpaceWallRepository spaceWallRepository, final SNSBlockRepository snsBlockRepository, final FreeBlockRepository freeBlockRepository, final TemplateBlockRepository templateBlockRepository, @@ -88,7 +86,8 @@ public SpaceWallService(final SpaceWallRepository spaceWallRepository, final SNS final ListBlockRepository listBlockRepository, final StyleSettingRepository styleSettingRepository, final BackgroundSettingRepository backgroundSettingRepository, final BlockSettingRepository blockSettingRepository, final ThemeSettingRepository themeSettingRepository, final MemberRepository memberRepository, - final AddSpaceRepository addSpaceRepository) { + final AddSpaceRepository addSpaceRepository, final BlockStrategyFactory blockStrategyFactory, + final BlockJsonProcessor blockJsonProcessor) { this.spaceWallRepository = spaceWallRepository; this.snsBlockRepository = snsBlockRepository; @@ -103,6 +102,8 @@ public SpaceWallService(final SpaceWallRepository spaceWallRepository, final SNS this.themeSettingRepository = themeSettingRepository; this.memberRepository = memberRepository; this.addSpaceRepository = addSpaceRepository; + this.blockStrategyFactory = blockStrategyFactory; + this.blockJsonProcessor = blockJsonProcessor; } @Transactional @@ -112,76 +113,61 @@ public SpaceWallSaveResponse save(final SpaceWallStringRequest spaceWallRequest, AddSpace addSpace = addSpaceRepository.findAddSpace(spaceWallRequest.getData().getSpaceId()); Member member = memberRepository.findMember(spaceWallRequest.getData().getMemberId()); + DataStringSaveRequest data = spaceWallRequest.getData(); + ArrayNode blockInfoArray = blockJsonProcessor.createArrayNode(); + processWallInfoBlock(data, blockInfoArray); + Long blocksPosition = 2L; AtomicLong blocksPositionCounter = new AtomicLong(blocksPosition); - ObjectMapper jsonMapper = new ObjectMapper(); - ArrayNode blockInfoArray = jsonMapper.createArrayNode(); - AtomicInteger i = new AtomicInteger(); - - WallInfoBlockStringSaveRequest wallInfoBlockStringSaveRequest = spaceWallRequest.getData().getWallInfoBlock(); - Long wallInfoBlock = saveWallInfoBlock(wallInfoBlockStringSaveRequest); - String wallInfoBlockType = BlockType.WALL_INFO_BLOCK.getEngTitle(); - Long blockStartPosition = 1L; - addBlockToJsonArray(blockInfoArray, jsonMapper, blockStartPosition, wallInfoBlockType, wallInfoBlock); spaceWallRequest.getData().getBlocks().forEach(block -> { + BlockType blockType = BlockType.findBlockTypeByString(block.getBlockType()); Long position = blocksPositionCounter.getAndIncrement(); - switch (blockType) { - case FREE_BLOCK: - List freeBlockRequests = jsonMapper.convertValue(block.getSubData(), - new TypeReference>() { - }); - List freeBlockIds = saveFreeBlocks(freeBlockRequests); - freeBlockIds.forEach(freeBlockId -> addBlockInfoToArray(blockInfoArray, jsonMapper, blockType, position, freeBlockId, block)); - break; - case SNS_BLOCK: - List snsBlockSaveRequests = jsonMapper.convertValue(block.getSubData(), - new TypeReference>() { - }); - List snsBlockIds = saveSnsBlocks(snsBlockSaveRequests); - snsBlockIds.forEach(snsBlockId -> addBlockInfoToArray(blockInfoArray, jsonMapper, blockType, position, snsBlockId, block)); - break; - case TEMPLATE_BLOCK: - List templateBlockSaveRequests = jsonMapper.convertValue(block.getSubData(), - new TypeReference>() { - }); - List templateBlockIds = saveTemplateBlocks(templateBlockSaveRequests); - templateBlockIds.forEach(templateBlockId -> addBlockInfoToArray(blockInfoArray, jsonMapper, blockType, position, templateBlockId, block)); - break; - case FILE_BLOCK: - List fileBlockSaveRequests = jsonMapper.convertValue(block.getSubData(), - new TypeReference>() { - }); - List fileBlockIds = saveFileBlocks(fileBlockSaveRequests); - fileBlockIds.forEach(templateBlockId -> addBlockInfoToArray(blockInfoArray, jsonMapper, blockType, position, templateBlockId, block)); - break; - case LIST_BLOCK: - List listBlockRequests = jsonMapper.convertValue(block.getSubData(), - new TypeReference>() { - }); - List listBlockIds = saveListBlocks(listBlockRequests); - listBlockIds.forEach(listBlockId -> addBlockInfoToArray(blockInfoArray, jsonMapper, blockType, position, listBlockId, block)); - } + + String strategyName = blockType.getStrategyName(); + MoveBlockStrategy blockProcessingStrategy = blockStrategyFactory.findMoveBlockStrategy(strategyName); + + List blockIds = blockProcessingStrategy.saveBlocks(block.getSubData()); + blockIds.forEach(blockId -> blockJsonProcessor.addBlockInfoToArray(blockInfoArray, position, blockId, block)); }); - StyleSettingStringSaveRequest styleSettingStringSaveRequest = spaceWallRequest.getData().getStyleSetting(); - Long styleSetting = saveStyleSetting(styleSettingStringSaveRequest); - String styleSettingString = "styleSetting"; + processStyleSettingBlock(data, blockInfoArray, blocksPositionCounter); + + String shareURL = spaceWallRequest.getData().getShareURL(); + Long spaceWallId = saveSpaceWall(spaceWallCategoryType, member, addSpace, shareURL, flagType, blockInfoArray); + + return new SpaceWallSaveResponse(spaceWallId); + } + + private void processWallInfoBlock(DataStringSaveRequest data, ArrayNode blockInfoArray) { + String wallInfoBlockStrategyName = BlockType.WALL_INFO_BLOCK.getStrategyName(); + FixBlockStrategy wallInfoBlockStrategy = blockStrategyFactory.findFixBlockStrategy(wallInfoBlockStrategyName); + Long wallInfoBlockId = wallInfoBlockStrategy.saveBlocks(data); + String wallInfoBlockType = BlockType.WALL_INFO_BLOCK.getEngTitle(); + Long blockStartPosition = 1L; + blockJsonProcessor.addBlockToJsonArray(blockInfoArray, blockStartPosition, wallInfoBlockType, wallInfoBlockId); + } + + private void processStyleSettingBlock(DataStringSaveRequest data, ArrayNode blockInfoArray, AtomicLong blocksPositionCounter) { + String styleSettingBlockStrategyName = BlockType.STYLE_SETTING.getStrategyName(); + FixBlockStrategy styleSettingBlockStrategy = blockStrategyFactory.findFixBlockStrategy(styleSettingBlockStrategyName); + Long styleSettingBlockId = styleSettingBlockStrategy.saveBlocks(data); + String styleSettingString = BlockType.STYLE_SETTING.getEngTitle(); Long stylePosition = blocksPositionCounter.getAndIncrement(); - addBlockToJsonArray(blockInfoArray, jsonMapper, stylePosition, styleSettingString, styleSetting); + blockJsonProcessor.addBlockToJsonArray(blockInfoArray, stylePosition, styleSettingString, styleSettingBlockId); + } + + private Long saveSpaceWall(SpaceWallCategoryType spaceWallCategoryType, Member member, AddSpace addSpace, String shareURL, FlagType flagType, ArrayNode blockInfoArray) { String blockInfoArrayAsString = blockInfoArray.toString(); - String shareURL = spaceWallRequest.getData().getShareURL(); SpaceWall spaceWall = SpaceWallSaveRequest.toEntity(spaceWallCategoryType, member, addSpace, shareURL, flagType, blockInfoArrayAsString); - Long spaceWallId = spaceWallRepository.save(spaceWall).getId(); - - return new SpaceWallSaveResponse(spaceWallId); + return spaceWallRepository.save(spaceWall).getId(); } @Transactional - public SpaceWallSaveResponse update(final SpaceWallStringUpdateRequest spaceWallUpdateRequest, final FlagType flagType){ + public SpaceWallSaveResponse update(final SpaceWallStringUpdateRequest spaceWallUpdateRequest, final FlagType flagType) { DataStringUpdateRequest dataUpdateRequest = spaceWallUpdateRequest.getData(); @@ -250,74 +236,6 @@ public SpaceWallSaveResponse update(final SpaceWallStringUpdateRequest spaceWall return new SpaceWallSaveResponse(spaceWallId); } - private Long saveWallInfoBlock(final WallInfoBlockStringSaveRequest wallInfoBlockRequest) { - - WallInfoBlock wallInfoBlock = WallInfoBlockStringSaveRequest.toEntity(wallInfoBlockRequest); - - return wallInfoBlockRepository.save(wallInfoBlock).getId(); - } - - private List saveFreeBlocks(final List subData) { - - List freeBlockIds = new ArrayList<>(); - subData.forEach(block -> { - FreeBlock freeBlock = FreeBlockSaveRequest.toEntity(block); - freeBlockIds.add(freeBlockRepository.save(freeBlock).getId()); - }); - return freeBlockIds; - } - - private List saveSnsBlocks(final List subData) { - - List snsBlockIds = new ArrayList<>(); - - subData.forEach(block -> { - SNSBlock snsBlock = SNSBlockSaveRequest.toEntity(block); - snsBlockIds.add(snsBlockRepository.save(snsBlock).getId()); - }); - return snsBlockIds; - } - - private List saveTemplateBlocks(final List subData){ - - List templateBlockIds = new ArrayList<>(); - - subData.forEach(block -> { - TemplateBlock templateBlock = TemplateBlockSaveRequest.toEntity(block); - templateBlockIds.add(templateBlockRepository.save(templateBlock).getId()); - }); - return templateBlockIds; - } - - private List saveFileBlocks(final List subData) { - - List fileBlockIds = new ArrayList<>(); - subData.forEach(block -> { - FileBlock fileBlock = FileBlockStringSaveRequest.toEntity(block); - fileBlockIds.add(fileBlockRepository.save(fileBlock).getId()); - }); - return fileBlockIds; - } - - private List saveListBlocks(final List subData) { - - List listBlockIds = new ArrayList<>(); - subData.forEach(block -> { - ListBlock listBlock = ListBlockSaveRequest.toEntity(block); - listBlockIds.add(listBlockRepository.save(listBlock).getId()); - }); - return listBlockIds; - } - - private Long saveStyleSetting(final StyleSettingStringSaveRequest saveRequest){ - - BackgroundSetting backgroundSetting = backgroundSettingRepository.save(saveRequest.getBackgroundSetting().toEntity()); - BlockSetting blockSetting = blockSettingRepository.save(saveRequest.getBlockSetting().toEntity()); - ThemeSetting themeSetting = themeSettingRepository.save(saveRequest.getThemeSetting().toEntity()); - StyleSetting styleSetting =saveRequest.toEntity(backgroundSetting, blockSetting, themeSetting); - - return styleSettingRepository.save(styleSetting).getId(); - } private Long updateWallInfoBlock(final WallInfoBlockStringUpdateRequest wallInfoBlockRequest) { diff --git a/src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java b/src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java new file mode 100644 index 0000000..ac27052 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/BlockJsonProcessor.java @@ -0,0 +1,53 @@ +package com.javajober.spaceWall.strategy; + +import org.springframework.stereotype.Component; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.javajober.spaceWall.dto.request.BlockSaveRequest; + +@Component +public class BlockJsonProcessor { + private final ObjectMapper jsonMapper; + + public BlockJsonProcessor(final ObjectMapper jsonMapper) { + this.jsonMapper = jsonMapper; + } + + public ArrayNode createArrayNode() { + return jsonMapper.createArrayNode(); + } + + public T convertValue(final Object fromValue, final Class toValueType) { + return jsonMapper.convertValue(fromValue, toValueType); + } + + public void addBlockInfoToArray(final ArrayNode blockInfoArray, final Long position, final Long blockId, final BlockSaveRequest block) { + + String currentBlockTypeTitle = block.getBlockType(); + String blockUUID = block.getBlockUUID(); + + ObjectNode blockInfoObject = jsonMapper.createObjectNode(); + + blockInfoObject.put("position", position); + blockInfoObject.put("block_type", currentBlockTypeTitle); + blockInfoObject.put("block_id", blockId); + blockInfoObject.put("block_uuid", blockUUID); + + blockInfoArray.add(blockInfoObject); + } + + + public void addBlockToJsonArray(final ArrayNode blockInfoArray, final Long position, final String blockType, final Long blockId) { + + ObjectNode blockInfoObject = jsonMapper.createObjectNode(); + + blockInfoObject.put("position", position); + blockInfoObject.put("block_type", blockType); + blockInfoObject.put("block_id", blockId); + blockInfoObject.put("block_uuid", ""); + + blockInfoArray.add(blockInfoObject); + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/BlockStrategyFactory.java b/src/main/java/com/javajober/spaceWall/strategy/BlockStrategyFactory.java new file mode 100644 index 0000000..7a8c18c --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/BlockStrategyFactory.java @@ -0,0 +1,51 @@ +package com.javajober.spaceWall.strategy; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.springframework.stereotype.Component; + +@Component +public class BlockStrategyFactory { + + private final Map moveBlockStrategies; + private final Map fixBlockStrategies; + + + public BlockStrategyFactory(Set moveBlockStrategySet, Set fixBlockStrategySet) { + initializeMoveBlockStrategies(moveBlockStrategySet); + this.moveBlockStrategies = initializeMoveBlockStrategies(moveBlockStrategySet); + this.fixBlockStrategies = initializeFixBlockStrategies(fixBlockStrategySet); + } + + public MoveBlockStrategy findMoveBlockStrategy(String moveBlockStrategyName) { + return moveBlockStrategies.get(moveBlockStrategyName); + } + + public FixBlockStrategy findFixBlockStrategy(String fixBlockStrategyName) { + return fixBlockStrategies.get(fixBlockStrategyName); + } + + + private Map initializeMoveBlockStrategies(Set StrategySet) { + + Map strategies = new HashMap<>(); + + StrategySet.forEach( + strategy -> strategies.put(strategy.getStrategyName(), strategy)); + + return strategies; + } + + private Map initializeFixBlockStrategies(Set StrategySet) { + + Map strategies = new HashMap<>(); + + + StrategySet.forEach( + strategy -> strategies.put(strategy.getStrategyName(), strategy)); + + return strategies; + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/BlockStrategyName.java b/src/main/java/com/javajober/spaceWall/strategy/BlockStrategyName.java new file mode 100644 index 0000000..13f5978 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/BlockStrategyName.java @@ -0,0 +1,11 @@ +package com.javajober.spaceWall.strategy; + +public enum BlockStrategyName { + SNSBlockStrategy, + FreeBlockStrategy, + FileBlockStrategy, + TemplateBlockStrategy, + ListBlockStrategy, + WallInfoBlockStrategy, + StyleSettingBlockStrategy +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/FixBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/FixBlockStrategy.java new file mode 100644 index 0000000..eb965c9 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/FixBlockStrategy.java @@ -0,0 +1,9 @@ +package com.javajober.spaceWall.strategy; + +import com.javajober.spaceWall.dto.request.DataStringSaveRequest; + +public interface FixBlockStrategy { + Long saveBlocks(final DataStringSaveRequest data); + + String getStrategyName(); +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java new file mode 100644 index 0000000..da88476 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/MoveBlockStrategy.java @@ -0,0 +1,10 @@ +package com.javajober.spaceWall.strategy; + +import java.util.List; + +public interface MoveBlockStrategy { + List saveBlocks(final List subData); + + String getStrategyName(); +} + diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java new file mode 100644 index 0000000..79b5ef1 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/FileBlockStrategy.java @@ -0,0 +1,43 @@ +package com.javajober.spaceWall.strategy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.javajober.blocks.fileBlock.domain.FileBlock; +import com.javajober.blocks.fileBlock.dto.request.FileBlockStringSaveRequest; +import com.javajober.blocks.fileBlock.repository.FileBlockRepository; +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 final BlockJsonProcessor blockJsonProcessor; + private final FileBlockRepository fileBlockRepository; + + public FileBlockStrategy(BlockJsonProcessor blockJsonProcessor, FileBlockRepository fileBlockRepository) { + this.blockJsonProcessor = blockJsonProcessor; + this.fileBlockRepository = fileBlockRepository; + } + + @Override + public List saveBlocks(final List subData) { + + List fileBlockIds = new ArrayList<>(); + + subData.forEach(block -> { + FileBlockStringSaveRequest request = blockJsonProcessor.convertValue(block, FileBlockStringSaveRequest.class); + FileBlock fileBlock = FileBlockStringSaveRequest.toEntity(request); + fileBlockIds.add(fileBlockRepository.save(fileBlock).getId()); + }); + return fileBlockIds; + } + + @Override + public String getStrategyName() { + return BlockStrategyName.FileBlockStrategy.name(); + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java new file mode 100644 index 0000000..3963b98 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/FreeBlockStrategy.java @@ -0,0 +1,43 @@ +package com.javajober.spaceWall.strategy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.javajober.blocks.freeBlock.domain.FreeBlock; +import com.javajober.blocks.freeBlock.dto.request.FreeBlockSaveRequest; +import com.javajober.blocks.freeBlock.repository.FreeBlockRepository; +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 final BlockJsonProcessor blockJsonProcessor; + private final FreeBlockRepository freeBlockRepository; + + public FreeBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final FreeBlockRepository freeBlockRepository) { + this.blockJsonProcessor = blockJsonProcessor; + this.freeBlockRepository = freeBlockRepository; + } + + @Override + public List saveBlocks(final List subData) { + + List freeBlockIds = new ArrayList<>(); + + subData.forEach(block -> { + FreeBlockSaveRequest request = blockJsonProcessor.convertValue(block, FreeBlockSaveRequest.class); + FreeBlock freeBlock = FreeBlockSaveRequest.toEntity(request); + freeBlockIds.add(freeBlockRepository.save(freeBlock).getId()); + }); + + return freeBlockIds; + } + + @Override + public String getStrategyName() { + return BlockStrategyName.FreeBlockStrategy.name(); + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java new file mode 100644 index 0000000..0cd2eb6 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/ListBlockStrategy.java @@ -0,0 +1,46 @@ +package com.javajober.spaceWall.strategy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.javajober.blocks.listBlock.domain.ListBlock; +import com.javajober.blocks.listBlock.dto.request.ListBlockSaveRequest; +import com.javajober.blocks.listBlock.repository.ListBlockRepository; +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 final BlockJsonProcessor blockJsonProcessor; + private final ListBlockRepository listBlockRepository; + + + public ListBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final ListBlockRepository listBlockRepository) { + this.blockJsonProcessor = blockJsonProcessor; + this.listBlockRepository = listBlockRepository; + } + + + @Override + public List saveBlocks(final List subData) { + + List listBlockIds = new ArrayList<>(); + + subData.forEach(block -> { + ListBlockSaveRequest request = blockJsonProcessor.convertValue(block, ListBlockSaveRequest.class); + ListBlock listBlock = ListBlockSaveRequest.toEntity(request); + listBlockIds.add(listBlockRepository.save(listBlock).getId()); + }); + + return listBlockIds; + } + + @Override + public String getStrategyName() { + return BlockStrategyName.ListBlockStrategy.name(); + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java new file mode 100644 index 0000000..5ebf542 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/SNSBlockStrategy.java @@ -0,0 +1,45 @@ +package com.javajober.spaceWall.strategy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.javajober.blocks.snsBlock.domain.SNSBlock; +import com.javajober.blocks.snsBlock.dto.request.SNSBlockSaveRequest; +import com.javajober.blocks.snsBlock.repository.SNSBlockRepository; +import com.javajober.spaceWall.strategy.BlockJsonProcessor; +import com.javajober.spaceWall.strategy.BlockStrategyName; +import com.javajober.spaceWall.strategy.MoveBlockStrategy; + +import lombok.extern.slf4j.Slf4j; + +@Component +@Slf4j +public class SNSBlockStrategy implements MoveBlockStrategy { + + private final BlockJsonProcessor blockJsonProcessor; + private final SNSBlockRepository snsBlockRepository; + + public SNSBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final SNSBlockRepository snsBlockRepository) { + this.blockJsonProcessor = blockJsonProcessor; + this.snsBlockRepository = snsBlockRepository; + } + + @Override + public List saveBlocks(final List subData) { + List snsBlockIds = new ArrayList<>(); + + subData.forEach(block -> { + SNSBlockSaveRequest request = blockJsonProcessor.convertValue(block, SNSBlockSaveRequest.class); + SNSBlock snsBlock = SNSBlockSaveRequest.toEntity(request); + snsBlockIds.add(snsBlockRepository.save(snsBlock).getId()); + }); + return snsBlockIds; + } + + @Override + public String getStrategyName() { + return BlockStrategyName.SNSBlockStrategy.name(); + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingBlockStrategy.java new file mode 100644 index 0000000..831198d --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/StyleSettingBlockStrategy.java @@ -0,0 +1,65 @@ +package com.javajober.spaceWall.strategy.impl; + +import org.springframework.stereotype.Component; + +import com.javajober.blocks.styleSetting.backgroundSetting.domain.BackgroundSetting; +import com.javajober.blocks.styleSetting.backgroundSetting.dto.request.BackgroundSettingStringSaveRequest; +import com.javajober.blocks.styleSetting.backgroundSetting.repository.BackgroundSettingRepository; +import com.javajober.blocks.styleSetting.blockSetting.domain.BlockSetting; +import com.javajober.blocks.styleSetting.blockSetting.dto.request.BlockSettingSaveRequest; +import com.javajober.blocks.styleSetting.blockSetting.repository.BlockSettingRepository; +import com.javajober.blocks.styleSetting.domain.StyleSetting; +import com.javajober.blocks.styleSetting.dto.request.StyleSettingStringSaveRequest; +import com.javajober.blocks.styleSetting.repository.StyleSettingRepository; +import com.javajober.blocks.styleSetting.themeSetting.domain.ThemeSetting; +import com.javajober.blocks.styleSetting.themeSetting.dto.request.ThemeSettingSaveRequest; +import com.javajober.blocks.styleSetting.themeSetting.repository.ThemeSettingRepository; +import com.javajober.spaceWall.dto.request.DataStringSaveRequest; +import com.javajober.spaceWall.strategy.BlockStrategyName; +import com.javajober.spaceWall.strategy.FixBlockStrategy; + +@Component +public class StyleSettingBlockStrategy implements FixBlockStrategy { + + private final StyleSettingRepository styleSettingRepository; + private final BackgroundSettingRepository backgroundSettingRepository; + private final BlockSettingRepository blockSettingRepository; + private final ThemeSettingRepository themeSettingRepository; + + public StyleSettingBlockStrategy(final StyleSettingRepository styleSettingRepository, + final BackgroundSettingRepository backgroundSettingRepository, final BlockSettingRepository blockSettingRepository, + final ThemeSettingRepository themeSettingRepository) { + this.styleSettingRepository = styleSettingRepository; + this.backgroundSettingRepository = backgroundSettingRepository; + this.blockSettingRepository = blockSettingRepository; + this.themeSettingRepository = themeSettingRepository; + } + + @Override + public Long saveBlocks(final DataStringSaveRequest data) { + StyleSettingStringSaveRequest request = data.getStyleSetting(); + + return saveStyleSetting(request); + } + + private Long saveStyleSetting(final StyleSettingStringSaveRequest request){ + + BackgroundSettingStringSaveRequest backgroundRequest = request.getBackgroundSetting(); + BackgroundSetting backgroundSetting = backgroundSettingRepository.save(BackgroundSettingStringSaveRequest.toEntity(backgroundRequest)); + + BlockSettingSaveRequest blockSettingRequest = request.getBlockSetting(); + BlockSetting blockSetting = blockSettingRepository.save(BlockSettingSaveRequest.toEntity(blockSettingRequest)); + + ThemeSettingSaveRequest themeSettingRequest = request.getThemeSetting(); + ThemeSetting themeSetting = themeSettingRepository.save(ThemeSettingSaveRequest.toEntity(themeSettingRequest)); + + StyleSetting styleSetting = request.toEntity(backgroundSetting, blockSetting, themeSetting); + + return styleSettingRepository.save(styleSetting).getId(); + } + + @Override + public String getStrategyName() { + return BlockStrategyName.StyleSettingBlockStrategy.name(); + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java new file mode 100644 index 0000000..989c131 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/TemplateBlockStrategy.java @@ -0,0 +1,45 @@ +package com.javajober.spaceWall.strategy.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Component; + +import com.javajober.blocks.templateBlock.domain.TemplateBlock; +import com.javajober.blocks.templateBlock.dto.request.TemplateBlockSaveRequest; +import com.javajober.blocks.templateBlock.repository.TemplateBlockRepository; +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 final BlockJsonProcessor blockJsonProcessor; + private final TemplateBlockRepository templateBlockRepository; + + public TemplateBlockStrategy(final BlockJsonProcessor blockJsonProcessor, final TemplateBlockRepository templateBlockRepository) { + this.blockJsonProcessor = blockJsonProcessor; + this.templateBlockRepository = templateBlockRepository; + } + + + @Override + public List saveBlocks(final List subData) { + List templateBlockIds = new ArrayList<>(); + + subData.forEach(block -> { + TemplateBlockSaveRequest request = blockJsonProcessor.convertValue(block, TemplateBlockSaveRequest.class); + TemplateBlock templateBlock = TemplateBlockSaveRequest.toEntity(request); + templateBlockIds.add(templateBlockRepository.save(templateBlock).getId()); + }); + + return templateBlockIds; + } + + @Override + public String getStrategyName() { + return BlockStrategyName.TemplateBlockStrategy.name(); + } +} diff --git a/src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java b/src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java new file mode 100644 index 0000000..bd69f29 --- /dev/null +++ b/src/main/java/com/javajober/spaceWall/strategy/impl/WallInfoBlockStrategy.java @@ -0,0 +1,36 @@ +package com.javajober.spaceWall.strategy.impl; + +import org.springframework.stereotype.Component; + +import com.javajober.blocks.wallInfoBlock.domain.WallInfoBlock; +import com.javajober.blocks.wallInfoBlock.dto.request.WallInfoBlockStringSaveRequest; +import com.javajober.blocks.wallInfoBlock.repository.WallInfoBlockRepository; +import com.javajober.spaceWall.dto.request.DataStringSaveRequest; +import com.javajober.spaceWall.strategy.BlockStrategyName; +import com.javajober.spaceWall.strategy.FixBlockStrategy; + +@Component +public class WallInfoBlockStrategy implements FixBlockStrategy { + + private final WallInfoBlockRepository wallInfoBlockRepository; + + public WallInfoBlockStrategy(WallInfoBlockRepository wallInfoBlockRepository) { + this.wallInfoBlockRepository = wallInfoBlockRepository; + } + + @Override + public Long saveBlocks(DataStringSaveRequest data) { + WallInfoBlockStringSaveRequest request = data.getWallInfoBlock(); + return saveWallInfoBlock(request); + } + + @Override + public String getStrategyName() { + return BlockStrategyName.WallInfoBlockStrategy.name(); + } + + private Long saveWallInfoBlock(WallInfoBlockStringSaveRequest request) { + WallInfoBlock wallInfoBlock = WallInfoBlockStringSaveRequest.toEntity(request); + return wallInfoBlockRepository.save(wallInfoBlock).getId(); + } +}