From 30697d03b0eee43d971592ea3f4a03848a886763 Mon Sep 17 00:00:00 2001 From: JongbeomLee623 Date: Mon, 2 Dec 2024 14:30:41 +0900 Subject: [PATCH] =?UTF-8?q?BE:=20[Fix]=20=EB=B6=80=EC=A0=95=ED=96=89?= =?UTF-8?q?=EC=9C=84=20=EC=98=81=EC=83=81=20=EC=A0=80=EC=9E=A5=20=ED=9B=84?= =?UTF-8?q?=20DB=EC=97=90=20=EB=A7=81=ED=81=AC=20=EC=A0=80=EC=9E=A5=20#6,?= =?UTF-8?q?=20#26?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fortune/eyesee/service/VideoService.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/VideoService.java b/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/VideoService.java index e30a045..733f805 100644 --- a/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/VideoService.java +++ b/src/backend/Eyesee/src/main/java/com/fortune/eyesee/service/VideoService.java @@ -2,6 +2,8 @@ import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.model.ObjectMetadata; +import com.fortune.eyesee.entity.VideoRecording; +import com.fortune.eyesee.repository.VideoRecordingRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -17,9 +19,11 @@ public class VideoService { private String bucketName; private final AmazonS3 amazonS3; + private final VideoRecordingRepository videoRecordingRepository; - public VideoService(AmazonS3 amazonS3) { + public VideoService(AmazonS3 amazonS3, VideoRecordingRepository videoRecordingRepository) { this.amazonS3 = amazonS3; + this.videoRecordingRepository = videoRecordingRepository; } public String saveVideo(Integer userId, LocalDateTime startOffset, LocalDateTime endOffset, MultipartFile videoFile) throws IOException { @@ -34,14 +38,29 @@ public String saveVideo(Integer userId, LocalDateTime startOffset, LocalDateTime amazonS3.putObject(bucketName, key, videoFile.getInputStream(), metadata); - // S3 URL 반환 - return amazonS3.getUrl(bucketName, key).toString(); + String filePath = amazonS3.getUrl(bucketName, key).toString(); + + // 비디오 정보를 DB에 저장 + saveVideoRecording(userId, startOffset, endOffset, filePath); + + return filePath; } catch (Exception e) { throw new IOException("Failed to upload video to S3", e); } } + private void saveVideoRecording(Integer userId, LocalDateTime startTime, LocalDateTime endTime, String filePath) { + VideoRecording videoRecording = new VideoRecording(); + videoRecording.setUserId(userId); + videoRecording.setStartTime(startTime); + videoRecording.setEndTime(endTime); + videoRecording.setFilePath(filePath); + + videoRecordingRepository.save(videoRecording); + } + + private String generateFileName(Integer userId) { return userId + "_" + UUID.randomUUID() + ".webm"; }