Add card lookup by cardIndex
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s

This commit is contained in:
androidlover5842
2026-01-28 20:05:53 +05:30
parent 10f79da44b
commit 7b72dd45e3

View File

@@ -171,6 +171,18 @@ class IssuedCards(
return CardRevokeResponse(timeData = timeData) 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? { private fun parseOffset(value: String?): OffsetDateTime? {
if (value.isNullOrBlank()) return null if (value.isNullOrBlank()) return null
return try { 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 { private fun nextCardIndex(propertyId: UUID): Int {
var counter = counterRepo.findByPropertyIdForUpdate(propertyId) var counter = counterRepo.findByPropertyIdForUpdate(propertyId)