diff --git a/backend/src/main/java/com/funeat/common/controller/PreSingedApiController.java b/backend/src/main/java/com/funeat/common/controller/PreSingedApiController.java new file mode 100644 index 000000000..34ec9776d --- /dev/null +++ b/backend/src/main/java/com/funeat/common/controller/PreSingedApiController.java @@ -0,0 +1,28 @@ +package com.funeat.common.controller; + +import com.funeat.common.dto.S3UrlRequest; +import com.funeat.common.dto.S3UrlResponse; +import com.funeat.common.s3.S3UploadUrlGenerator; +import org.springframework.http.HttpStatus; +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.RestController; + +@RestController +public class PreSingedApiController implements PreSingedController { + + private final S3UploadUrlGenerator s3UploadUrlGenerator; + + public PreSingedApiController(final S3UploadUrlGenerator s3UploadUrlGenerator) { + this.s3UploadUrlGenerator = s3UploadUrlGenerator; + } + + @PostMapping("/api/s3/presigned") + public ResponseEntity getPreSingedUrl(@RequestBody final S3UrlRequest request) { + final S3UrlResponse preSignedUrl = s3UploadUrlGenerator.getPreSignedUrl(request.getFileName()); + + return ResponseEntity.status(HttpStatus.CREATED) + .body(preSignedUrl); + } +} diff --git a/backend/src/main/java/com/funeat/common/controller/PreSingedController.java b/backend/src/main/java/com/funeat/common/controller/PreSingedController.java new file mode 100644 index 000000000..cc78d575a --- /dev/null +++ b/backend/src/main/java/com/funeat/common/controller/PreSingedController.java @@ -0,0 +1,20 @@ +package com.funeat.common.controller; + +import com.funeat.common.dto.S3UrlRequest; +import com.funeat.common.dto.S3UrlResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + +public interface PreSingedController { + + @Operation(summary = "S3 업로드 URL 요청", description = "S3 업로드 URL 요청한다.") + @ApiResponse( + responseCode = "201", + description = "업로드 URL 요청 성공." + ) + @PostMapping + ResponseEntity getPreSingedUrl(@RequestBody final S3UrlRequest request); +}