Skip to content

Commit

Permalink
Add new TokenCollectorStatus to indicate that a token is inactive, ad…
Browse files Browse the repository at this point in the history
…d default value to column
  • Loading branch information
Isti01 authored and Tschonti committed Mar 16, 2024
1 parent 8dd95d4 commit 967071e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class TokenCollectorService(
val tokenEntity = tokenRepository.findAllByTokenAndVisibleTrue(token).firstOrNull()
if (tokenEntity != null) {
if (!isTokenActive(tokenEntity)) {
return TokenSubmittedView(TokenCollectorStatus.CANNOT_COLLECT, null, null, null)
return TokenSubmittedView(TokenCollectorStatus.INACTIVE, null, null, null)
}
val userEntity = userService.getById(user.internalId)
return qrFightService
Expand All @@ -67,7 +67,7 @@ open class TokenCollectorService(
val tokenEntity = tokenRepository.findAllByTokenAndVisibleTrue(token).firstOrNull()
if (tokenEntity != null) {
if (!isTokenActive(tokenEntity)) {
return TokenSubmittedView(TokenCollectorStatus.CANNOT_COLLECT, null, null, null)
return TokenSubmittedView(TokenCollectorStatus.INACTIVE, null, null, null)
}
return qrFightService
.filter { qrFightComponent.map { it.enabled.isValueTrue() }.orElse(false) }
Expand Down Expand Up @@ -149,11 +149,13 @@ open class TokenCollectorService(
)
}

private fun isTokenActive(tokenEntity: TokenEntity): Boolean {
val now = clock.getTimeInSeconds()
return (tokenEntity.availableFrom == null || tokenEntity.availableFrom!! <= now) &&
(tokenEntity.availableUntil == null || tokenEntity.availableUntil!! >= now)
}
private fun isTokenActive(tokenEntity: TokenEntity): Boolean =
clock.inRange(
tokenEntity.availableFrom ?: 0,
tokenEntity.availableUntil ?: Long.MAX_VALUE,
clock.getTimeInSeconds(),
)


private fun fetchTotalTokenCount(tokenCategoryToDisplay: String) =
if (tokenCategoryToDisplay == ALL_TOKEN_TYPE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ enum class TokenCollectorStatus {
ALREADY_SCANNED,
WRONG,
CANNOT_COLLECT,
INACTIVE,
QR_FIGHT_LEVEL_NOT_OPEN,
QR_FIGHT_LEVEL_LOCKED,
QR_FIGHT_TOWER_LOCKED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ data class TokenEntity(
var displayDescription: String = "",

@field:JsonView(value = [ Edit::class, Preview::class, FullDetails::class ])
@Column(nullable = true)
@Column(nullable = true, columnDefinition = "BIGINT DEFAULT NULL")
@property:GenerateInput(type = INPUT_TYPE_DATE, order = 11, label = "Scannelhető innentől")
@property:GenerateOverview(columnName = "Ettől", order = 5, renderer = OVERVIEW_TYPE_DATE)
@property:ImportFormat(ignore = false, type = IMPORT_LONG)
var availableFrom: Long? = null,

@field:JsonView(value = [ Edit::class, Preview::class, FullDetails::class ])
@Column(nullable = true)
@Column(nullable = true, columnDefinition = "BIGINT DEFAULT NULL")
@property:GenerateInput(type = INPUT_TYPE_DATE, order = 12, label = "Scannelhető eddig")
@property:GenerateOverview(columnName = "Eddig", order = 6, renderer = OVERVIEW_TYPE_DATE)
@property:ImportFormat(ignore = false, type = IMPORT_LONG)
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/token/components/QRScanResultComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const QRScanResultComponent = ({ response, isError }: QrScanResultProps)
return <WarningTwoIcon color="yellow.500" boxSize="120px" />
case ScanStatus.CANNOT_COLLECT:
return <WarningTwoIcon color="yellow.500" boxSize="120px" />
case ScanStatus.INACTIVE:
return <WarningTwoIcon color="yellow.500" boxSize="120px" />
case ScanStatus.QR_FIGHT_LEVEL_LOCKED:
return <InfoIcon color="orange.500" boxSize="120px" />
case ScanStatus.QR_FIGHT_LEVEL_NOT_OPEN:
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/util/views/token.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum ScanStatus {
ALREADY_SCANNED = 'ALREADY_SCANNED',
WRONG = 'WRONG',
CANNOT_COLLECT = 'CANNOT_COLLECT',
INACTIVE = 'INACTIVE',
QR_FIGHT_LEVEL_NOT_OPEN = 'QR_FIGHT_LEVEL_NOT_OPEN',
QR_FIGHT_LEVEL_LOCKED = 'QR_FIGHT_LEVEL_LOCKED',
QR_FIGHT_TOWER_LOCKED = 'QR_FIGHT_TOWER_LOCKED',
Expand All @@ -35,6 +36,7 @@ export const ScanMessages: Record<ScanStatus, string> = {
[ScanStatus.ALREADY_SCANNED]: 'Már beolvasott QR',
[ScanStatus.WRONG]: 'Rossz QR',
[ScanStatus.CANNOT_COLLECT]: 'Nem lehet megszerezni ezt a QR-t',
[ScanStatus.INACTIVE]: 'Ez a QR jelenleg nem aktív',
[ScanStatus.QR_FIGHT_LEVEL_NOT_OPEN]: 'Ez a QR harc szint még nincs megnyitva',
[ScanStatus.QR_FIGHT_LEVEL_LOCKED]: 'Ez a QR harc szint zárva van',
[ScanStatus.QR_FIGHT_TOWER_LOCKED]: 'Ez a QR harc torony zárva van',
Expand Down

0 comments on commit 967071e

Please sign in to comment.