Use property timezone for card issued times
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:
@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.ZoneId
|
||||
import java.util.UUID
|
||||
|
||||
@RestController
|
||||
@@ -58,7 +59,7 @@ class IssuedCards(
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Room stay closed")
|
||||
}
|
||||
|
||||
val issuedAt = OffsetDateTime.now()
|
||||
val issuedAt = nowForProperty(stay.property.timezone)
|
||||
val expiresAt = request.expiresAt?.let { parseOffset(it) } ?: stay.toAt
|
||||
?: throw ResponseStatusException(HttpStatus.BAD_REQUEST, "expiresAt required")
|
||||
if (!expiresAt.isAfter(issuedAt)) {
|
||||
@@ -101,7 +102,7 @@ class IssuedCards(
|
||||
if (stay.toAt != null) {
|
||||
throw ResponseStatusException(HttpStatus.CONFLICT, "Room stay closed")
|
||||
}
|
||||
val issuedAt = parseOffset(request.issuedAt) ?: OffsetDateTime.now()
|
||||
val issuedAt = parseOffset(request.issuedAt) ?: nowForProperty(stay.property.timezone)
|
||||
val expiresAt = parseOffset(request.expiresAt)
|
||||
?: throw ResponseStatusException(HttpStatus.BAD_REQUEST, "expiresAt required")
|
||||
if (!expiresAt.isAfter(issuedAt)) {
|
||||
@@ -170,6 +171,15 @@ class IssuedCards(
|
||||
}
|
||||
}
|
||||
|
||||
private fun nowForProperty(timezone: String?): OffsetDateTime {
|
||||
val zone = try {
|
||||
if (timezone.isNullOrBlank()) ZoneId.of("Asia/Kolkata") else ZoneId.of(timezone)
|
||||
} catch (_: Exception) {
|
||||
ZoneId.of("Asia/Kolkata")
|
||||
}
|
||||
return OffsetDateTime.now(zone)
|
||||
}
|
||||
|
||||
private fun requireMember(propertyId: UUID, principal: MyPrincipal?) {
|
||||
if (principal == null) {
|
||||
throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "Missing principal")
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.ResponseStatus
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.ZoneId
|
||||
import java.util.UUID
|
||||
|
||||
@RestController
|
||||
@@ -49,7 +50,7 @@ class TemporaryRoomCards(
|
||||
val room = roomRepo.findByIdAndPropertyId(roomId, propertyId)
|
||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room not found")
|
||||
|
||||
val issuedAt = OffsetDateTime.now()
|
||||
val issuedAt = nowForProperty(room.property.timezone)
|
||||
val expiresAt = issuedAt.plusMinutes(temporaryCardDurationMinutes)
|
||||
val cardIndex = nextCardIndex(propertyId)
|
||||
val payload = buildSector0Payload(room.roomNumber, cardIndex, issuedAt, expiresAt)
|
||||
@@ -81,7 +82,7 @@ class TemporaryRoomCards(
|
||||
val room = roomRepo.findByIdAndPropertyId(roomId, propertyId)
|
||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Room not found")
|
||||
|
||||
val issuedAt = parseOffset(request.issuedAt) ?: OffsetDateTime.now()
|
||||
val issuedAt = parseOffset(request.issuedAt) ?: nowForProperty(room.property.timezone)
|
||||
val expiresAt = issuedAt.plusMinutes(temporaryCardDurationMinutes)
|
||||
val now = OffsetDateTime.now()
|
||||
if (issuedCardRepo.existsActiveForRoom(propertyId, room.id!!, now)) {
|
||||
@@ -110,6 +111,15 @@ class TemporaryRoomCards(
|
||||
}
|
||||
}
|
||||
|
||||
private fun nowForProperty(timezone: String?): OffsetDateTime {
|
||||
val zone = try {
|
||||
if (timezone.isNullOrBlank()) ZoneId.of("Asia/Kolkata") else ZoneId.of(timezone)
|
||||
} catch (_: Exception) {
|
||||
ZoneId.of("Asia/Kolkata")
|
||||
}
|
||||
return OffsetDateTime.now(zone)
|
||||
}
|
||||
|
||||
private fun requireIssueActor(propertyId: UUID, principal: MyPrincipal?): com.android.trisolarisserver.models.property.AppUser {
|
||||
if (principal == null) {
|
||||
throw ResponseStatusException(HttpStatus.UNAUTHORIZED, "Missing principal")
|
||||
|
||||
Reference in New Issue
Block a user