Add card lookup by cardIndex
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user