-
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.
Refactor | CAKK-62 | external 모듈 kt 전환
* Rename .java to .kt * Refactor | CAKK-62 | kotlin으로 전환 * Test | CAKK-62 | 테스트 코드 수정
- Loading branch information
Showing
9 changed files
with
126 additions
and
155 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
46 changes: 0 additions & 46 deletions
46
cakk-external/src/main/java/com/cakk/external/config/S3Config.java
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
cakk-external/src/main/java/com/cakk/external/config/S3Config.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,33 @@ | ||
package com.cakk.external.config | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.context.annotation.Primary | ||
|
||
import com.amazonaws.auth.AWSStaticCredentialsProvider | ||
import com.amazonaws.auth.BasicAWSCredentials | ||
import com.amazonaws.services.s3.AmazonS3 | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder | ||
|
||
@Configuration | ||
class S3Config( | ||
@Value("\${cloud.aws.credentials.access-key}") private val accessKey: String, | ||
@Value("\${cloud.aws.credentials.secret-key}") private val secretKey: String, | ||
@Value("\${cloud.aws.region.static}") private val region: String | ||
) { | ||
@Bean | ||
@Primary | ||
fun awsCredentialsProvider(): BasicAWSCredentials { | ||
return BasicAWSCredentials(accessKey, secretKey) | ||
} | ||
|
||
@Bean | ||
fun amazonS3(): AmazonS3 { | ||
return AmazonS3ClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(AWSStaticCredentialsProvider(awsCredentialsProvider())) | ||
.build() | ||
} | ||
} | ||
|
84 changes: 0 additions & 84 deletions
84
cakk-external/src/main/java/com/cakk/external/service/S3Service.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
cakk-external/src/main/java/com/cakk/external/service/S3Service.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,70 @@ | ||
package com.cakk.external.service | ||
|
||
import java.util.* | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
|
||
import com.amazonaws.AmazonServiceException | ||
import com.amazonaws.HttpMethod | ||
import com.amazonaws.SdkClientException | ||
import com.amazonaws.services.s3.AmazonS3 | ||
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest | ||
|
||
import com.cakk.common.enums.ReturnCode | ||
import com.cakk.common.exception.CakkException | ||
import com.cakk.external.vo.PresignedUrl | ||
|
||
@Service | ||
class S3Service( | ||
private val amazonS3: AmazonS3, | ||
@Value("\${cloud.aws.s3.bucket}") private val bucket: String, | ||
@Value("\${cloud.aws.s3.expire-in}") private val expiredIn: String, | ||
@Value("\${cloud.aws.s3.object-key}") private val objectKey: String | ||
) { | ||
|
||
fun getPresignedUrlWithImagePath(): PresignedUrl { | ||
try { | ||
val imagePath = makeObjectKey() | ||
val imageUrl = getImageUrl(imagePath) | ||
val generatePresignedUrlRequest = createGeneratePresignedUrlRequestInstance(imagePath) | ||
val presignedUrl = generatePresignedUrlRequest(generatePresignedUrlRequest) | ||
|
||
return PresignedUrl(imagePath, imageUrl, presignedUrl) | ||
} catch (e: SdkClientException) { | ||
throw CakkException(ReturnCode.EXTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
fun deleteObject(imagePath: String) { | ||
try { | ||
amazonS3.deleteObject(bucket, imagePath) | ||
} catch (e: AmazonServiceException) { | ||
throw CakkException(ReturnCode.EXTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
|
||
private fun createGeneratePresignedUrlRequestInstance(imagePath: String): GeneratePresignedUrlRequest { | ||
val expiration = Date() | ||
var expirationInMs = expiration.time | ||
expirationInMs += expiredIn.toLong() | ||
expiration.time = expirationInMs | ||
|
||
return GeneratePresignedUrlRequest(bucket, imagePath) | ||
.withMethod(HttpMethod.PUT) | ||
.withExpiration(expiration) | ||
} | ||
|
||
private fun generatePresignedUrlRequest(generatePresignedUrlRequest: GeneratePresignedUrlRequest): String { | ||
return amazonS3.generatePresignedUrl(generatePresignedUrlRequest).toString() | ||
} | ||
|
||
private fun makeObjectKey(): String { | ||
return StringBuffer().append(objectKey).append("/").append(UUID.randomUUID()).append(".jpeg").toString() | ||
} | ||
|
||
private fun getImageUrl(imagePath: String): String { | ||
return amazonS3.getUrl(bucket, imagePath).toString() | ||
} | ||
} | ||
|
14 changes: 0 additions & 14 deletions
14
cakk-external/src/main/java/com/cakk/external/vo/CertificationMessage.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
cakk-external/src/main/java/com/cakk/external/vo/CertificationMessage.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,13 @@ | ||
package com.cakk.external.vo | ||
|
||
data class CertificationMessage( | ||
val businessRegistrationImageUrl: String, | ||
val idCardImageUrl: String, | ||
val emergencyContact: String, | ||
val message: String, | ||
val userId: Long, | ||
val userEmail: String, | ||
val shopName: String, | ||
val latitude: Double, | ||
val longitude: Double | ||
) |
8 changes: 0 additions & 8 deletions
8
cakk-external/src/main/java/com/cakk/external/vo/PresignedUrl.java
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
cakk-external/src/main/java/com/cakk/external/vo/PresignedUrl.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,7 @@ | ||
package com.cakk.external.vo | ||
|
||
data class PresignedUrl( | ||
val imagePath: String, | ||
val imageUrl: String, | ||
val presignedUrl: String | ||
) |