Randomize property codes with 7-char alphabet
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s
This commit is contained in:
@@ -39,6 +39,8 @@ class Properties(
|
|||||||
private val propertyUserRepo: PropertyUserRepo,
|
private val propertyUserRepo: PropertyUserRepo,
|
||||||
private val appUserRepo: AppUserRepo
|
private val appUserRepo: AppUserRepo
|
||||||
) {
|
) {
|
||||||
|
private val codeRandom = java.security.SecureRandom()
|
||||||
|
private val codeAlphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
|
||||||
|
|
||||||
@PostMapping("/properties")
|
@PostMapping("/properties")
|
||||||
@ResponseStatus(HttpStatus.CREATED)
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
@@ -277,8 +279,12 @@ class Properties(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generatePropertyCode(): String {
|
private fun generatePropertyCode(): String {
|
||||||
repeat(10) {
|
repeat(200) {
|
||||||
val code = "HOTE" + (100..999).random()
|
val code = buildString(7) {
|
||||||
|
repeat(7) {
|
||||||
|
append(codeAlphabet[codeRandom.nextInt(codeAlphabet.length)])
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!propertyRepo.existsByCode(code)) {
|
if (!propertyRepo.existsByCode(code)) {
|
||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user