Skip to content

Commit 392449b

Browse files
committed
feat: get /log/{id} presigned video URL logic #160
1 parent ba3f498 commit 392449b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

backend/src/main/java/com/example/backend/search/dto/DetailResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,11 @@ public static DetailResponse fromEntity(CaseEntity entity) {
3939
.memo(entity.getMemo())
4040
.build();
4141
}
42+
43+
// 오버로드: presignedUrl을 video 필드에 덮어씌워 반환
44+
public static DetailResponse fromEntity(CaseEntity e, String presignedUrl) {
45+
DetailResponse r = fromEntity(e);
46+
r.setVideo(presignedUrl);
47+
return r;
48+
}
4249
}

backend/src/main/java/com/example/backend/search/service/SearchService.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
package com.example.backend.search.service;
22

3+
import com.amazonaws.HttpMethod;
4+
import com.amazonaws.services.s3.AmazonS3;
5+
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
36
import com.example.backend.common.domain.CaseEntity;
47
import com.example.backend.search.domain.SearchSpecification;
58
import com.example.backend.search.dto.*;
69
import com.example.backend.search.repository.SearchRepository;
710
import lombok.RequiredArgsConstructor;
11+
import org.springframework.beans.factory.annotation.Value;
812
import org.springframework.data.domain.*;
913
import org.springframework.data.jpa.domain.Specification;
1014
import org.springframework.stereotype.Service;
1115
import org.springframework.transaction.annotation.Transactional;
1216

1317
import java.time.LocalDateTime;
18+
import java.util.Date;
1419
import java.util.List;
20+
import java.util.concurrent.TimeUnit;
1521
import java.util.stream.Collectors;
1622

1723
@Service
@@ -58,11 +64,29 @@ public SearchResult getCheckLog(String category, LocalDateTime startDate, LocalD
5864
.build();
5965
}
6066

67+
@Value("${cloud.aws.bucket}")
68+
private String bucket;
69+
private final AmazonS3 s3Client;
6170
public DetailResponse getLogById(Integer id) {
6271
CaseEntity caseEntity = searchRepository.findById(id)
6372
.orElseThrow(() -> new IllegalArgumentException("해당 ID의 로그를 찾을 수 없습니다."));
6473

65-
return DetailResponse.fromEntity(caseEntity);
74+
String videoKey = caseEntity.getVideo();
75+
76+
// Presigned URL 유효기간 설정 (30분)
77+
Date expiration = new Date();
78+
long expTime = expiration.getTime();
79+
expTime += TimeUnit.MINUTES.toMillis(30); // 30 minute
80+
expiration.setTime(expTime);
81+
82+
GeneratePresignedUrlRequest presignRequest =
83+
new GeneratePresignedUrlRequest(bucket, videoKey)
84+
.withMethod(HttpMethod.GET)
85+
.withExpiration(expiration);
86+
87+
String presignedUrl = s3Client.generatePresignedUrl(presignRequest).toString();
88+
89+
return DetailResponse.fromEntity(caseEntity, presignedUrl);
6690
}
6791

6892

0 commit comments

Comments
 (0)