Skip to content

Commit de073b7

Browse files
authored
Merge pull request #183 from kookmin-sw/feat/180
[Backend] feat: SSE 알림에 presigned URL 로직 추가
2 parents 55e9eac + 79e339f commit de073b7

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

backend/src/main/java/com/example/backend/dashboard/service/CaseDetectService.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.example.backend.dashboard.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.common.domain.CctvEntity;
58
import com.example.backend.common.domain.OfficeEntity;
@@ -9,10 +12,13 @@
912
import com.example.backend.search.repository.CctvRepository;
1013
import jakarta.persistence.EntityNotFoundException;
1114
import lombok.RequiredArgsConstructor;
15+
import org.springframework.beans.factory.annotation.Value;
1216
import org.springframework.stereotype.Service;
1317
import org.springframework.transaction.annotation.Transactional;
1418

1519
import java.time.LocalDateTime;
20+
import java.util.Date;
21+
import java.util.concurrent.TimeUnit;
1622

1723
@Service
1824
@Transactional
@@ -22,6 +28,10 @@ public class CaseDetectService {
2228
private final DashboardRepository caseRepository;
2329
private final CctvRepository cctvRepository; // CCTV 정보(주소) 조회용
2430

31+
@Value("${cloud.aws.bucket}")
32+
private String bucket;
33+
private final AmazonS3 s3Client;
34+
2535
public CaseDetectResponse saveCase(CaseDetectRequest request) {
2636
// 1) CCTV 정보 조회 (주소 포함)
2737
CctvEntity cctvEntity = cctvRepository.findById(request.getCctvId())
@@ -48,7 +58,23 @@ public CaseDetectResponse saveCase(CaseDetectRequest request) {
4858

4959
CaseEntity saved = caseRepository.save(caseEntity);
5060

61+
CaseDetectResponse detect_case = CaseDetectResponse.fromEntity(saved);
62+
63+
// Presigned URL 유효기간 설정 (30분)
64+
Date expiration = new Date();
65+
long expTime = expiration.getTime();
66+
expTime += TimeUnit.MINUTES.toMillis(30); // 30 minute
67+
expiration.setTime(expTime);
68+
69+
GeneratePresignedUrlRequest presignRequest =
70+
new GeneratePresignedUrlRequest(bucket, detect_case.getVideo())
71+
.withMethod(HttpMethod.GET)
72+
.withExpiration(expiration);
73+
74+
String url = s3Client.generatePresignedUrl(presignRequest).toString();
75+
detect_case.setVideo(url);
76+
5177
// 3) DTO 변환: 기존에 정의한 fromEntity 메서드를 사용하여 응답 객체 생성
52-
return CaseDetectResponse.fromEntity(saved);
78+
return detect_case;
5379
}
5480
}

0 commit comments

Comments
 (0)