Skip to content

Commit

Permalink
공유페이지 저장 API 리팩토링 (Fastcampus-Final-Team3#180)
Browse files Browse the repository at this point in the history
* refactor : FixBlockStrategy 인터페이스 생성 (Fastcampus-Final-Team3#179)

* refactor : MoveBlockStrategy 인터페이스 생성 (Fastcampus-Final-Team3#179)

* refactor : 다양한 블록 전략 유형을 위한 BlockStrategyName 생성 (Fastcampus-Final-Team3#179)

* refactor : MoveBlockStrategy 인터페이스에 saveBlocks와 getStrategyName 메서드 정의 (Fastcampus-Final-Team3#179)

* refactor : FileBlockStrategy 클래스에 saveBlocks 메서드 구현 (Fastcampus-Final-Team3#179)

* refactor : FreeBlockStrategy 클래스에 saveBlocks 메서드 구현 (Fastcampus-Final-Team3#179)

* refactor : ListBlockStrategy 클래스에 saveBlocks 메서드 구현 (Fastcampus-Final-Team3#179)

* refactor : SNSBlockStrategy 클래스에 saveBlocks 메서드 구현 (Fastcampus-Final-Team3#179)

* refactor : TemplateBlockStrategy 클래스에 saveBlocks 메서드 구현 (Fastcampus-Final-Team3#179)

* refactor : BlockStrategyFactory 클래스 추가 및 구현 (Fastcampus-Final-Team3#179)

-  MoveBlockStrategy와 FixBlockStrategy 인터페이스를 구현하는 여러 전략들을 관리하고, 필요한 전략을 찾아 반환합니다.

* refactor : SpaceWallService save 메서드 리팩토링 (Fastcampus-Final-Team3#179)

* refactor : BlockJsonHandler 클래스 생성 및 ObjectMapper 활용 개선 (Fastcampus-Final-Team3#179)

* refactor : blockJsonHandler를 활용하여 메서드 변경 (Fastcampus-Final-Team3#179)

* refactor : blockJsonHandler를 활용하여 메서드 변경 및 매개변수 수정 (Fastcampus-Final-Team3#179)

* refactor : toEntity 메서드를 static factory method로 변경 (Fastcampus-Final-Team3#179)

* refactor : FixBlockStrategy 인터페이스에 saveBlocks와 getStrategyName 메서드 정의 (Fastcampus-Final-Team3#179)

* refactor : WallInfoBlockStrategy 클래스에 saveBlocks 메서드 구현 (Fastcampus-Final-Team3#179)

* refactor : StyleSettingBlockStrategy 클래스에 saveBlocks 메서드 구현 (Fastcampus-Final-Team3#179)

* refactor : FixBlockStrategy 전략 패턴을 활용한 SpaceWall 저장 메서드 변경 (Fastcampus-Final-Team3#179)

* refactor : 불필요한 클래스 및 import, 변수, 메서드 제거 (Fastcampus-Final-Team3#179)

* refactor : strategyName 필드 추가 (Fastcampus-Final-Team3#179)

* refactor : StyleSettingBlockStrategy 이름 수정 및 공백 제거 (Fastcampus-Final-Team3#179)

* refactor : processWallInfoBlock, processStyleSettingBlock 메서드 분리 (Fastcampus-Final-Team3#179)

- save 메서드 내 WallInfoBlock 저장 로직을 processWallInfoBlock 메서드로 분리
- save 메서드 내 saveStyleSettingBlock 정보 블록 저장 로직을 processStyleSettingBlock 메서드로 분리

* refactor : 변수 위치 변경 및 Style Setting 문자열을 BlockType Enum에서 가져오도록 변경 (Fastcampus-Final-Team3#179)

* refactor : ResponseEntity 반환 형식을 ApiResponse로 변경 (Fastcampus-Final-Team3#179)

* refactor : saveSpaceWall 메서드 분리 (Fastcampus-Final-Team3#179)

- save 메서드 내 spaceWall 저장 로직을 saveSpaceWall 메서드로 분리

* refactor : 클래스명 변경 (Fastcampus-Final-Team3#179)

- BlockJsonHandler -> BlockJsonProcessor
  • Loading branch information
dpdmstjs authored Oct 22, 2023
1 parent 2c9eddb commit 36afeca
Show file tree
Hide file tree
Showing 22 changed files with 558 additions and 200 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@
@Getter
public class StyleSettingStringSaveRequest {

private BackgroundStringSaveRequest backgroundSetting;
private BackgroundSettingStringSaveRequest backgroundSetting;
private BlockSettingSaveRequest blockSetting;
private ThemeSettingSaveRequest themeSetting;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ public SpaceWallController(final SpaceWallService spaceWallService, final SpaceW
}

@PostMapping("/wall")
public ResponseEntity<ApiUtils.ApiResponse<SpaceWallSaveResponse>> save(
@RequestBody final SpaceWallStringRequest spaceWallRequest) {
public ResponseEntity<ApiResponse.Response<SpaceWallSaveResponse>> 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")
Expand Down Expand Up @@ -87,11 +86,11 @@ public ResponseEntity<ApiResponse.Response<SpaceWallResponse>> findByShareURL(@P
}

@GetMapping("/wall/has-duplicate/{shareURL}")
public ResponseEntity<ApiUtils.ApiResponse<DuplicateURLResponse>> hasDuplicateShareURL (@PathVariable final String shareURL) {
public ResponseEntity<ApiResponse.Response<DuplicateURLResponse>> 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")
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/com/javajober/spaceWall/domain/BlockType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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, "유효하지 않은 블록 타입입니다."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -320,19 +325,19 @@ private List<Long> saveListBlocks(final List<ListBlockSaveRequest> 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();
}
Expand Down
Loading

0 comments on commit 36afeca

Please sign in to comment.