-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 피드 작성 api 개발 및 S3 관련 설정 및 feed 패키지 구조 리펙토링 #85
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
46 commits
Select commit
Hold shift + click to select a range
67e5d16
[refactor] book 설명 길이 늘림 (#73)
hd0rable 747eb91
[refactor] feed 패키지 구조 변경 (#73)
hd0rable f98e7a7
[feat] s3 의존성 추가 (#73)
hd0rable 883c722
[feat] ContentJpaRepository (#73)
hd0rable 6b97af4
[remove] 더미 클래스 삭제 (#73)
hd0rable 79da645
[feat] 관련 에러 코드 추가 (#73)
hd0rable 1693ee6
[feat] feed<-> Content 양방향 매핑 관계 추가 (#73)
hd0rable d3b68f0
[feat] FeedCommandController 작성 (#73)
hd0rable 7e46961
[feat] FeedCommandPersistenceAdapter.save 작성 (#73)
hd0rable 05454e6
[feat] FeedCommandPort.save 작성 (#73)
hd0rable 3b37c05
[feat] FeedCreateCommand dto 작성 (#73)
hd0rable b207739
[feat] FeedCreateRequest dto 작성 (#73)
hd0rable 6d9b66c
[feat] FeedCreateResponse dto 작성 (#73)
hd0rable 3cce8d5
[feat] FeedCreateService.createFeed 작성 (#73)
hd0rable 402de3e
[feat] FeedCreateUseCase 작성 (#73)
hd0rable 667c450
[refactor] feed 패키지 구조 변경 (#73)
hd0rable 9c0a52b
[test] 피드 생성 통합 테스트 코드 작성 (#73)
hd0rable d81bf6e
[test] 피드 생성 컨트롤러 단위 테스트 코드 작성 (#73)
hd0rable 52e1da5
[test] 더미 테스트 데이터 함수 추가 (#73)
hd0rable 17ff089
[test] TestS3MockConfig 작성 (#73)
hd0rable 60bd35e
[feat] feed<-> Content 양방향 매핑 관계 추가 (#73)
hd0rable d703528
[feat] FeedTagJpaRepository 작성 (#73)
hd0rable c95dbb9
[feat] RoomCommandPersistenceAdapter.findCategoryByValue 작성 (#73)
hd0rable 0d276c5
[feat] RoomCommandPort.findCategoryByValue 작성 (#73)
hd0rable 31d35cd
[feat] S3 관련 설정 (#73)
hd0rable 4ba88cb
[feat] tag 생성 관련 함수 추가 (#73)
hd0rable d6079a9
[fix] tag 잘못된 매핑관계 수정 (#73)
hd0rable a9129ed
[feat] TagJpaRepository.findByValue (#73)
hd0rable e66b797
Merge remote-tracking branch 'origin/develop' into feat/#73-post-feed…
hd0rable fd0f795
Merge remote-tracking branch 'origin/develop' into feat/#73-post-feed…
hd0rable b8eeda6
[refactor] 머지 충돌 해결 (#73)
hd0rable 7e423a3
[refactor] 중복 저장 수정 (#73)
hd0rable 9d92c4c
[refactor] Content-Type 설정 버그 수정 (#73)
hd0rable c782833
[refactor] 비동기 예외 캐치 로직 수정 (#73)
hd0rable 02a5b18
[refactor] 예외 처리 및 메시지 형식 개선 (#73)
hd0rable d4ca2c8
[refactor] 저장 객체 사용 (#73)
hd0rable 8f56c25
[refactor] final 설정 (#73)
hd0rable a82e4f7
[test] 테스트코드 isbn 오류 수정 (#73)
hd0rable a7e4ca0
[refactor] 관련 에러코드 추가 (#73)
hd0rable b20c0bd
[refactor] feed 비즈니스 정책 책임 추가 (#73)
hd0rable e37df7d
[refactor] S3CommandPort 의존성 추가 리펙 (#73)
hd0rable aaf0560
[refactor] 메서드 명 리펙 (#73)
hd0rable c3213e1
[refactor] 태그리스트 생성시 NPE방지 (#73)
hd0rable ec9dde6
[test] 테스트코드 수정 (#73)
hd0rable 1fb1686
[test] 테스트코드 수정 (#73)
hd0rable 38171e3
[refactor] feed 도메인에서 MultipartFile 의존성 분리 (#73)
hd0rable 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package konkuk.thip.config; | ||
|
|
||
| import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
| import com.amazonaws.auth.BasicAWSCredentials; | ||
| import com.amazonaws.services.s3.AmazonS3Client; | ||
| import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class S3Config { | ||
|
|
||
| @Value("${cloud.aws.credentials.access-key}") | ||
| private String accessKey; | ||
|
|
||
| @Value("${cloud.aws.credentials.secret-key}") | ||
| private String secretKey; | ||
|
|
||
| @Value("${cloud.aws.region.static}") | ||
| private String region; | ||
|
hd0rable marked this conversation as resolved.
|
||
|
|
||
| @Bean | ||
| public AmazonS3Client amazonS3Client() { | ||
| //accessKey, secretKey, region 값으로 S3에 접근 가능한 객체 등록 | ||
| BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); | ||
|
|
||
| return (AmazonS3Client) AmazonS3ClientBuilder | ||
| .standard() | ||
| .withRegion(region) | ||
| .withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
| .build(); | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
src/main/java/konkuk/thip/feed/adapter/in/web/FeedCommandController.java
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 |
|---|---|---|
| @@ -1,10 +1,31 @@ | ||
| package konkuk.thip.feed.adapter.in.web; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import konkuk.thip.common.dto.BaseResponse; | ||
| import konkuk.thip.common.security.annotation.UserId; | ||
| import konkuk.thip.feed.adapter.in.web.request.FeedCreateRequest; | ||
| import konkuk.thip.feed.adapter.in.web.response.FeedCreateResponse; | ||
| import konkuk.thip.feed.application.port.in.FeedCreateUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestPart; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class FeedCommandController { | ||
|
|
||
| private final FeedCreateUseCase feedCreateUseCase; | ||
|
|
||
| @PostMapping("/feeds") | ||
| public BaseResponse<FeedCreateResponse> createFeed(@RequestPart("request") @Valid final FeedCreateRequest request, | ||
| @RequestPart(value = "images", required = false) final List<MultipartFile> images, | ||
| @UserId final Long userId) { | ||
| return BaseResponse.ok(FeedCreateResponse.of(feedCreateUseCase.createFeed(request.toCommand(userId),images))); | ||
| } | ||
| } |
7 changes: 0 additions & 7 deletions
7
src/main/java/konkuk/thip/feed/adapter/in/web/request/DummyRequest.java
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
src/main/java/konkuk/thip/feed/adapter/in/web/request/FeedCreateRequest.java
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,34 @@ | ||
| package konkuk.thip.feed.adapter.in.web.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import konkuk.thip.feed.application.port.in.dto.FeedCreateCommand; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public record FeedCreateRequest( | ||
|
|
||
| @NotBlank(message = "ISBN은 필수입니다.") | ||
| String isbn, | ||
|
hd0rable marked this conversation as resolved.
|
||
|
|
||
| @NotBlank(message = "콘텐츠 내용은 필수입니다.") | ||
| String contentBody, | ||
|
|
||
| @NotNull(message = "방 공개 설정 여부는 필수입니다.") | ||
| Boolean isPublic, | ||
|
|
||
| String category, | ||
|
|
||
| List<String> tagList | ||
| ) { | ||
| public FeedCreateCommand toCommand(Long userId) { | ||
| return new FeedCreateCommand( | ||
| isbn, | ||
| contentBody, | ||
| isPublic, | ||
| category, | ||
| tagList, | ||
| userId | ||
| ); | ||
| } | ||
| } | ||
7 changes: 0 additions & 7 deletions
7
src/main/java/konkuk/thip/feed/adapter/in/web/response/DummyResponse.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
src/main/java/konkuk/thip/feed/adapter/in/web/response/FeedCreateResponse.java
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 konkuk.thip.feed.adapter.in.web.response; | ||
|
|
||
| public record FeedCreateResponse(Long feedId) { | ||
| public static FeedCreateResponse of(Long feedId) { | ||
| return new FeedCreateResponse(feedId); | ||
| } | ||
| } |
3 changes: 2 additions & 1 deletion
3
...ost/adapter/out/jpa/ContentJpaEntity.java → ...eed/adapter/out/jpa/ContentJpaEntity.java
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
6 changes: 3 additions & 3 deletions
6
...ost/adapter/out/mapper/ContentMapper.java → ...eed/adapter/out/mapper/ContentMapper.java
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
79 changes: 77 additions & 2 deletions
79
src/main/java/konkuk/thip/feed/adapter/out/persistence/FeedCommandPersistenceAdapter.java
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 |
|---|---|---|
| @@ -1,15 +1,90 @@ | ||
| package konkuk.thip.feed.adapter.out.persistence; | ||
|
|
||
| import konkuk.thip.book.adapter.out.jpa.BookJpaEntity; | ||
| import konkuk.thip.book.adapter.out.persistence.repository.BookJpaRepository; | ||
| import konkuk.thip.common.exception.EntityNotFoundException; | ||
| import konkuk.thip.feed.adapter.out.jpa.ContentJpaEntity; | ||
| import konkuk.thip.feed.adapter.out.jpa.FeedJpaEntity; | ||
| import konkuk.thip.feed.adapter.out.jpa.FeedTagJpaEntity; | ||
| import konkuk.thip.feed.adapter.out.jpa.TagJpaEntity; | ||
| import konkuk.thip.feed.adapter.out.mapper.ContentMapper; | ||
| import konkuk.thip.feed.adapter.out.mapper.FeedMapper; | ||
| import konkuk.thip.feed.adapter.out.persistence.repository.FeedJpaRepository; | ||
| import konkuk.thip.feed.adapter.out.persistence.repository.FeedTag.FeedTagJpaRepository; | ||
| import konkuk.thip.feed.adapter.out.persistence.repository.Tag.TagJpaRepository; | ||
| import konkuk.thip.feed.application.port.out.FeedCommandPort; | ||
| import konkuk.thip.feed.domain.Feed; | ||
| import konkuk.thip.feed.domain.Tag; | ||
| import konkuk.thip.user.adapter.out.jpa.UserJpaEntity; | ||
| import konkuk.thip.user.adapter.out.persistence.repository.UserJpaRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.*; | ||
|
|
||
| @Slf4j | ||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class FeedCommandPersistenceAdapter implements FeedCommandPort { | ||
|
|
||
| private final FeedJpaRepository jpaRepository; | ||
| private final FeedMapper userMapper; | ||
| private final FeedJpaRepository feedJpaRepository; | ||
| private final UserJpaRepository userJpaRepository; | ||
| private final BookJpaRepository bookJpaRepository; | ||
| private final TagJpaRepository tagJpaRepository; | ||
| private final FeedTagJpaRepository feedTagJpaRepository; | ||
| private final FeedMapper feedMapper; | ||
| private final ContentMapper contentMapper; | ||
|
|
||
| @Override | ||
| public Long save(Feed feed) { | ||
|
|
||
| UserJpaEntity userJpaEntity = userJpaRepository.findById(feed.getCreatorId()).orElseThrow( | ||
| () -> new EntityNotFoundException(USER_NOT_FOUND) | ||
| ); | ||
| BookJpaEntity bookJpaEntity = bookJpaRepository.findById(feed.getTargetBookId()).orElseThrow( | ||
| () -> new EntityNotFoundException(BOOK_NOT_FOUND) | ||
| ); | ||
| FeedJpaEntity feedJpaEntity = feedMapper.toJpaEntity(feed,userJpaEntity,bookJpaEntity); | ||
|
|
||
| // Feed 먼저 영속화 → ID 생성 | ||
| FeedJpaEntity savedFeed = feedJpaRepository.save(feedJpaEntity); | ||
|
|
||
| // Content가 존재하면 ContentJpaEntity 생성 및 Feed 연관관계 설정 | ||
| saveContents(feed, savedFeed); | ||
| // 태그가 존재하면 태그 피드 매핑 생성 및 저장 | ||
| saveFeedTags(feed, savedFeed); | ||
|
|
||
| return savedFeed.getPostId(); | ||
| } | ||
|
|
||
| private void saveContents(Feed feed, FeedJpaEntity feedJpaEntity) { | ||
| if (feed.getContentList().isEmpty()) return; | ||
|
|
||
| List<ContentJpaEntity> contentJpaEntities = feed.getContentList().stream() | ||
| .map(content -> contentMapper.toJpaEntity(content, feedJpaEntity)) | ||
| .toList(); | ||
|
|
||
| contentJpaEntities.forEach(feedJpaEntity.getContentList()::add); | ||
| } | ||
|
|
||
| private void saveFeedTags(Feed feed, FeedJpaEntity feedJpaEntity) { | ||
| if (feed.getTagList().isEmpty()) return; | ||
|
|
||
| for (Tag tag : feed.getTagList()) { | ||
| TagJpaEntity tagJpaEntity = tagJpaRepository.findByValue(tag.getValue()) | ||
| .orElseThrow(() -> new EntityNotFoundException(TAG_NOT_FOUND)); | ||
|
|
||
| FeedTagJpaEntity feedTagJpaEntity = FeedTagJpaEntity.builder() | ||
| .feedJpaEntity(feedJpaEntity) | ||
| .tagJpaEntity(tagJpaEntity) | ||
| .build(); | ||
|
|
||
| feedTagJpaRepository.save(feedTagJpaEntity); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } |
1 change: 1 addition & 0 deletions
1
src/main/java/konkuk/thip/feed/adapter/out/persistence/FeedQueryPersistenceAdapter.java
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
28 changes: 28 additions & 0 deletions
28
src/main/java/konkuk/thip/feed/adapter/out/persistence/S3CommandPersistenceAdapter.java
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,28 @@ | ||
| package konkuk.thip.feed.adapter.out.persistence; | ||
|
|
||
| import konkuk.thip.feed.adapter.out.s3.S3Service; | ||
| import konkuk.thip.feed.application.port.out.S3CommandPort; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class S3CommandPersistenceAdapter implements S3CommandPort { | ||
|
|
||
| private final S3Service s3Service; | ||
|
|
||
| @Override | ||
| public List<String> uploadImages(List<MultipartFile> images) { | ||
| return images.stream() | ||
| .map(s3Service::uploadUserImageAndGetUrl) | ||
| .toList(); | ||
| } | ||
|
Comment on lines
+17
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 부분 실패 시나리오에 대한 에러 처리 개선이 필요합니다. 현재 구현에서 여러 이미지 중 일부가 업로드 실패할 경우 예외 처리가 부족합니다. 부분 실패 시 이미 업로드된 이미지들에 대한 정리 로직이 필요합니다. 다음과 같이 개선을 제안합니다: @Override
public List<String> uploadImages(List<MultipartFile> images) {
- return images.stream()
- .map(s3Service::uploadUserImageAndGetUrl)
- .toList();
+ List<String> uploadedUrls = new ArrayList<>();
+ try {
+ for (MultipartFile image : images) {
+ String url = s3Service.uploadUserImageAndGetUrl(image);
+ uploadedUrls.add(url);
+ }
+ return uploadedUrls;
+ } catch (Exception e) {
+ // 부분 업로드된 이미지들 정리
+ if (!uploadedUrls.isEmpty()) {
+ deleteImages(uploadedUrls);
+ }
+ throw e;
+ }
}🤖 Prompt for AI Agents |
||
|
|
||
| @Override | ||
| public void deleteImages(List<String> imageUrls) { | ||
| imageUrls.forEach(s3Service::deleteImageFromS3); | ||
| } | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
...ava/konkuk/thip/feed/adapter/out/persistence/repository/Content/ContentJpaRepository.java
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 konkuk.thip.feed.adapter.out.persistence.repository.Content; | ||
|
|
||
| import konkuk.thip.feed.adapter.out.jpa.ContentJpaEntity; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface ContentJpaRepository extends JpaRepository<ContentJpaEntity, Long>{ | ||
| } |
4 changes: 2 additions & 2 deletions
4
...er/out/persistence/FeedJpaRepository.java → ...istence/repository/FeedJpaRepository.java
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 |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package konkuk.thip.feed.adapter.out.persistence; | ||
| package konkuk.thip.feed.adapter.out.persistence.repository; | ||
|
|
||
| import konkuk.thip.feed.adapter.out.jpa.FeedJpaEntity; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface FeedJpaRepository extends JpaRepository<FeedJpaEntity, Long>, FeedQueryRepository{ | ||
| public interface FeedJpaRepository extends JpaRepository<FeedJpaEntity, Long>, FeedQueryRepository { | ||
| } |
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.