Skip to content

Commit 238927b

Browse files
committed
[fix] 커뮤니티 이미지 데이터가 빈 배열로 들어가는 문제 수정
1 parent 2635ce1 commit 238927b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/com/back/domain/post/post/entity/Post.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ public void updateContent(String content) {
115115
this.content = content;
116116
}
117117

118+
public void addImage(PostImage image) {
119+
if (this.images == null) {
120+
this.images = new ArrayList<>();
121+
}
122+
this.images.add(image);
123+
image.updatePost(this); // 양방향 관계 유지
124+
}
125+
126+
118127
public void updateImages(List<PostImage> images) {
119128
this.images.clear();
120129
for (PostImage i : images) {

src/main/java/com/back/domain/post/post/service/PostService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@ public PostResponseDto createPost(PostCreateRequestDto reqBody, List<MultipartFi
7979
String url = fileService.uploadFile(image);
8080

8181
PostImage postImage = PostImage.builder()
82-
.post(post)
8382
.fileName(image.getOriginalFilename())
8483
.url(url)
8584
.sortOrder(order++)
8685
.build();
8786

88-
postImageRepository.save(postImage);
87+
post.addImage(postImage);
8988
}
9089
}
9190

0 commit comments

Comments
 (0)