diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java index 046aea29..569c92a2 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/ImageStorage.java @@ -4,10 +4,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import org.ktc2.cokaen.wouldyouin.Image.api.dto.ImageRequest; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToDeleteImageException; import org.ktc2.cokaen.wouldyouin._common.exception.FailedToUploadImageException; import org.springframework.beans.factory.annotation.Value; @@ -36,19 +36,19 @@ public String save(MultipartFile image, String subPath) { } // Todo: payment랑 이부분 restclient 유틸로 빼기 - public String save(String imageUrl, String subPath) { + public ImageRequest save(String imageUrl, String subPath) { RestClient client = RestClient.builder().build(); String fileName = ""; + Long size = 0L; try { ResponseEntity response = client.get() .uri(imageUrl) .retrieve() .toEntity(byte[].class); - if (Optional.ofNullable(response).isPresent() && response.getStatusCode().is2xxSuccessful()) { - byte[] imageBytes = response.getBody(); - + if (Optional.ofNullable(response.getBody()).isPresent() && response.getStatusCode().is2xxSuccessful()) { fileName = generateUuidName() + "." + getExtension(imageUrl); + size = (long) response.getBody().length; Path path = Paths.get(commonPath, subPath, fileName); Files.createDirectories(path.getParent()); Files.write(path, response.getBody()); @@ -56,7 +56,8 @@ public String save(String imageUrl, String subPath) { } catch (IOException ex) { throw new FailedToUploadImageException(); } - return subPath + "/" + fileName; + String url = subPath + "/" + fileName; + return ImageRequest.of(url, size, getExtension(imageUrl)); } public void delete(String imagePath) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java index 621679b3..ba009567 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/Image/application/MemberImageService.java @@ -60,10 +60,7 @@ public void setBaseMember(MemberImage image, BaseMember member) { image.setBaseMember(member); } - // TODO: imageUrl을 MemberImage로 변환하는 로직 추가 필요 - // Todo: extension과 size 불러오기 public MemberImage convert(String imageUrl) { - var request = ImageRequest.of(imageStorage.save(imageUrl, subPath), 123123L, "jpg"); - return memberImageRepository.save(toEntity(request)); + return memberImageRepository.save(toEntity(imageStorage.save(imageUrl, subPath))); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java new file mode 100644 index 00000000..861847a4 --- /dev/null +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/config/ObjectMapperConfig.java @@ -0,0 +1,14 @@ +package org.ktc2.cokaen.wouldyouin._common.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ObjectMapperConfig { + + @Bean + ObjectMapper objectMapper() { + return new ObjectMapper(); + } +} \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e76ba79b..446aa5a9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,6 +4,11 @@ spring: application.name: WouldYouIn + servlet: + multipart: + max-file-size: 10MB + max-request-size: 10MB + # 임시 프로젝트 url wouldyouin-domain-name: http://52.78.71.136/ profiles: diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java index d6fcb308..d7055555 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/curation/CurationControllerUnitTest.java @@ -48,6 +48,7 @@ @WebMvcTest(CurationController.class) class CurationControllerUnitTest { + private static ObjectMapper objectMapper; @MockBean @@ -66,7 +67,6 @@ class CurationControllerUnitTest { @BeforeAll public static void init() { - objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); }