Skip to content

Commit

Permalink
Merge pull request #133 from CSID-DGU/backend/feature/crew
Browse files Browse the repository at this point in the history
BE: [fix] 갤러리 글 이미지 저장 문제 해결 #83
  • Loading branch information
Seoyoung2222 authored Dec 1, 2024
2 parents 201d43c + 51ff84e commit 98ffd29
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public class CrewPost extends BaseEntity {
@OneToMany(mappedBy = "crewPost")
private List<CrewPostComment> comments = new ArrayList<>();

@OneToMany(mappedBy = "crewPost")
@OneToMany(mappedBy = "crewPost", cascade = CascadeType.ALL, orphanRemoval = true)
@Builder.Default
private List<CrewPostImage> images = new ArrayList<>();

@OneToMany(mappedBy = "crewPost")
Expand All @@ -50,11 +51,8 @@ public int getLikeCount() {
return likes.size();
}

public void anddImage(CrewPostImage image) {
public void addImage(CrewPostImage image) {
this.images.add(image);
}

public void setImages(List<CrewPostImage> images) {
this.images = images;
image.setCrewPost(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ public class CrewPostImage extends BaseEntity {
@JoinColumn(name = "crew_post_id")
private CrewPost crewPost;

public void setCrewPost(CrewPost crewPost) {
this.crewPost = crewPost;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ public Long createGalleryPost(Long crewId, GalleryPostCreateRequestDto galleryPo
.board(CrewBoard.GALLERY)
.build();

List<CrewPostImage> crewPostImages = new ArrayList<>();
for (MultipartFile image : images) {
String imageUrl = s3Provider.uploadFile(image, S3RequestDto.builder()
.userId(currentUser.getId())
.dirName("gallery")
.build());
crewPostImages.add(CrewPostImage.builder()

CrewPostImage crewPostImage = CrewPostImage.builder()
.imageUrl(imageUrl)
.crewPost(galleryPost)
.build());
.build();

galleryPost.addImage(crewPostImage);
}

galleryPost.setImages(crewPostImages);
crewPostRepository.save(galleryPost);
return galleryPost.getId();
}
Expand Down

0 comments on commit 98ffd29

Please sign in to comment.