-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 이름 생성 공통 로직 ObjectPathGenerator로 통일
- Loading branch information
1 parent
af75f56
commit 133166d
Showing
3 changed files
with
32 additions
and
30 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
28 changes: 28 additions & 0 deletions
28
api/src/main/kotlin/com/few/api/domain/admin/document/utils/ObjectPathGenerator.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,28 @@ | ||
package com.few.api.domain.admin.document.utils | ||
|
||
import java.time.LocalDate | ||
import kotlin.random.Random | ||
|
||
object ObjectPathGenerator { | ||
|
||
fun imagePath(suffix: String): String { | ||
val dateDir = LocalDate.now().toString() | ||
return "images/$dateDir/${generateImageName()}" + ".$suffix" | ||
} | ||
|
||
fun documentPath(suffix: String): String { | ||
val dateDir = LocalDate.now().toString() | ||
return "documents/$dateDir/${generateImageName()}" + ".$suffix" | ||
} | ||
|
||
private fun generateImageName(): String { | ||
return randomString() | ||
} | ||
|
||
private fun randomString(): String { | ||
val charPool: List<Char> = ('a'..'z') + ('A'..'Z') + ('0'..'9') | ||
return (1..16) | ||
.map { Random.nextInt(0, charPool.size).let { charPool[it] } } | ||
.joinToString("") | ||
} | ||
} |