Skip to content

Commit

Permalink
[REFACTOR] #75 - pre-signed url 호출하는 API를 프로필, 포스트 이미지 따로
Browse files Browse the repository at this point in the history
  • Loading branch information
jung0115 committed Aug 14, 2024
1 parent c387577 commit c327f59
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import retrofit2.http.Query

interface PreSignedUrlDataSource {
@GET("/api/v1/posts/preSignedUrl")
suspend fun getPreSignedUrl(
suspend fun getPreSignedPostUrl(
@Query("extension") extension: String = "jpeg" // 확장자
) : PreSignedUrlDTO

@GET("/api/v1/profileImage/preSignedUrl")
suspend fun getPreSignedProfileUrl(
@Query("extension") extension: String = "jpeg" // 확장자
) : PreSignedUrlDTO
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,36 @@ class PreSignedUrlRepositoryImpl @Inject constructor(
private val preSignedUrlDataSource: PreSignedUrlDataSource,
private val putImageS3DataSource: PutImageS3DataSource,
) : PreSignedUrlRepository {
override suspend fun getPreSignedUrl(imageLocalUri: Any): String? {
override suspend fun getPreSignedPostUrl(imageLocalUri: Any): String? {
try {
val preSignedUrlResponse = preSignedUrlDataSource.getPreSignedUrl()
val preSignedUrlResponse = preSignedUrlDataSource.getPreSignedPostUrl()

val imageFile = FormDataUtil.convertUriToRequestBody(context, imageLocalUri)

if (imageFile == null) {
Toast.makeText(context, "손상된 이미지입니다.", Toast.LENGTH_SHORT).show()
return null
} else {
try {
putImageS3DataSource.putImageForS3(
preSignedUrlResponse.url,
imageFile
)

val imageUrl: String = preSignedUrlResponse.url.split("?")[0]
return imageUrl
} catch (e: Exception) {
return null
}
}
} catch (e: Exception) {
return null
}
}

override suspend fun getPreSignedProfileUrl(imageLocalUri: Any): String? {
try {
val preSignedUrlResponse = preSignedUrlDataSource.getPreSignedProfileUrl()

val imageFile = FormDataUtil.convertUriToRequestBody(context, imageLocalUri)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.swmarastro.mykkumi.domain.repository

interface PreSignedUrlRepository {
suspend fun getPreSignedUrl(imageLocalUri: Any): String?
suspend fun getPreSignedPostUrl(imageLocalUri: Any): String?
suspend fun getPreSignedProfileUrl(imageLocalUri: Any): String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class LoginComposeActivity : ComponentActivity() {
.background(colorResource(id = com.swmarastro.mykkumi.common_ui.R.color.kakao_background))
.pointerInteropFilter {
when (it.action) {
MotionEvent.ACTION_DOWN -> navController.navigate(route = LoginScreens.LoginSelectHobbyScreen.name)//handleKakaoLogin()
MotionEvent.ACTION_DOWN -> handleKakaoLogin()
else -> false
}
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class LoginInputUserViewModel @Inject constructor(
try {
var imageUrl: String? = null
if(profileImage.value != null)
imageUrl = preSignedUrlRepository.getPreSignedUrl(profileImage.value as Uri)
imageUrl = preSignedUrlRepository.getPreSignedProfileUrl(profileImage.value as Uri)

val userInfo = UpdateUserInfoRequestVO(
nickname = nickname.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PostEditViewModel @Inject constructor(
fun selectPostImage(uri: Uri) {
viewModelScope.launch {
try {
val imageUrl = preSignedUrlRepository.getPreSignedUrl(uri)
val imageUrl = preSignedUrlRepository.getPreSignedPostUrl(uri)

if(imageUrl != null) {
val addPostImages = _postEditUiState.value
Expand Down

0 comments on commit c327f59

Please sign in to comment.