Return sector0 time data on card revoke
All checks were successful
build-and-deploy / build-deploy (push) Successful in 3m36s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 3m36s
This commit is contained in:
@@ -3,6 +3,7 @@ package com.android.trisolarisserver.controller
|
|||||||
import com.android.trisolarisserver.component.PropertyAccess
|
import com.android.trisolarisserver.component.PropertyAccess
|
||||||
import com.android.trisolarisserver.controller.dto.CardPrepareRequest
|
import com.android.trisolarisserver.controller.dto.CardPrepareRequest
|
||||||
import com.android.trisolarisserver.controller.dto.CardPrepareResponse
|
import com.android.trisolarisserver.controller.dto.CardPrepareResponse
|
||||||
|
import com.android.trisolarisserver.controller.dto.CardRevokeResponse
|
||||||
import com.android.trisolarisserver.controller.dto.IssueCardRequest
|
import com.android.trisolarisserver.controller.dto.IssueCardRequest
|
||||||
import com.android.trisolarisserver.controller.dto.IssuedCardResponse
|
import com.android.trisolarisserver.controller.dto.IssuedCardResponse
|
||||||
import com.android.trisolarisserver.models.property.Role
|
import com.android.trisolarisserver.models.property.Role
|
||||||
@@ -150,19 +151,23 @@ class IssuedCards(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/cards/{cardId}/revoke")
|
@PostMapping("/cards/{cardId}/revoke")
|
||||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
|
||||||
fun revoke(
|
fun revoke(
|
||||||
@PathVariable propertyId: UUID,
|
@PathVariable propertyId: UUID,
|
||||||
@PathVariable cardId: UUID,
|
@PathVariable cardId: UUID,
|
||||||
@AuthenticationPrincipal principal: MyPrincipal?
|
@AuthenticationPrincipal principal: MyPrincipal?
|
||||||
) {
|
): CardRevokeResponse {
|
||||||
requireRevokeActor(propertyId, principal)
|
requireRevokeActor(propertyId, principal)
|
||||||
val card = issuedCardRepo.findByIdAndPropertyId(cardId, propertyId)
|
val card = issuedCardRepo.findByIdAndPropertyId(cardId, propertyId)
|
||||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Card not found")
|
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Card not found")
|
||||||
if (card.revokedAt == null) {
|
if (card.revokedAt == null) {
|
||||||
card.revokedAt = OffsetDateTime.now()
|
val now = nowForProperty(card.property.timezone)
|
||||||
|
card.revokedAt = now
|
||||||
|
card.expiresAt = now
|
||||||
issuedCardRepo.save(card)
|
issuedCardRepo.save(card)
|
||||||
}
|
}
|
||||||
|
val key = buildSector0Block2(card.room.roomNumber, card.cardIndex)
|
||||||
|
val timeData = buildSector0TimeData(card.issuedAt, card.expiresAt, key)
|
||||||
|
return CardRevokeResponse(timeData = timeData)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseOffset(value: String?): OffsetDateTime? {
|
private fun parseOffset(value: String?): OffsetDateTime? {
|
||||||
@@ -259,12 +264,20 @@ class IssuedCards(
|
|||||||
expiresAt: OffsetDateTime
|
expiresAt: OffsetDateTime
|
||||||
): Sector0Payload {
|
): Sector0Payload {
|
||||||
val key = buildSector0Block2(roomNumber, cardIndex)
|
val key = buildSector0Block2(roomNumber, cardIndex)
|
||||||
val newData = "0000000000" + formatDateComponents(issuedAt) + formatDateComponents(expiresAt)
|
val finalData = buildSector0TimeData(issuedAt, expiresAt, key)
|
||||||
val checkSum = calculateChecksum(key + newData)
|
|
||||||
val finalData = newData + checkSum
|
|
||||||
return Sector0Payload(key, finalData)
|
return Sector0Payload(key, finalData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildSector0TimeData(
|
||||||
|
issuedAt: OffsetDateTime,
|
||||||
|
expiresAt: OffsetDateTime,
|
||||||
|
key: String? = null
|
||||||
|
): String {
|
||||||
|
val newData = "0000000000" + formatDateComponents(issuedAt) + formatDateComponents(expiresAt)
|
||||||
|
val checkSum = calculateChecksum((key ?: "") + newData)
|
||||||
|
return newData + checkSum
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildSector0Block2(roomNumber: Int, cardID: Int): String {
|
private fun buildSector0Block2(roomNumber: Int, cardID: Int): String {
|
||||||
val guestID = cardID + 1
|
val guestID = cardID + 1
|
||||||
val cardIdStr = cardID.toString().padStart(6, '0')
|
val cardIdStr = cardID.toString().padStart(6, '0')
|
||||||
|
|||||||
@@ -86,3 +86,7 @@ data class CardPrepareResponse(
|
|||||||
val sector3Block1: String? = null,
|
val sector3Block1: String? = null,
|
||||||
val sector3Block2: String? = null
|
val sector3Block2: String? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class CardRevokeResponse(
|
||||||
|
val timeData: String
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user