-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Team-BomBomBom/feat/generate_presigned_urβ¦
β¦l#BBB-125 Feat: #BBB-125 AWS S3 multipart λ°©μ μμ μ λ‘λ API ꡬν
- Loading branch information
Showing
27 changed files
with
480 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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: 7 additions & 0 deletions
7
...m/bombombom/devs/external/study/controller/dto/request/CheckVideoUploadStatusRequest.java
This file contains 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,7 @@ | ||
package com.bombombom.devs.external.study.controller.dto.request; | ||
|
||
public record CheckVideoUploadStatusRequest( | ||
Long assignmentId | ||
) { | ||
|
||
} |
This file contains 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
52 changes: 52 additions & 0 deletions
52
...ernal-api/src/main/java/com/bombombom/devs/external/video/controller/VideoController.java
This file contains 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,52 @@ | ||
package com.bombombom.devs.external.video.controller; | ||
|
||
import com.bombombom.devs.S3MultipartUploadClient; | ||
import com.bombombom.devs.dto.FinishMultipartUploadResponse; | ||
import com.bombombom.devs.dto.GeneratePresignedUrlResponse; | ||
import com.bombombom.devs.dto.InitiateMultipartUploadResponse; | ||
import com.bombombom.devs.external.video.controller.dto.CompleteVideoUploadRequest; | ||
import com.bombombom.devs.external.video.controller.dto.CompleteVideoUploadResponse; | ||
import com.bombombom.devs.external.video.controller.dto.GenerateUploadUrlRequest; | ||
import com.bombombom.devs.external.video.controller.dto.GenerateUploadUrlResponse; | ||
import com.bombombom.devs.external.video.controller.dto.InitiateUploadRequest; | ||
import com.bombombom.devs.external.video.controller.dto.InitiateUploadResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/videos") | ||
public class VideoController { | ||
|
||
private final S3MultipartUploadClient s3MultipartUploadClient; | ||
|
||
@PostMapping("/initiate-upload") | ||
public ResponseEntity<InitiateUploadResponse> initiateUpload( | ||
@RequestBody InitiateUploadRequest request) { | ||
InitiateMultipartUploadResponse response = s3MultipartUploadClient.initiate( | ||
request.toS3ClientDto()); | ||
return ResponseEntity.ok(InitiateUploadResponse.fromS3ClientResponse(response)); | ||
} | ||
|
||
@PostMapping("/presigned-url") | ||
public ResponseEntity<GenerateUploadUrlResponse> generateMultipartUploadUrl( | ||
@RequestBody GenerateUploadUrlRequest request) { | ||
GeneratePresignedUrlResponse response = s3MultipartUploadClient.generatePresignedUrl( | ||
request.toS3ClientDto()); | ||
return ResponseEntity.ok().body(GenerateUploadUrlResponse.fromS3ClientResponse(response)); | ||
} | ||
|
||
@PostMapping("/complete-upload") | ||
public ResponseEntity<CompleteVideoUploadResponse> completeVideoUpload( | ||
@RequestBody CompleteVideoUploadRequest request) { | ||
FinishMultipartUploadResponse response = s3MultipartUploadClient.finishMultipartUpload( | ||
request.toS3ClientDto()); | ||
return ResponseEntity.ok(CompleteVideoUploadResponse.fromS3ClientResponse(response)); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...ain/java/com/bombombom/devs/external/video/controller/dto/CompleteVideoUploadRequest.java
This file contains 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,24 @@ | ||
package com.bombombom.devs.external.video.controller.dto; | ||
|
||
import com.bombombom.devs.dto.FinishMultipartUploadRequest; | ||
import com.bombombom.devs.dto.FinishMultipartUploadRequest.Part; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record CompleteVideoUploadRequest( | ||
String uploadId, | ||
List<Part> parts, | ||
long studyId, | ||
long assignmentId | ||
) { | ||
|
||
public FinishMultipartUploadRequest toS3ClientDto() { | ||
return FinishMultipartUploadRequest.builder() | ||
.uploadId(uploadId) | ||
.objectName("task/" + studyId + "/" + assignmentId) | ||
.parts(parts) | ||
.build(); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...in/java/com/bombombom/devs/external/video/controller/dto/CompleteVideoUploadResponse.java
This file contains 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 com.bombombom.devs.external.video.controller.dto; | ||
|
||
import com.bombombom.devs.dto.FinishMultipartUploadResponse; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record CompleteVideoUploadResponse( | ||
String bucketName, | ||
String objectName | ||
) { | ||
|
||
public static CompleteVideoUploadResponse fromS3ClientResponse( | ||
FinishMultipartUploadResponse response) { | ||
return CompleteVideoUploadResponse.builder() | ||
.bucketName(response.bucket()) | ||
.objectName(response.key()) | ||
.build(); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
.../main/java/com/bombombom/devs/external/video/controller/dto/GenerateUploadUrlRequest.java
This file contains 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,24 @@ | ||
package com.bombombom.devs.external.video.controller.dto; | ||
|
||
import com.bombombom.devs.dto.GeneratePresignedUrlRequest; | ||
import jakarta.validation.constraints.Min; | ||
|
||
public record GenerateUploadUrlRequest( | ||
String uploadId, | ||
@Min(0) int partNumber, | ||
long partSize, | ||
@Min(0) long studyId, | ||
@Min(0) long assignmentId | ||
) { | ||
|
||
public GeneratePresignedUrlRequest toS3ClientDto() { | ||
return GeneratePresignedUrlRequest.builder() | ||
.uploadId(uploadId) | ||
.partNumber(partNumber) | ||
.contentType("video/*") | ||
.objectName("task/" + studyId + "/" + assignmentId) | ||
.contentLength(partSize) | ||
.build(); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...main/java/com/bombombom/devs/external/video/controller/dto/GenerateUploadUrlResponse.java
This file contains 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,18 @@ | ||
package com.bombombom.devs.external.video.controller.dto; | ||
|
||
import com.bombombom.devs.dto.GeneratePresignedUrlResponse; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record GenerateUploadUrlResponse( | ||
String presignedUrl | ||
) { | ||
|
||
public static GenerateUploadUrlResponse fromS3ClientResponse( | ||
GeneratePresignedUrlResponse response) { | ||
return GenerateUploadUrlResponse.builder() | ||
.presignedUrl(response.presignedUrl()) | ||
.build(); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...src/main/java/com/bombombom/devs/external/video/controller/dto/InitiateUploadRequest.java
This file contains 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,22 @@ | ||
package com.bombombom.devs.external.video.controller.dto; | ||
|
||
import com.bombombom.devs.dto.InitiateMultipartUploadRequest; | ||
import jakarta.validation.constraints.Min; | ||
import jakarta.validation.constraints.Pattern; | ||
|
||
public record InitiateUploadRequest( | ||
@Min(0) long studyId, | ||
@Min(0) long assignmentId, | ||
@Pattern(regexp = "^video/.+", message = "λΉλμ€ νμΌμ MIME νμ λ§ κ°λ₯ν©λλ€.") String fileType | ||
) { | ||
|
||
public InitiateMultipartUploadRequest toS3ClientDto() { | ||
return InitiateMultipartUploadRequest.builder() | ||
.objectName("task/" + studyId + "/" + assignmentId) | ||
.studyId(String.valueOf(studyId)) | ||
.assignmentId(String.valueOf(assignmentId)) | ||
.fileType(fileType) | ||
.build(); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...rc/main/java/com/bombombom/devs/external/video/controller/dto/InitiateUploadResponse.java
This file contains 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,18 @@ | ||
package com.bombombom.devs.external.video.controller.dto; | ||
|
||
import com.bombombom.devs.dto.InitiateMultipartUploadResponse; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record InitiateUploadResponse( | ||
String uploadId | ||
) { | ||
|
||
public static InitiateUploadResponse fromS3ClientResponse( | ||
InitiateMultipartUploadResponse response) { | ||
return InitiateUploadResponse.builder() | ||
.uploadId(response.uploadId()) | ||
.build(); | ||
} | ||
|
||
} |
This file contains 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 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 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 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,11 @@ | ||
subprojects { | ||
dependencies { | ||
compileOnly 'org.springframework:spring-context' | ||
implementation project(':core') | ||
|
||
testImplementation platform('org.junit:junit-bom:5.9.1') | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'org.assertj:assertj-core:3.11.1' | ||
testImplementation 'com.squareup.okhttp3:mockwebserver' | ||
} | ||
} |
This file contains 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,14 @@ | ||
ext { | ||
springCloudAwsVersion = '3.1.1' | ||
} | ||
|
||
dependencies { | ||
compileOnly 'org.springframework:spring-context' | ||
|
||
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:${springCloudAwsVersion}") | ||
implementation 'software.amazon.awssdk:bom:2.27.17' | ||
implementation 'io.awspring.cloud:spring-cloud-aws-starter-s3' | ||
|
||
testImplementation platform('org.junit:junit-bom:5.10.0') | ||
testImplementation 'org.junit.jupiter:junit-jupiter' | ||
} |
Oops, something went wrong.