-
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: UrlConverter 에게 url 변환 로직 위임
- Loading branch information
Showing
3 changed files
with
46 additions
and
5 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
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/petqua/application/image/UrlConverter.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,26 @@ | ||
package com.petqua.application.image | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class UrlConverter( | ||
@Value("\${image.common.domain}") | ||
private val domain: String, | ||
) { | ||
|
||
fun convertToAccessibleUrl(filePath: String, storedUrl: String): String { | ||
/* | ||
* example) | ||
* filePath = "root/directory/image.jpeg" | ||
* storedUrl = "https://storedUrl.com/root/directory/image.jpeg" | ||
* | ||
* pathIndex = 21 | ||
* storedPath = "/root/directory/image.jpeg" | ||
* return "https://domain.com/root/directory/image.jpeg" | ||
* */ | ||
val pathIndex = storedUrl.indexOf("/$filePath") | ||
val storedPath = storedUrl.substring(pathIndex) | ||
return "$domain$storedPath" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/kotlin/com/petqua/application/image/UrlConverterTest.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,18 @@ | ||
package com.petqua.application.image | ||
|
||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class UrlConverterTest : StringSpec({ | ||
|
||
"파일 경로와 파일이 저장된 url 을 입력해 접근 가능한 url로 변환한다" { | ||
val domainUrl = "https://domain.com" | ||
val filePath = "root/directory/image.jpeg" | ||
val storedUrl = "https://storedUrl.com/root/directory/image.jpeg" | ||
val urlConverter = UrlConverter(domainUrl) | ||
|
||
val accessibleUrl = urlConverter.convertToAccessibleUrl(filePath, storedUrl) | ||
|
||
accessibleUrl shouldBe "https://domain.com/root/directory/image.jpeg" | ||
} | ||
}) |