From 8c69a18e751a9f6464657bc3d0403772e80b79a9 Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Wed, 28 Jan 2026 18:18:18 +0530 Subject: [PATCH] Allow card revoke by UUID or cardId --- .../controller/IssuedCards.kt | 19 +++++++++++++++++-- .../trisolarisserver/repo/IssuedCardRepo.kt | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt b/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt index 37ad5cf..1a3a8e4 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt @@ -153,11 +153,11 @@ class IssuedCards( @PostMapping("/cards/{cardId}/revoke") fun revoke( @PathVariable propertyId: UUID, - @PathVariable cardId: UUID, + @PathVariable cardId: String, @AuthenticationPrincipal principal: MyPrincipal? ): CardRevokeResponse { requireRevokeActor(propertyId, principal) - val card = issuedCardRepo.findByIdAndPropertyId(cardId, propertyId) + val card = findCardForRevoke(cardId, propertyId) ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Card not found") if (card.revokedAt == null) { val now = nowForProperty(card.property.timezone) @@ -238,6 +238,21 @@ 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.findByCardIdIgnoreCaseAndPropertyId(trimmed, propertyId) + } + } + private fun nextCardIndex(propertyId: UUID): Int { var counter = counterRepo.findByPropertyIdForUpdate(propertyId) if (counter == null) { diff --git a/src/main/kotlin/com/android/trisolarisserver/repo/IssuedCardRepo.kt b/src/main/kotlin/com/android/trisolarisserver/repo/IssuedCardRepo.kt index bbe34bf..0f4e625 100644 --- a/src/main/kotlin/com/android/trisolarisserver/repo/IssuedCardRepo.kt +++ b/src/main/kotlin/com/android/trisolarisserver/repo/IssuedCardRepo.kt @@ -7,6 +7,7 @@ import java.util.UUID interface IssuedCardRepo : JpaRepository { fun findByRoomStayIdOrderByIssuedAtDesc(roomStayId: UUID): List fun findByIdAndPropertyId(id: UUID, propertyId: UUID): IssuedCard? + fun findByCardIdIgnoreCaseAndPropertyId(cardId: String, propertyId: UUID): IssuedCard? @org.springframework.data.jpa.repository.Query(""" select case when count(c) > 0 then true else false end