-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1415: Revoke existing cards when user entitlements are revoked or exp…
…ired
- Loading branch information
1 parent
ae8a6d2
commit f9b6150
Showing
6 changed files
with
124 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 16 additions & 17 deletions
33
...rc/main/kotlin/app/ehrenamtskarte/backend/userdata/database/UserEntitlementsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
package app.ehrenamtskarte.backend.userdata.database | ||
|
||
import org.jetbrains.exposed.sql.booleanLiteral | ||
import org.jetbrains.exposed.sql.intLiteral | ||
import org.jetbrains.exposed.sql.javatime.dateLiteral | ||
import org.jetbrains.exposed.sql.javatime.timestampLiteral | ||
import org.jetbrains.exposed.sql.upsert | ||
import org.jetbrains.exposed.sql.insert | ||
import org.jetbrains.exposed.sql.update | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
|
||
object UserEntitlementsRepository { | ||
|
||
fun insertOrUpdateUserData(userHash: ByteArray, startDate: LocalDate, endDate: LocalDate, revoked: Boolean, regionId: Int) { | ||
UserEntitlements.upsert( | ||
UserEntitlements.userHash, | ||
onUpdate = listOf( | ||
UserEntitlements.startDate to dateLiteral(startDate), | ||
UserEntitlements.endDate to dateLiteral(endDate), | ||
UserEntitlements.revoked to booleanLiteral(revoked), | ||
UserEntitlements.regionId to intLiteral(regionId), | ||
UserEntitlements.lastUpdated to timestampLiteral(Instant.now()) | ||
) | ||
) { | ||
fun insert(userHash: ByteArray, startDate: LocalDate, endDate: LocalDate, revoked: Boolean, regionId: Int) { | ||
UserEntitlements.insert { | ||
it[UserEntitlements.userHash] = userHash | ||
it[UserEntitlements.startDate] = startDate | ||
it[UserEntitlements.endDate] = endDate | ||
it[UserEntitlements.revoked] = revoked | ||
it[UserEntitlements.regionId] = regionId | ||
it[lastUpdated] = Instant.now() | ||
} | ||
} | ||
|
||
fun findUserEntitlements(userHash: ByteArray): UserEntitlementsEntity? { | ||
fun update(userHash: ByteArray, startDate: LocalDate, endDate: LocalDate, revoked: Boolean, regionId: Int) { | ||
UserEntitlements.update({ UserEntitlements.userHash eq userHash }) { | ||
it[UserEntitlements.startDate] = startDate | ||
it[UserEntitlements.endDate] = endDate | ||
it[UserEntitlements.revoked] = revoked | ||
it[UserEntitlements.regionId] = regionId | ||
it[lastUpdated] = Instant.now() | ||
} | ||
} | ||
|
||
fun find(userHash: ByteArray): UserEntitlementsEntity? { | ||
return UserEntitlementsEntity.find { UserEntitlements.userHash eq userHash }.firstOrNull() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters