From b477536b8fc688263c34889adefe92470acc6491 Mon Sep 17 00:00:00 2001 From: jeong-inho Date: Wed, 23 Jun 2021 11:19:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20(#35)=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=97=85=EB=A1=9C=EB=93=9C=20API=EC=9D=98=20response=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/issuetracker/service/ImageService.java | 5 +++-- .../java/com/issuetracker/web/ImageController.java | 3 ++- .../web/dto/response/ImageResponseDTO.java | 11 +++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 BE/src/main/java/com/issuetracker/web/dto/response/ImageResponseDTO.java diff --git a/BE/src/main/java/com/issuetracker/service/ImageService.java b/BE/src/main/java/com/issuetracker/service/ImageService.java index 1b0c594f3..c31efcc0a 100644 --- a/BE/src/main/java/com/issuetracker/service/ImageService.java +++ b/BE/src/main/java/com/issuetracker/service/ImageService.java @@ -8,6 +8,7 @@ import com.amazonaws.services.s3.model.ObjectMetadata; import com.issuetracker.domain.image.Image; import com.issuetracker.domain.image.ImageRepository; +import com.issuetracker.web.dto.response.ImageResponseDTO; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -36,7 +37,7 @@ public ImageService(@Value("${cloud.aws.credentials.accessKey}") String accessKe this.imageRepository = imageRepository; } - public String upload(MultipartFile multipartFile) throws IOException { + public ImageResponseDTO upload(MultipartFile multipartFile) throws IOException { ObjectMetadata data = new ObjectMetadata(); data.setContentType(multipartFile.getContentType()); data.setContentLength(multipartFile.getSize()); @@ -50,7 +51,7 @@ public String upload(MultipartFile multipartFile) throws IOException { String imageName = getImageName(multipartFile); s3client.putObject(bucket, imageName, multipartFile.getInputStream(), data); Image image = saveImageUrl(defaultUrl + "/" + imageName); - return image.getImageUrl(); + return new ImageResponseDTO(image.getImageUrl()); } private String getImageName(MultipartFile multipartFile) { diff --git a/BE/src/main/java/com/issuetracker/web/ImageController.java b/BE/src/main/java/com/issuetracker/web/ImageController.java index 05a35a497..8b9520e4d 100644 --- a/BE/src/main/java/com/issuetracker/web/ImageController.java +++ b/BE/src/main/java/com/issuetracker/web/ImageController.java @@ -1,6 +1,7 @@ package com.issuetracker.web; import com.issuetracker.service.ImageService; +import com.issuetracker.web.dto.response.ImageResponseDTO; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -16,7 +17,7 @@ public class ImageController { private final ImageService imageService; @PostMapping("/api/images") - public String upload(@RequestParam("image") MultipartFile multipartFile) throws IOException { + public ImageResponseDTO upload(@RequestParam("image") MultipartFile multipartFile) throws IOException { return imageService.upload(multipartFile); } } diff --git a/BE/src/main/java/com/issuetracker/web/dto/response/ImageResponseDTO.java b/BE/src/main/java/com/issuetracker/web/dto/response/ImageResponseDTO.java new file mode 100644 index 000000000..75353f802 --- /dev/null +++ b/BE/src/main/java/com/issuetracker/web/dto/response/ImageResponseDTO.java @@ -0,0 +1,11 @@ +package com.issuetracker.web.dto.response; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public class ImageResponseDTO { + + private final String image; +}