Skip to content

Commit

Permalink
[Fix/534] S3 presigned url 발급받는 api 수정한다 (#535)
Browse files Browse the repository at this point in the history
* fix: presigned url 발급 api 수정

* fix: request dto 제거
  • Loading branch information
miseongk authored Oct 27, 2024
1 parent c965de8 commit a63de75
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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
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
Expand All @@ -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 저장하기")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<String>()
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) {
Expand All @@ -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
}
Expand Down

This file was deleted.

0 comments on commit a63de75

Please sign in to comment.