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"; }