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 appUserRepo: AppUserRepo
|
||||
) {
|
||||
private val codeRandom = java.security.SecureRandom()
|
||||
private val codeAlphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
|
||||
|
||||
@PostMapping("/properties")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
@@ -277,8 +279,12 @@ class Properties(
|
||||
}
|
||||
|
||||
private fun generatePropertyCode(): String {
|
||||
repeat(10) {
|
||||
val code = "HOTE" + (100..999).random()
|
||||
repeat(200) {
|
||||
val code = buildString(7) {
|
||||
repeat(7) {
|
||||
append(codeAlphabet[codeRandom.nextInt(codeAlphabet.length)])
|
||||
}
|
||||
}
|
||||
if (!propertyRepo.existsByCode(code)) {
|
||||
return code
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user