Revoke cards by cardIndex and drop cardId uniqueness
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 1m33s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user