-
Notifications
You must be signed in to change notification settings - Fork 0
[Refactor] 응원 등록 이미지 트랜잭션 분리 및 보상 트랜잭션 적용 #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a02afb4
refactor: 이미지 이동 트랜잭션 분리, 파사드 도입
lvalentine6 b24f5e5
refactor: S3 보상트랜잭션 구현
lvalentine6 e2af28c
test: 응원 파사드 테스트 추가
lvalentine6 b352087
test: 응원, 문서 테스트 구조에 맞게 수정
lvalentine6 ab52d2d
test: 이미지 부분 성공 케이스 추가
lvalentine6 82b774f
refactor: 이미지가 없을때 조건 추가
lvalentine6 1ec8489
refactor: 불필요한 반환 제거 및 응답 메서드 추가
lvalentine6 325cf73
refactor: 반환 객체 수정
lvalentine6 3766b08
refactor: 예외 케이스 추가
lvalentine6 12ac1bc
test: 검증을 catch 블럭에서 분리
lvalentine6 06562cc
test: 예외 검증 수정
lvalentine6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package eatda.facade; | ||
|
|
||
| import eatda.domain.cheer.Cheer; | ||
| import eatda.domain.store.Store; | ||
|
|
||
| public record CheerCreationResult(Cheer cheer, Store store) { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package eatda.facade; | ||
|
|
||
| import eatda.client.file.FileClient; | ||
| import eatda.controller.cheer.CheerRegisterRequest; | ||
| import eatda.controller.cheer.CheerResponse; | ||
| import eatda.domain.ImageDomain; | ||
| import eatda.domain.cheer.Cheer; | ||
| import eatda.domain.store.StoreSearchResult; | ||
| import eatda.service.cheer.CheerService; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class CheerRegisterFacade { | ||
|
|
||
| private final CheerService cheerService; | ||
| private final FileClient fileClient; | ||
|
|
||
| public CheerResponse registerCheer(CheerRegisterRequest request, | ||
| StoreSearchResult result, | ||
| long memberId, | ||
| ImageDomain domain | ||
| ) { | ||
| CheerCreationResult creationResult = cheerService.createCheer(request, result, memberId); | ||
| Cheer cheer = creationResult.cheer(); | ||
|
|
||
| if (request.images() == null || request.images().isEmpty()) { | ||
| return cheerService.getCheerResponse(cheer.getId()); | ||
| } | ||
|
|
||
| List<String> permanentKeys = Collections.emptyList(); | ||
| try { | ||
| List<CheerRegisterRequest.UploadedImageDetail> sortedImages = sortImages(request.images()); | ||
| permanentKeys = moveImages(domain, cheer.getId(), sortedImages); | ||
| cheerService.saveCheerImages(cheer.getId(), sortedImages, permanentKeys); | ||
|
|
||
| } catch (Exception e) { | ||
| log.error("응원 등록 프로세스 실패. 롤백 수행. cheerId={}", cheer.getId(), e); | ||
|
|
||
| cheerService.deleteCheer(cheer.getId()); | ||
|
|
||
| if (!permanentKeys.isEmpty()) { | ||
| fileClient.deleteFiles(permanentKeys); | ||
| } | ||
| throw e; | ||
| } | ||
lvalentine6 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return cheerService.getCheerResponse(cheer.getId()); | ||
| } | ||
|
|
||
| private List<CheerRegisterRequest.UploadedImageDetail> sortImages( | ||
| List<CheerRegisterRequest.UploadedImageDetail> images) { | ||
| return images.stream() | ||
| .sorted(Comparator.comparingLong(CheerRegisterRequest.UploadedImageDetail::orderIndex)) | ||
| .toList(); | ||
| } | ||
|
|
||
| private List<String> moveImages(ImageDomain domain, | ||
| long cheerId, | ||
| List<CheerRegisterRequest.UploadedImageDetail> sortedImages) { | ||
| if (sortedImages.isEmpty()) { | ||
| return List.of(); | ||
| } | ||
|
|
||
| List<String> tempKeys = sortedImages.stream() | ||
| .map(CheerRegisterRequest.UploadedImageDetail::imageKey) | ||
| .toList(); | ||
| return fileClient.moveTempFilesToPermanent(domain.getName(), cheerId, tempKeys); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.