Skip to content

Commit

Permalink
feat: (#35) 이미지 업로드 API의 response 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
eNoLJ committed Jun 23, 2021
1 parent ef793cc commit b477536
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions BE/src/main/java/com/issuetracker/service/ImageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion BE/src/main/java/com/issuetracker/web/ImageController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit b477536

Please sign in to comment.