diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/dto/property/OrgPropertyDtos.kt b/src/main/kotlin/com/android/trisolarisserver/controller/dto/property/OrgPropertyDtos.kt index 1bd074c..0cdf927 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/dto/property/OrgPropertyDtos.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/dto/property/OrgPropertyDtos.kt @@ -38,6 +38,11 @@ data class PropertyResponse( val allowedTransportModes: Set ) +data class PropertyCodeResponse( + val propertyId: UUID, + val code: String +) + data class GuestResponse( val id: UUID, val name: String?, diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/property/Properties.kt b/src/main/kotlin/com/android/trisolarisserver/controller/property/Properties.kt index e7233d6..443bd3c 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/property/Properties.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/property/Properties.kt @@ -4,6 +4,7 @@ import com.android.trisolarisserver.controller.common.requirePrincipal import com.android.trisolarisserver.controller.common.requireUser import com.android.trisolarisserver.component.auth.PropertyAccess +import com.android.trisolarisserver.controller.dto.property.PropertyCodeResponse import com.android.trisolarisserver.controller.dto.property.PropertyCreateRequest import com.android.trisolarisserver.controller.dto.property.PropertyResponse import com.android.trisolarisserver.controller.dto.property.PropertyUserDisableRequest @@ -93,6 +94,19 @@ class Properties( } } + @GetMapping("/properties/{propertyId}/code") + fun getPropertyCode( + @PathVariable propertyId: UUID, + @AuthenticationPrincipal principal: MyPrincipal? + ): PropertyCodeResponse { + requirePrincipal(principal) + propertyAccess.requireMember(propertyId, principal!!.userId) + val property = propertyRepo.findById(propertyId).orElseThrow { + ResponseStatusException(HttpStatus.NOT_FOUND, "Property not found") + } + return PropertyCodeResponse(propertyId = property.id!!, code = property.code) + } + @GetMapping("/properties/{propertyId}/users") fun listPropertyUsers( @PathVariable propertyId: UUID, @@ -279,7 +293,7 @@ class Properties( } private fun generatePropertyCode(): String { - repeat(200) { + repeat(10) { val code = buildString(7) { repeat(7) { append(codeAlphabet[codeRandom.nextInt(codeAlphabet.length)])