-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from goalSetter09/10th-Kampus-BE-41
[FEATURE] 게시글 수정 기능 구현
- Loading branch information
Showing
12 changed files
with
159 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/cotato/kampus/domain/post/application/PostImageUpdater.java
This file contains 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,43 @@ | ||
package com.cotato.kampus.domain.post.application; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.cotato.kampus.domain.post.dao.PostPhotoRepository; | ||
import com.cotato.kampus.domain.post.domain.PostPhoto; | ||
import com.cotato.kampus.global.error.exception.ImageException; | ||
import com.cotato.kampus.global.util.s3.S3Uploader; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class PostImageUpdater { | ||
|
||
private final PostPhotoRepository postPhotoRepository; | ||
private final S3Uploader s3Uploader; | ||
private static final String POST_IMAGE_FOLDER = "post"; | ||
|
||
public void updatePostImages(Long postId, List<MultipartFile> images) throws ImageException { | ||
postPhotoRepository.deleteAllByPostId(postId); | ||
|
||
// 이미지가 있는 경우에만 업데이트 | ||
if (!images.isEmpty()) { | ||
List<String> postImages = s3Uploader.uploadFiles(images, POST_IMAGE_FOLDER); | ||
|
||
List<PostPhoto> postPhotos = postImages.stream() | ||
.map((postImage) -> PostPhoto.builder() | ||
.postId(postId) | ||
.photoUrl(postImage) | ||
.build() | ||
).toList(); | ||
|
||
postPhotoRepository.saveAll(postPhotos); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/cotato/kampus/domain/post/dto/request/PostUpdateRequest.java
This file contains 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,20 @@ | ||
package com.cotato.kampus.domain.post.dto.request; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.cotato.kampus.domain.common.enums.Anonymity; | ||
import com.cotato.kampus.domain.post.enums.PostCategory; | ||
|
||
import jakarta.annotation.Nullable; | ||
|
||
public record PostUpdateRequest( | ||
String title, | ||
String content, | ||
PostCategory postCategory, | ||
Anonymity anonymity, | ||
@Nullable | ||
List<MultipartFile> images | ||
) { | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/cotato/kampus/domain/post/enums/PostCategory.java
This file contains 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,5 @@ | ||
package com.cotato.kampus.domain.post.enums; | ||
|
||
public enum PostCategory { | ||
HOSPITAL, UNIVERSITY, RESTAURANT, ETC | ||
} |
2 changes: 1 addition & 1 deletion
2
...cotato/kampus/domain/post/PostStatus.java → .../kampus/domain/post/enums/PostStatus.java
This file contains 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