Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
67e5d16
[refactor] book 설명 길이 늘림 (#73)
hd0rable Jul 16, 2025
747eb91
[refactor] feed 패키지 구조 변경 (#73)
hd0rable Jul 16, 2025
f98e7a7
[feat] s3 의존성 추가 (#73)
hd0rable Jul 16, 2025
883c722
[feat] ContentJpaRepository (#73)
hd0rable Jul 16, 2025
6b97af4
[remove] 더미 클래스 삭제 (#73)
hd0rable Jul 16, 2025
79da645
[feat] 관련 에러 코드 추가 (#73)
hd0rable Jul 16, 2025
1693ee6
[feat] feed<-> Content 양방향 매핑 관계 추가 (#73)
hd0rable Jul 16, 2025
d3b68f0
[feat] FeedCommandController 작성 (#73)
hd0rable Jul 16, 2025
7e46961
[feat] FeedCommandPersistenceAdapter.save 작성 (#73)
hd0rable Jul 16, 2025
05454e6
[feat] FeedCommandPort.save 작성 (#73)
hd0rable Jul 16, 2025
3b37c05
[feat] FeedCreateCommand dto 작성 (#73)
hd0rable Jul 16, 2025
b207739
[feat] FeedCreateRequest dto 작성 (#73)
hd0rable Jul 16, 2025
6d9b66c
[feat] FeedCreateResponse dto 작성 (#73)
hd0rable Jul 16, 2025
3cce8d5
[feat] FeedCreateService.createFeed 작성 (#73)
hd0rable Jul 16, 2025
402de3e
[feat] FeedCreateUseCase 작성 (#73)
hd0rable Jul 16, 2025
667c450
[refactor] feed 패키지 구조 변경 (#73)
hd0rable Jul 16, 2025
9c0a52b
[test] 피드 생성 통합 테스트 코드 작성 (#73)
hd0rable Jul 16, 2025
d81bf6e
[test] 피드 생성 컨트롤러 단위 테스트 코드 작성 (#73)
hd0rable Jul 16, 2025
52e1da5
[test] 더미 테스트 데이터 함수 추가 (#73)
hd0rable Jul 16, 2025
17ff089
[test] TestS3MockConfig 작성 (#73)
hd0rable Jul 16, 2025
60bd35e
[feat] feed<-> Content 양방향 매핑 관계 추가 (#73)
hd0rable Jul 16, 2025
d703528
[feat] FeedTagJpaRepository 작성 (#73)
hd0rable Jul 16, 2025
c95dbb9
[feat] RoomCommandPersistenceAdapter.findCategoryByValue 작성 (#73)
hd0rable Jul 16, 2025
0d276c5
[feat] RoomCommandPort.findCategoryByValue 작성 (#73)
hd0rable Jul 16, 2025
31d35cd
[feat] S3 관련 설정 (#73)
hd0rable Jul 16, 2025
4ba88cb
[feat] tag 생성 관련 함수 추가 (#73)
hd0rable Jul 16, 2025
d6079a9
[fix] tag 잘못된 매핑관계 수정 (#73)
hd0rable Jul 16, 2025
a9129ed
[feat] TagJpaRepository.findByValue (#73)
hd0rable Jul 16, 2025
e66b797
Merge remote-tracking branch 'origin/develop' into feat/#73-post-feed…
hd0rable Jul 16, 2025
fd0f795
Merge remote-tracking branch 'origin/develop' into feat/#73-post-feed…
hd0rable Jul 16, 2025
b8eeda6
[refactor] 머지 충돌 해결 (#73)
hd0rable Jul 16, 2025
7e423a3
[refactor] 중복 저장 수정 (#73)
hd0rable Jul 16, 2025
9d92c4c
[refactor] Content-Type 설정 버그 수정 (#73)
hd0rable Jul 16, 2025
c782833
[refactor] 비동기 예외 캐치 로직 수정 (#73)
hd0rable Jul 16, 2025
02a5b18
[refactor] 예외 처리 및 메시지 형식 개선 (#73)
hd0rable Jul 16, 2025
d4ca2c8
[refactor] 저장 객체 사용 (#73)
hd0rable Jul 16, 2025
8f56c25
[refactor] final 설정 (#73)
hd0rable Jul 16, 2025
a82e4f7
[test] 테스트코드 isbn 오류 수정 (#73)
hd0rable Jul 16, 2025
a7e4ca0
[refactor] 관련 에러코드 추가 (#73)
hd0rable Jul 17, 2025
b20c0bd
[refactor] feed 비즈니스 정책 책임 추가 (#73)
hd0rable Jul 17, 2025
e37df7d
[refactor] S3CommandPort 의존성 추가 리펙 (#73)
hd0rable Jul 17, 2025
aaf0560
[refactor] 메서드 명 리펙 (#73)
hd0rable Jul 17, 2025
c3213e1
[refactor] 태그리스트 생성시 NPE방지 (#73)
hd0rable Jul 17, 2025
ec9dde6
[test] 테스트코드 수정 (#73)
hd0rable Jul 17, 2025
1fb1686
[test] 테스트코드 수정 (#73)
hd0rable Jul 17, 2025
38171e3
[refactor] feed 도메인에서 MultipartFile 의존성 분리 (#73)
hd0rable Jul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ dependencies {
annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

//s3 버킷
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
Comment thread
hd0rable marked this conversation as resolved.
}

def querydslDir = layout.buildDirectory.dir("generated/querydsl").get().asFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BookJpaEntity extends BaseJpaEntity {
@Column(name = "page_count")
private Integer pageCount;

@Column(length = 1000)
@Column(length = 3000)
Comment thread
hd0rable marked this conversation as resolved.
private String description;

public void changePageCount(Integer pageCount) {
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/konkuk/thip/common/exception/code/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,20 @@ public enum ErrorCode implements ResponseCode {
CATEGORY_NOT_MATCH(HttpStatus.BAD_REQUEST, 150001, "일치하는 카테고리 이름이 없습니다."),

/**
* 160000 : Feed error
* 160000 : Feed,Tag error
*/
FEED_NOT_FOUND(HttpStatus.NOT_FOUND, 160000, "존재하지 않는 FEED 입니다."),
TAG_NAME_NOT_MATCH(HttpStatus.BAD_REQUEST, 160001, "일치하는 태그 이름이 없습니다.")
TAG_NAME_NOT_MATCH(HttpStatus.BAD_REQUEST, 160001, "일치하는 태그 이름이 없습니다."),
TAG_NOT_FOUND(HttpStatus.NOT_FOUND, 160002, "존재하지 않는 TAG 입니다."),
INVALID_FEED_CREATE(HttpStatus.BAD_REQUEST, 160003, "유효하지 않은 FEED 생성 요청 입니다."),

/**
* 170000 : Image File error
*/
EMPTY_FILE_EXCEPTION(HttpStatus.BAD_REQUEST, 170001, "업로드하려는 이미지가 비어있습니다."),
EXCEPTION_ON_IMAGE_UPLOAD(HttpStatus.BAD_REQUEST, 170002, "이미지 업로드에 실패하였습니다."),
INVALID_FILE_EXTENSION(HttpStatus.BAD_REQUEST, 170003, "올바르지 않은 파일 형식입니다."),
IO_EXCEPTION_ON_IMAGE_DELETE(HttpStatus.BAD_REQUEST, 170004, "파일 삭제에 실패하였습니다.")
;

private final HttpStatus httpStatus;
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/konkuk/thip/config/S3Config.java
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;
Comment thread
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();
}
}
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)));
}
}

This file was deleted.

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,
Comment thread
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
);
}
}

This file was deleted.

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);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package konkuk.thip.post.adapter.out.jpa;
package konkuk.thip.feed.adapter.out.jpa;

import jakarta.persistence.*;
import konkuk.thip.common.entity.BaseJpaEntity;
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
import lombok.*;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Entity
@Table(name = "feeds")
@DiscriminatorValue("FEED")
Expand All @@ -27,11 +29,15 @@ public class FeedJpaEntity extends PostJpaEntity {
@JoinColumn(name = "book_id", nullable = false)
private BookJpaEntity bookJpaEntity;

@OneToMany(mappedBy = "postJpaEntity", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ContentJpaEntity> contentList;

@Builder
public FeedJpaEntity(String content, Integer likeCount, Integer commentCount, UserJpaEntity userJpaEntity, Boolean isPublic, int reportCount, BookJpaEntity bookJpaEntity) {
public FeedJpaEntity(String content, Integer likeCount, Integer commentCount, UserJpaEntity userJpaEntity, Boolean isPublic, int reportCount, BookJpaEntity bookJpaEntity, List<ContentJpaEntity> contentList) {
super(content, likeCount, commentCount, userJpaEntity);
this.isPublic = isPublic;
this.reportCount = reportCount;
this.bookJpaEntity = bookJpaEntity;
this.contentList = contentList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.persistence.*;
import konkuk.thip.common.entity.BaseJpaEntity;
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
import konkuk.thip.room.adapter.out.jpa.CategoryJpaEntity;
import lombok.*;

Expand All @@ -22,10 +21,6 @@ public class TagJpaEntity extends BaseJpaEntity {
@Column(name = "tag_value",length = 50, nullable = false)
private String value;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_id", nullable = false)
private PostJpaEntity postJpaEntity;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category_id", nullable = false)
private CategoryJpaEntity categoryJpaEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package konkuk.thip.post.adapter.out.mapper;
package konkuk.thip.feed.adapter.out.mapper;

import konkuk.thip.post.adapter.out.jpa.ContentJpaEntity;
import konkuk.thip.feed.adapter.out.jpa.ContentJpaEntity;
import konkuk.thip.feed.domain.Content;
import konkuk.thip.post.adapter.out.jpa.PostJpaEntity;
import konkuk.thip.post.domain.Content;
import org.springframework.stereotype.Component;

@Component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import konkuk.thip.user.adapter.out.jpa.UserJpaEntity;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
Expand All @@ -22,6 +23,7 @@ public FeedJpaEntity toJpaEntity(Feed feed, UserJpaEntity userJpaEntity, BookJpa
.likeCount(feed.getLikeCount())
.commentCount(feed.getCommentCount())
.bookJpaEntity(bookJpaEntity)
.contentList(new ArrayList<>())
.build();
}

Expand Down
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);
}
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package konkuk.thip.feed.adapter.out.persistence;

import konkuk.thip.feed.adapter.out.mapper.FeedMapper;
import konkuk.thip.feed.adapter.out.persistence.repository.FeedJpaRepository;
import konkuk.thip.feed.application.port.out.FeedQueryPort;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
Expand Down
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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
In
src/main/java/konkuk/thip/feed/adapter/out/persistence/S3CommandPersistenceAdapter.java
around lines 17 to 22, the uploadImages method lacks error handling for partial
failures during multiple image uploads. To fix this, wrap the upload calls in a
try-catch block, track successfully uploaded images, and if any upload fails,
delete the already uploaded images to clean up. Then rethrow or handle the
exception appropriately to ensure no orphaned uploads remain.


@Override
public void deleteImages(List<String> imageUrls) {
imageUrls.forEach(s3Service::deleteImageFromS3);
}
}
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>{
}
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 {
}
Loading