From d8e341f38b27ed08dd3d4cb7f45b42a0dcbc111c Mon Sep 17 00:00:00 2001 From: Miseong Kim Date: Sun, 27 Oct 2024 23:53:36 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20presigned=20url=20=EB=B0=9C=EA=B8=89=20a?= =?UTF-8?q?pi=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserProfileControllerV2.kt | 8 ++--- .../api/user/facade/UserProfileFacadeV2.kt | 30 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/api/src/main/kotlin/com/nexters/bottles/api/user/controller/UserProfileControllerV2.kt b/api/src/main/kotlin/com/nexters/bottles/api/user/controller/UserProfileControllerV2.kt index 5a4f46f..4871b3c 100644 --- a/api/src/main/kotlin/com/nexters/bottles/api/user/controller/UserProfileControllerV2.kt +++ b/api/src/main/kotlin/com/nexters/bottles/api/user/controller/UserProfileControllerV2.kt @@ -3,7 +3,6 @@ package com.nexters.bottles.api.user.controller import com.nexters.bottles.api.global.interceptor.AuthRequired import com.nexters.bottles.api.global.resolver.AuthUserId import com.nexters.bottles.api.user.facade.UserProfileFacadeV2 -import com.nexters.bottles.api.user.facade.dto.PresignedUrlsRequest import com.nexters.bottles.api.user.facade.dto.PresignedUrlsResponse import com.nexters.bottles.api.user.facade.dto.RegisterImageUrlsRequest import io.swagger.annotations.ApiOperation @@ -11,6 +10,7 @@ import org.springframework.web.bind.annotation.GetMapping 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.RequestParam import org.springframework.web.bind.annotation.RestController @RestController @@ -22,10 +22,8 @@ class UserProfileControllerV2( @ApiOperation("사진 여러장 업로드 S3 Presigned Url 발급받기") @GetMapping("/images/presigned-url") @AuthRequired - fun getS3PresignedUrls( - @AuthUserId userId: Long, @RequestBody presignedUrlsRequest: PresignedUrlsRequest - ): PresignedUrlsResponse { - return profileFacadeV2.getS3PresignedUrls(userId, presignedUrlsRequest) + fun getS3PresignedUrls(@AuthUserId userId: Long, @RequestParam imageCount: Int): PresignedUrlsResponse { + return profileFacadeV2.getS3PresignedUrls(userId, imageCount) } @ApiOperation("사진 업로드 후 url 저장하기") diff --git a/api/src/main/kotlin/com/nexters/bottles/api/user/facade/UserProfileFacadeV2.kt b/api/src/main/kotlin/com/nexters/bottles/api/user/facade/UserProfileFacadeV2.kt index a977f1e..7e8e66a 100644 --- a/api/src/main/kotlin/com/nexters/bottles/api/user/facade/UserProfileFacadeV2.kt +++ b/api/src/main/kotlin/com/nexters/bottles/api/user/facade/UserProfileFacadeV2.kt @@ -1,6 +1,5 @@ package com.nexters.bottles.api.user.facade -import com.nexters.bottles.api.user.facade.dto.PresignedUrlsRequest import com.nexters.bottles.api.user.facade.dto.PresignedUrlsResponse import com.nexters.bottles.api.user.facade.dto.RegisterImageUrlsRequest import com.nexters.bottles.app.common.component.FileService @@ -16,16 +15,17 @@ class UserProfileFacadeV2( private val fileService: FileService, ) { - fun getS3PresignedUrls(userId: Long, presignedUrlsRequest: PresignedUrlsRequest): PresignedUrlsResponse { - return PresignedUrlsResponse( - presignedUrlsRequest.fileNames.mapIndexed { index, fileName -> - val filePath = when (index) { - 0 -> makeFirstPathWithUserId(fileName, userId) - else -> makePathWithUserId(fileName, userId) - } - fileService.getPresignedUrl(filePath, HttpMethod.PUT).toString() - }.toList() - ) + fun getS3PresignedUrls(userId: Long, imageCount: Int): PresignedUrlsResponse { + val presignedUrls = mutableListOf() + for (index in 0 until imageCount) { + val filePath = when (index) { + 0 -> makeFirstPathWithUserId(index, userId) + else -> makePathWithUserId(index, userId) + } + val presignedUrl = fileService.getPresignedUrl(filePath, HttpMethod.PUT).toString() + presignedUrls.add(presignedUrl) + } + return PresignedUrlsResponse(presignedUrls) } fun registerImageUrls(userId: Long, registerImageUrlsRequest: RegisterImageUrlsRequest) { @@ -37,23 +37,23 @@ class UserProfileFacadeV2( } private fun makeFirstPathWithUserId( - fileName: String, + order: Int, userId: Long ): String { val filePath = "${PREFIX_ORIGINAL_IMAGE_MAIN}${userId}${FILE_NAME_DELIMITER}${ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) - }${FILE_NAME_DELIMITER}${fileName}" + }${FILE_NAME_DELIMITER}${order}" return filePath } private fun makePathWithUserId( - fileName: String, + order: Int, userId: Long ): String { val filePath = "${PREFIX_ORIGINAL_IMAGE}${userId}${FILE_NAME_DELIMITER}${ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) - }${FILE_NAME_DELIMITER}${fileName}" + }${FILE_NAME_DELIMITER}${order}" return filePath }