-
Notifications
You must be signed in to change notification settings - Fork 4
[feat] 이미지 업로드 API 엔드포인트 분리 #97
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/arom/with_travel/domain/image/ImageType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.arom.with_travel.domain.image; | ||
|
|
||
| public enum ImageType { | ||
| ACCOMPANY, COMMUNITY, MEMBER_PROFILE | ||
| } |
69 changes: 69 additions & 0 deletions
69
src/main/java/com/arom/with_travel/domain/image/PostUploadImages.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| package com.arom.with_travel.domain.image; | ||
|
|
||
| import com.arom.with_travel.domain.image.dto.UploadedImageResponse; | ||
| import com.arom.with_travel.global.exception.response.ErrorResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.Parameters; | ||
| import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
| import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
| import io.swagger.v3.oas.annotations.media.Content; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import org.springframework.http.MediaType; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Operation( | ||
| summary = "이미지 업로드", | ||
| description = """ | ||
| Multipart/form-data 요청으로 여러 이미지를 S3에 업로드합니다. | ||
| 저장 디렉터리(dir) 파라미터는 S3 버킷 내의 하위 경로를 의미하며, | ||
| 정상 처리되면 업로드된 각 이미지의 URL과 원본 파일명을 담은 리스트를 반환합니다. | ||
| """) | ||
| @Parameters({ | ||
| @Parameter( | ||
| name = "files", | ||
| description = "업로드할 이미지 파일들 (복수 가능)", | ||
| in = ParameterIn.DEFAULT, | ||
| required = true, | ||
| content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA_VALUE, | ||
| array = @ArraySchema(schema = @Schema(type = "string", format = "binary"))) | ||
| ), | ||
| @Parameter( | ||
| name = "dir", | ||
| description = """ | ||
| S3 저장 디렉터리 | ||
| 디렉토리 종류 : | ||
| accompany-img(동행글), | ||
| member-profile-img(프로필 이미지), | ||
| community-img(커뮤니티 글) | ||
| """, | ||
| in = ParameterIn.QUERY, | ||
| required = true, | ||
| schema = @Schema(type = "string") | ||
| ) | ||
| }) | ||
| @ApiResponses(value = { | ||
| @ApiResponse( | ||
| responseCode = "200", | ||
| description = "업로드 성공", | ||
| content = @Content( | ||
| mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
| array = @ArraySchema(schema = @Schema(implementation = UploadedImageResponse.class))) | ||
| ), | ||
| @ApiResponse( | ||
| responseCode = "400", | ||
| description = "요청 형식 오류(파일 누락 등)", | ||
| content = @Content( | ||
| mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
| schema = @Schema(implementation = ErrorResponse.class))) | ||
| }) | ||
| public @interface PostUploadImages { | ||
| } |
21 changes: 14 additions & 7 deletions
21
src/main/java/com/arom/with_travel/domain/image/controller/ImageController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,36 @@ | ||
| package com.arom.with_travel.domain.image.controller; | ||
|
|
||
| import com.arom.with_travel.domain.image.PostUploadImages; | ||
| import com.arom.with_travel.domain.image.dto.UploadedImageResponse; | ||
| import com.arom.with_travel.global.oauth2.dto.CustomOAuth2User; | ||
| import com.arom.with_travel.global.s3.service.S3Service; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| @Slf4j | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/image") | ||
| @RequestMapping("/api/v1/images") | ||
| @Tag(name = "이미지", description = "이미지 업로드 api") | ||
| public class ImageController { | ||
|
|
||
| private final S3Service s3Service; | ||
|
|
||
| @PostUploadImages | ||
| @PostMapping("/upload") | ||
| public String upload( | ||
| @RequestParam("file") MultipartFile file, | ||
| @RequestParam("dir") String directory) throws IOException { | ||
| log.info("Uploading file {}", file.getOriginalFilename()); | ||
| return s3Service.uploadFile(file, directory); | ||
| public List<UploadedImageResponse> uploadAccompanyImages(@AuthenticationPrincipal CustomOAuth2User user, | ||
| @RequestParam("files") List<MultipartFile> files, | ||
| @RequestParam("dir") String directory) throws IOException { | ||
| return s3Service.uploadFiles(files, directory); | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/arom/with_travel/domain/image/dto/ImageRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.arom.with_travel.domain.image.dto; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public class ImageRequest { | ||
| private String imageName; | ||
| private String imageUrl; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fromCommunity factory method hardcodes ImageType.COMMUNITY instead of accepting it as a parameter like the other factory methods. This is inconsistent with fromAccompany and fromMember methods which accept ImageType as a parameter.