Skip to content

Commit

Permalink
shareURL 중복 검사 API 리팩토링 및 저장 예외 처리 로직 추가 완료 (#209)
Browse files Browse the repository at this point in the history
* refactor: FlagType이 'SAVED'인 항목만 검사하기 위해 'existsByShareURL' 메서드를 'existsByShareURLAndFlag' 메서드로 변경 (#208)

* feat :  existsByShareURLAndFlag' 메서드를 이용하여 중복 shareURL 검사 및 예외 처리 로직 추가 (#208)

* refactor : shareURL 중복 체크 로직을 'checkDuplicateShareURL' 메서드로 분리 (#208)
  • Loading branch information
dpdmstjs authored Oct 26, 2023
1 parent 02e2e53 commit 9698703
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface SpaceWallRepository extends Repository<SpaceWall, Long> {

SpaceWall save(final SpaceWall spaceWall);

boolean existsByShareURL(final String shareURL);
boolean existsByShareURLAndFlag(final String shareURL, final FlagType flagType);

boolean existsByAddSpaceId(final Long spaceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public SpaceWallSaveResponse save(final Long memberId, final SpaceWallSaveReques

validateAddSpaceId(addSpace.getId());

checkDuplicateShareURL(data.getShareURL());

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

ArrayNode blockInfoArray = blockJsonProcessor.createArrayNode();
Expand Down Expand Up @@ -175,6 +177,13 @@ private void validateAddSpaceId (final Long spaceId) {
}
}

private void checkDuplicateShareURL(final String shareURL) {
boolean existsShareURL = spaceWallRepository.existsByShareURLAndFlag(shareURL, FlagType.SAVED);
if (existsShareURL) {
throw new ApplicationException(ApiStatus.ALREADY_EXIST, "이미 사용중인 shareURL입니다.");
}
}

private void processWallInfoBlock(final MultipartFile backgroundImgURL, final MultipartFile wallInfoImgURL,
final DataSaveRequest data, final ArrayNode blockInfoArray,
final AtomicLong blocksPositionCounter) {
Expand All @@ -190,6 +199,7 @@ private void processWallInfoBlock(final MultipartFile backgroundImgURL, final Mu

private void processBlocks(final List<BlockSaveRequest<?>> blocks, final ArrayNode blockInfoArray,
final AtomicLong blocksPositionCounter, final List<MultipartFile> files) {

try {
AtomicInteger fileIndexCounter = new AtomicInteger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SpaceWallFindService(final SpaceWallRepository spaceWallRepository,
}

public DuplicateURLResponse hasDuplicateShareURL(final String shareURL) {
boolean hasDuplicateURL = spaceWallRepository.existsByShareURL(shareURL);
boolean hasDuplicateURL = spaceWallRepository.existsByShareURLAndFlag(shareURL, FlagType.SAVED);
return new DuplicateURLResponse(hasDuplicateURL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public SpaceWallSaveResponse save(final Long memberId, final SpaceWallStringRequ

validateAddSpaceId(addSpace.getId());

checkDuplicateShareURL(data.getShareURL());

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

ArrayNode blockInfoArray = blockJsonProcessor.createArrayNode();
Expand Down Expand Up @@ -158,6 +160,13 @@ private void validateAddSpaceId (final Long spaceId) {
}
}

private void checkDuplicateShareURL(final String shareURL) {
boolean existsShareURL = spaceWallRepository.existsByShareURLAndFlag(shareURL, FlagType.SAVED);
if (existsShareURL) {
throw new ApplicationException(ApiStatus.ALREADY_EXIST, "이미 사용중인 shareURL입니다.");
}
}

private void processWallInfoBlock(final DataStringSaveRequest data, final ArrayNode blockInfoArray, final AtomicLong blocksPositionCounter) {
String wallInfoBlockStrategyName = BlockType.WALL_INFO_BLOCK.getStrategyName();
FixBlockStrategy wallInfoBlockStrategy = blockStrategyFactory.findFixBlockStrategy(wallInfoBlockStrategyName);
Expand Down

0 comments on commit 9698703

Please sign in to comment.