From 6b99895b9977224ee4da5acb1b2f56536d280138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Mon, 23 Sep 2024 16:30:23 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20S3=EC=97=90=20=EC=83=88=EB=A1=9C?= =?UTF-8?q?=EC=9A=B4=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/service/ProjectService.java | 22 +++++++++++++++++-- .../global/service/S3UploadService.java | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java b/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java index 36d2a2b..dd11673 100644 --- a/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java +++ b/backend/src/main/java/com/worlabel/domain/project/service/ProjectService.java @@ -32,6 +32,7 @@ import com.worlabel.global.annotation.CheckPrivilege; import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.ErrorCode; import com.worlabel.global.service.AiRequestService; +import com.worlabel.global.service.S3UploadService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -57,6 +58,7 @@ public class ProjectService { private final AiModelRepository aiModelRepository; private final AiRequestService aiService; private final Gson gson; + private final S3UploadService s3UploadService; public ProjectResponse createProject(final Integer memberId, final Integer workspaceId, final ProjectRequest projectRequest) { Workspace workspace = getWorkspace(memberId, workspaceId); @@ -170,10 +172,21 @@ public class ProjectService { // 응답없음 log.debug("요청"); List list = aiService.postRequest(endPoint, autoLabelingRequest, List.class, this::converter); - log.debug("list: {}", list); + saveAutoLabelList(list); } - public List converter(String data) { + public void saveAutoLabelList(final List resultList) { + for(AutoLabelingResult result: resultList) { + Image image = getImage(result.getImageId()); + String dataPath = image.getDataPath(); + s3UploadService.uploadJson(result.getData(), dataPath); + } + } + + /** + * 데이터 변환 + */ + private List converter(String data) { try { log.debug("data :{}", data); // Gson에서 리스트 형태로 변환할 타입을 지정 @@ -205,6 +218,11 @@ public class ProjectService { return labelMap; } + private Image getImage(final Long imageId){ + return imageRepository.findById(imageId) + .orElseThrow(()-> new CustomException(ErrorCode.DATA_NOT_FOUND)); + } + private Project getProject(final Integer projectId) { return projectRepository.findById(projectId) .orElseThrow(() -> new CustomException(ErrorCode.PROJECT_NOT_FOUND)); diff --git a/backend/src/main/java/com/worlabel/global/service/S3UploadService.java b/backend/src/main/java/com/worlabel/global/service/S3UploadService.java index dffbee7..e514d01 100644 --- a/backend/src/main/java/com/worlabel/global/service/S3UploadService.java +++ b/backend/src/main/java/com/worlabel/global/service/S3UploadService.java @@ -46,6 +46,7 @@ public class S3UploadService { public void uploadJson(final String json, final String dataUrl) { String key = getKeyFromImageAddress(dataUrl); + log.debug(key); try { byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);