Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#63 S3 이미지 여러장 업로드 #64

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/main/java/com/pyro/yolog/domain/diary/entity/Mood.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,4 @@ public enum Mood {
ANGRY("화나는");

private final String name;

@JsonCreator
public static Mood parsing(String inputValue) {
return Stream.of(Mood.values())
.filter(mood -> mood.getName().equals(inputValue))
.findFirst()
.orElseThrow(RequestMoodNameInvalidException::new);
}
}
8 changes: 0 additions & 8 deletions src/main/java/com/pyro/yolog/domain/diary/entity/Weather.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,4 @@ public enum Weather {
WINDS("바람");

private final String name;

@JsonCreator
public static Weather parsing(String inputValue) {
return Stream.of(Weather.values())
.filter(weather -> weather.getName().equals(inputValue))
.findFirst()
.orElseThrow(RequestWeatherNameInvalidException::new);
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/pyro/yolog/global/s3/api/S3ImageApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

public interface S3ImageApi {
@Operation(
summary = "이미지 업로드",
Expand All @@ -20,7 +22,7 @@ public interface S3ImageApi {
description = "Created"
)
})
S3ImageDto uploadImage(MultipartFile image);
List<S3ImageDto> uploadImage(List<MultipartFile> image);

@Operation(
summary = "이미지 삭제",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("images")
Expand All @@ -16,8 +18,8 @@ public class S3ImageImageController implements S3ImageApi {
@ResponseStatus(HttpStatus.CREATED)
@PostMapping("")
@Override
public S3ImageDto uploadImage(@RequestPart(value = "image", required = false) MultipartFile image) {
return s3ImageService.uploadImage(image);
public List<S3ImageDto> uploadImage(@RequestPart(value = "images", required = false) List<MultipartFile> images) {
return s3ImageService.uploadImage(images);
}

@ResponseStatus(HttpStatus.CREATED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
Expand All @@ -34,9 +35,13 @@ public class S3ImageService {

private final AmazonS3 amazonS3;

public S3ImageDto uploadImage(MultipartFile file) {
validateImageExtension(file.getOriginalFilename());
return new S3ImageDto(uploadImageToS3(file));
public List<S3ImageDto> uploadImage(List<MultipartFile> files) {
List<S3ImageDto> imageUrls = new ArrayList<>();
files.forEach(file -> {
validateImageExtension(file.getOriginalFilename());
imageUrls.add(new S3ImageDto(uploadImageToS3(file)));
});
return imageUrls;
}

private void validateImageExtension(String fileName) {
Expand Down
Loading