-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Presigned URL 구현 #210
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
15 commits
Select commit
Hold shift + click to select a range
572c4b8
feat: Enum Converter 추가
Choi-JJunho e82b46d
chore: merge develop
Choi-JJunho 602a96e
style: 변수명 변경
Choi-JJunho 7137794
style: 불필요한 주석 제거
Choi-JJunho e62f312
refactor: Controller 테스트 제거
Choi-JJunho a784b8a
refactor: 예외 수정
Choi-JJunho de95915
chore: 패키지 구분
Choi-JJunho 32fd261
refactor: 외부 API로 구분
Choi-JJunho b470cea
style: 공백제거
Choi-JJunho 43ea630
test: 테스트 수정
Choi-JJunho b6acc07
refactor: 변수명 변경
Choi-JJunho 2f8bc32
Merge branch 'develop' of https://github.com/BCSDLab/KOIN_API_V2 into…
Choi-JJunho e31ec07
refactor: fileName 포함하도록 수정
Choi-JJunho a0decd1
chore: merge develop
Choi-JJunho 72a505e
refactor: request dto swagger 설명 추가
Choi-JJunho 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
3 changes: 1 addition & 2 deletions
3
src/main/java/in/koreatech/koin/domain/ownershop/controller/OwnerShopApi.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
11 changes: 6 additions & 5 deletions
11
...ershop/controller/OwnerShopContoller.java → ...rshop/controller/OwnerShopController.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
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
3 changes: 1 addition & 2 deletions
3
src/main/java/in/koreatech/koin/domain/shop/dto/ShopResponse.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
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
7 changes: 2 additions & 5 deletions
7
src/main/java/in/koreatech/koin/domain/timetable/model/Semester.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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/in/koreatech/koin/global/config/S3Config.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,23 @@ | ||
| package in.koreatech.koin.global.config; | ||
|
|
||
|
|
||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider; | ||
| import static software.amazon.awssdk.regions.Region.AP_NORTHEAST_2; | ||
| import software.amazon.awssdk.services.s3.presigner.S3Presigner; | ||
|
|
||
| @Configuration | ||
| public class S3Config { | ||
|
|
||
| /** | ||
| * S3Presigner 사용 후 close()를 권장하므로, Builder 를 반환하여 필요 시 객체를 만들어 사용 후 close 되도록 구현. | ||
| */ | ||
| @Bean | ||
| public S3Presigner.Builder s3PresignerBuilder() { | ||
| return S3Presigner.builder() | ||
| .credentialsProvider(InstanceProfileCredentialsProvider.create()) | ||
| .region(AP_NORTHEAST_2); | ||
| } | ||
| } |
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
19 changes: 19 additions & 0 deletions
19
...ava/in/koreatech/koin/global/domain/upload/controller/ImageUploadDomainEnumConverter.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,19 @@ | ||
| package in.koreatech.koin.global.domain.upload.controller; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| import org.springframework.core.convert.converter.Converter; | ||
|
|
||
| import in.koreatech.koin.global.domain.upload.exception.ImageUploadDomainNotFoundException; | ||
| import in.koreatech.koin.global.domain.upload.model.ImageUploadDomain; | ||
|
|
||
| public class ImageUploadDomainEnumConverter implements Converter<String, ImageUploadDomain> { | ||
|
|
||
| @Override | ||
| public ImageUploadDomain convert(String source) { | ||
| return Arrays.stream(ImageUploadDomain.values()) | ||
| .filter(it -> it.name().equalsIgnoreCase(source)) | ||
| .findAny() | ||
| .orElseThrow(() -> ImageUploadDomainNotFoundException.withDetail("source: " + source)); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/main/java/in/koreatech/koin/global/domain/upload/controller/UploadApi.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,51 @@ | ||
| package in.koreatech.koin.global.domain.upload.controller; | ||
|
|
||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
|
|
||
| import in.koreatech.koin.domain.user.model.UserType; | ||
| import static in.koreatech.koin.domain.user.model.UserType.STUDENT; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import in.koreatech.koin.global.domain.upload.dto.UploadUrlRequest; | ||
| import in.koreatech.koin.global.domain.upload.dto.UploadUrlResponse; | ||
| import in.koreatech.koin.global.domain.upload.model.ImageUploadDomain; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| 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 io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
|
|
||
| @Tag(name = "(Normal) Upload : 파일 업로드", description = "파일 업로드를 수행한다.") | ||
| public interface UploadApi { | ||
|
|
||
| @ApiResponses( | ||
| value = { | ||
| @ApiResponse(responseCode = "200"), | ||
| @ApiResponse(responseCode = "401", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "403", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "404", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "413", content = @Content(schema = @Schema(hidden = true))), | ||
| @ApiResponse(responseCode = "415", content = @Content(schema = @Schema(hidden = true))), | ||
| } | ||
| ) | ||
| @Operation(summary = "파일을 업로드할 수 있는 URL 생성", description = """ | ||
| - `items` | ||
| - `lands` | ||
| - `circles` | ||
| - `market` | ||
| - `shops` | ||
| - `members` | ||
| - `owners` | ||
| """) | ||
| @PostMapping("/{domain}/upload/url") | ||
| ResponseEntity<UploadUrlResponse> getPresignedUrl( | ||
| @PathVariable ImageUploadDomain domain, | ||
| @RequestBody @Valid UploadUrlRequest request, | ||
| @Auth(permit = {UserType.OWNER, STUDENT}) Long memberId | ||
| ); | ||
| } |
34 changes: 34 additions & 0 deletions
34
src/main/java/in/koreatech/koin/global/domain/upload/controller/UploadController.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,34 @@ | ||
| package in.koreatech.koin.global.domain.upload.controller; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import in.koreatech.koin.domain.user.model.UserType; | ||
| import static in.koreatech.koin.domain.user.model.UserType.STUDENT; | ||
| import in.koreatech.koin.global.auth.Auth; | ||
| import in.koreatech.koin.global.domain.upload.dto.UploadUrlRequest; | ||
| import in.koreatech.koin.global.domain.upload.dto.UploadUrlResponse; | ||
| import in.koreatech.koin.global.domain.upload.model.ImageUploadDomain; | ||
| import in.koreatech.koin.global.domain.upload.service.UploadService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class UploadController implements UploadApi { | ||
|
|
||
| private final UploadService uploadService; | ||
|
|
||
| @PostMapping("/{domain}/upload/url") | ||
| public ResponseEntity<UploadUrlResponse> getPresignedUrl( | ||
| @PathVariable ImageUploadDomain domain, | ||
| @RequestBody @Valid UploadUrlRequest request, | ||
| @Auth(permit = {UserType.OWNER, STUDENT}) Long memberId | ||
| ) { | ||
| var response = uploadService.getPresignedUrl(domain, request); | ||
| return ResponseEntity.ok(response); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/main/java/in/koreatech/koin/global/domain/upload/dto/UploadUrlRequest.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,20 @@ | ||
| package in.koreatech.koin.global.domain.upload.dto; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| public record UploadUrlRequest( | ||
| @Schema(description = "파일 크기", example = "1000") | ||
| Integer contentLength, | ||
|
|
||
| @Schema(description = "파일 타입", example = "image/png") | ||
| String contentType, | ||
|
|
||
| @Schema(description = "파일 이름", example = "hello.png") | ||
| String fileName | ||
| ) { | ||
|
|
||
| } |
33 changes: 33 additions & 0 deletions
33
src/main/java/in/koreatech/koin/global/domain/upload/dto/UploadUrlResponse.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,33 @@ | ||
| package in.koreatech.koin.global.domain.upload.dto; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| public record UploadUrlResponse( | ||
| @Schema(description = "파일을 업로드할 수 있는 url", | ||
| example = """ | ||
| https://bucketname.ap-northeast-2.amazonaws.com/upload/domain/2000/00/00/d4cb13df-cf57-4612-b37d-80ecfa3f4621-1694847132589/image.jpg | ||
| ?x-amz-acl=public-read | ||
| &X-Amz-Algorithm=AWS4-HMAC-SHA256 | ||
| &X-Amz-Date=20000000T000000Z | ||
| &X-Amz-SignedHeaders=content-length%3Bcontent-type%3Bhost | ||
| &X-Amz-Expires=7199&X-Amz-Credential=AKIA6BRP3Q6L5PUD5W5Q%2F20230916%2Fap-northeast-2%2Fs3%2Faws4_request | ||
| &X-Amz-Signature=796esadfsadfxcv213f851431a88bc16c8db048f322b8993e21e4829c531 | ||
| """) | ||
| String preSignedUrl, | ||
|
|
||
| @Schema(description = "업로드한 파일을 가져올 때 사용하는 url", example = "https://static.koreatech.in/2023/09/01/uuid/example.png") | ||
| String fileUrl, | ||
|
|
||
| @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
| @Schema(description = "presigned url 만료 일자", example = "2023-01-01 12:34:56") | ||
| LocalDateTime expirationDate | ||
| ) { | ||
|
|
||
| } |
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.
A
헐.. 대박