Randomize property codes with 7-char alphabet
All checks were successful
build-and-deploy / build-deploy (push) Successful in 34s

This commit is contained in:
androidlover5842
2026-02-01 23:00:03 +05:30
parent 5df019ed6e
commit 0a11e765ad

View File

@@ -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
}