forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Backend/feat/#107
- Loading branch information
Showing
7 changed files
with
70 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,5 @@ public static class UpdateRecord { | |
@Schema(description = "STT") | ||
private final String stt; | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...end/moment/moment-server/core/src/main/java/com/moment/core/service/ImageFileService.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 |
---|---|---|
@@ -1,25 +1,51 @@ | ||
package com.moment.core.service; | ||
|
||
import com.moment.core.domain.cardView.CardView; | ||
import com.moment.core.domain.cardView.CardViewRepository; | ||
import com.moment.core.domain.imageFile.ImageFile; | ||
import com.moment.core.domain.imageFile.ImageFileRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ImageFileService { | ||
private final ImageFileRepository imageFileRepository; | ||
private final S3Service s3Service; | ||
private final CardViewRepository cardViewRepository; | ||
|
||
@Transactional | ||
public void deleteAll(CardView cardView) { | ||
List<ImageFile> imageFiles = imageFileRepository.findAllByCardView(cardView); | ||
for (ImageFile imageFile : imageFiles) { | ||
s3Service.deleteFile(imageFile.getFileName()); | ||
} | ||
imageFiles.forEach(imageFileRepository::delete); | ||
} | ||
|
||
@Transactional | ||
public void uploadAll(List<MultipartFile> imageFiles, Long cardViewId, Long userId) throws IOException { | ||
for (MultipartFile imageFile : imageFiles) { | ||
CardView cv = cardViewRepository.findById(cardViewId).orElseThrow(() -> new IllegalArgumentException("해당 카드뷰가 없습니다.")); | ||
String filename = UUID.randomUUID().toString(); | ||
String url = s3Service.uploadFile(imageFile, userId, filename, false); | ||
ImageFile image = ImageFile.builder() | ||
.fileUrl(url) | ||
.fileName(filename) | ||
.cardView(cv) | ||
.build(); | ||
imageFileRepository.save(image); | ||
} | ||
|
||
} | ||
|
||
} |
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