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);