Revoke cards by cardIndex and drop cardId uniqueness
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s

This commit is contained in:
androidlover5842
2026-01-28 18:24:40 +05:30
parent 914d824e51
commit 385a66d5c5
3 changed files with 7 additions and 39 deletions

View File

@@ -150,14 +150,14 @@ class IssuedCards(
.map { it.toResponse() }
}
@PostMapping("/cards/{cardId}/revoke")
@PostMapping("/cards/{cardIndex}/revoke")
fun revoke(
@PathVariable propertyId: UUID,
@PathVariable cardId: String,
@PathVariable cardIndex: Int,
@AuthenticationPrincipal principal: MyPrincipal?
): CardRevokeResponse {
requireRevokeActor(propertyId, principal)
val card = findCardForRevoke(cardId, propertyId)
val card = issuedCardRepo.findByPropertyIdAndCardIndex(propertyId, cardIndex)
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Card not found")
if (card.revokedAt == null) {
val now = nowForProperty(card.property.timezone)
@@ -238,21 +238,6 @@ class IssuedCards(
propertyAccess.requireAnyRole(propertyId, principal.userId, Role.ADMIN)
}
private fun findCardForRevoke(cardId: String, propertyId: UUID): IssuedCard? {
val trimmed = cardId.trim()
if (trimmed.isBlank()) return null
val uuid = try {
java.util.UUID.fromString(trimmed)
} catch (_: Exception) {
null
}
return if (uuid != null) {
issuedCardRepo.findByIdAndPropertyId(uuid, propertyId)
} else {
issuedCardRepo.findAllByCardIdIgnoreCaseAndPropertyId(trimmed, propertyId)
.maxByOrNull { it.issuedAt }
}
}
private fun nextCardIndex(propertyId: UUID): Int {
var counter = counterRepo.findByPropertyIdForUpdate(propertyId)