-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: presigned url 발급 api 구현 및 balance 등록 api request 수정
- Loading branch information
Showing
25 changed files
with
273 additions
and
62 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
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
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/balancemania/api/balance/model/request/CreateBalanceRequest.kt
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package com.balancemania.api.balance.model.request | ||
|
||
data class CreateBalanceRequest( | ||
val frontImgUrl: String, | ||
val sideImgUrl: String, | ||
val frontImgKey: String, | ||
val sideImgKey: String, | ||
val leftWeight: Float, | ||
val rightWeight: Float, | ||
) |
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
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/balancemania/api/client/mediapipe/MediaPipeClient.kt
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.balancemania.api.client.mediapipe | ||
|
||
import com.balancemania.api.client.mediapipe.model.MediaPipeImgAnalysisRequest | ||
import com.balancemania.api.client.mediapipe.model.MediaPipeImgAnalysisResponse | ||
|
||
interface MediaPipeClient { | ||
suspend fun getImgAnalysis( | ||
frontImgUrl: String, | ||
sideImgUrl: String, | ||
body: MediaPipeImgAnalysisRequest | ||
): MediaPipeImgAnalysisResponse | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/balancemania/api/client/mediapipe/model/MediaPipeImgAnalysisRequest.kt
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,8 @@ | ||
package com.balancemania.api.client.mediapipe.model | ||
|
||
data class MediaPipeImgAnalysisRequest( | ||
/** 정면 사진 키 */ | ||
val frontImgKey: String, | ||
/** 측면 사진 키 */ | ||
val sideImgKey: String, | ||
) |
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,18 @@ | ||
package com.balancemania.api.config | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider | ||
import software.amazon.awssdk.regions.Region | ||
import software.amazon.awssdk.services.s3.presigner.S3Presigner | ||
|
||
@Configuration | ||
class S3Config { | ||
@Bean | ||
fun s3Presigner(): S3Presigner { | ||
return S3Presigner.builder() | ||
.credentialsProvider(DefaultCredentialsProvider.create()) | ||
.region(Region.AP_NORTHEAST_2) | ||
.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
23 changes: 19 additions & 4 deletions
23
...mania/api/config/swagger/SwaggerConfig.kt → ...nia/api/config/swagger/SpringDocConfig.kt
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
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/balancemania/api/s3/application/S3Facade.kt
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,23 @@ | ||
package com.balancemania.api.s3.application | ||
|
||
import com.balancemania.api.auth.model.AuthUser | ||
import com.balancemania.api.extension.toCurrentZone | ||
import com.balancemania.api.s3.model.ImageType | ||
import com.balancemania.api.s3.model.response.S3PresignedUrlResponse | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class S3Facade( | ||
private val s3PresignedUrlService: S3PresignedUrlService, | ||
) { | ||
suspend fun getPresignedUrl(user: AuthUser, imgType: ImageType): S3PresignedUrlResponse { | ||
return s3PresignedUrlService.generatePresignedUrl(user, imgType) | ||
.let { model -> | ||
S3PresignedUrlResponse( | ||
url = model.url, | ||
exp = model.exp.toCurrentZone(), | ||
key = model.key | ||
) | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/kotlin/com/balancemania/api/s3/application/S3PresignedUrlService.kt
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,57 @@ | ||
package com.balancemania.api.s3.application | ||
|
||
import com.balancemania.api.auth.model.AuthUser | ||
import com.balancemania.api.s3.model.ImageType | ||
import com.balancemania.api.s3.model.S3PresignedUrlModel | ||
import io.awspring.cloud.s3.ObjectMetadata | ||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
import software.amazon.awssdk.services.s3.model.ObjectCannedACL | ||
import software.amazon.awssdk.services.s3.model.PutObjectRequest | ||
import software.amazon.awssdk.services.s3.presigner.S3Presigner | ||
import software.amazon.awssdk.services.s3.presigner.model.PutObjectPresignRequest | ||
import java.time.Duration | ||
import java.util.UUID | ||
|
||
@Service | ||
class S3PresignedUrlService( | ||
@Value("\${spring.cloud.aws.s3.bucket}") | ||
private val bucket: String, | ||
private val s3Presigner: S3Presigner, | ||
) { | ||
companion object { | ||
/** 5분 */ | ||
const val PRESIGNED_EXP_TIME = 5L | ||
} | ||
|
||
val logger = KotlinLogging.logger { } | ||
|
||
suspend fun generatePresignedUrl(user: AuthUser, imageType: ImageType): S3PresignedUrlModel { | ||
val fileName = "${user.uid}/${UUID.randomUUID()}.${imageType.type}" | ||
|
||
val metadata = ObjectMetadata.builder() | ||
.acl(ObjectCannedACL.PUBLIC_READ) | ||
.build() | ||
|
||
val putObjectRequest = PutObjectRequest.builder() | ||
.key(fileName) | ||
.contentType("image/${imageType.type}") | ||
.bucket(bucket) | ||
.metadata(metadata.metadata) | ||
.build() | ||
|
||
val preSignRequest = PutObjectPresignRequest.builder() | ||
.signatureDuration(Duration.ofMinutes(PRESIGNED_EXP_TIME)) | ||
.putObjectRequest(putObjectRequest) | ||
.build() | ||
|
||
val presignedRequest = s3Presigner.presignPutObject(preSignRequest) | ||
|
||
return S3PresignedUrlModel( | ||
url = presignedRequest.url().toString(), | ||
exp = presignedRequest.expiration(), | ||
key = fileName | ||
) | ||
} | ||
} |
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,9 @@ | ||
package com.balancemania.api.s3.model | ||
|
||
enum class ImageType(val type: String) { | ||
JPEG("jpeg"), | ||
PNG("png"), | ||
JPG("jpeg"), | ||
|
||
; | ||
} |
Oops, something went wrong.