From 7b72dd45e396c7df714bdf79bc924193c915eec8 Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Wed, 28 Jan 2026 20:05:53 +0530 Subject: [PATCH] Add card lookup by cardIndex --- .../controller/IssuedCards.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt b/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt index d6dacf2..7041119 100644 --- a/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt +++ b/src/main/kotlin/com/android/trisolarisserver/controller/IssuedCards.kt @@ -171,6 +171,18 @@ class IssuedCards( return CardRevokeResponse(timeData = timeData) } + @GetMapping("/cards/{cardIndex}") + fun getCardByIndex( + @PathVariable propertyId: UUID, + @PathVariable cardIndex: Int, + @AuthenticationPrincipal principal: MyPrincipal? + ): IssuedCardResponse { + requireCardAdminActor(propertyId, principal) + val card = issuedCardRepo.findByPropertyIdAndCardIndex(propertyId, cardIndex) + ?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Card not found") + return card.toResponse() + } + private fun parseOffset(value: String?): OffsetDateTime? { if (value.isNullOrBlank()) return null return try { @@ -243,6 +255,14 @@ class IssuedCards( } } + private fun requireCardAdminActor(propertyId: UUID, principal: MyPrincipal?) { + if (principal == null) { + throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "Missing principal") + } + propertyAccess.requireMember(propertyId, principal.userId) + propertyAccess.requireAnyRole(propertyId, principal.userId, Role.ADMIN, Role.MANAGER) + } + private fun nextCardIndex(propertyId: UUID): Int { var counter = counterRepo.findByPropertyIdForUpdate(propertyId)