Skip to content

Commit

Permalink
Align uuid types
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvv committed Jan 21, 2025
1 parent 35b638b commit e812555
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class SurveyRepository(
val userId = row[CompanySurveyTable.createdById] ?: return null

return com.zenmo.zummon.User(
row[UserTable.id],
row[UserTable.id].toKotlinUuid(),
row[UserTable.note],
)
}
Expand Down
4 changes: 2 additions & 2 deletions zorm/src/main/kotlin/com/zenmo/orm/user/UserRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class UserRepository(
) {
transaction(db) {
UserTable.upsertReturning() {
it[id] = user.id
it[id] = user.id.toJavaUuid()
it[UserTable.note] = user.note
it[UserTable.isAdmin] = user.isAdmin
}.map {
Expand Down Expand Up @@ -113,7 +113,7 @@ class UserRepository(

protected fun hydrateUser(row: ResultRow): User {
return User(
id = row[UserTable.id],
id = row[UserTable.id].toKotlinUuid(),
note = row[UserTable.note],
isAdmin = row[UserTable.isAdmin],
projects = emptyList(), // data from different table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ class SurveyRepositoryTest {
val createdBy = surveyLoadedAfterCreate?.createdBy
assertNotNull(createdBy)
assertEquals("Jaap", createdBy.note)
assertEquals(jaapId, createdBy.id)
assertEquals(jaapId.toKotlinUuid(), createdBy.id)

// edit survey
surveyRepository.save(surveyLoadedAfterCreate, pietId)
val surveyLoadedAfterEdit = surveyRepository.getSurveyById(surveyId)
val createdBy2 = surveyLoadedAfterEdit?.createdBy
assertNotNull(createdBy2)
assertEquals("Jaap", createdBy2.note)
assertEquals(jaapId, createdBy2.id)
assertEquals(jaapId.toKotlinUuid(), createdBy2.id)
}

private fun wipeSequence(survey: Survey)
Expand Down
10 changes: 3 additions & 7 deletions zummon/src/commonMain/kotlin/User.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package com.zenmo.zummon

import com.benasher44.uuid.Uuid
import com.benasher44.uuid.uuid4
import com.zenmo.zummon.BenasherUuidSerializer
import com.zenmo.zummon.companysurvey.Project
import kotlinx.serialization.Serializable
import kotlin.js.JsExport
import kotlin.uuid.Uuid

/**
* This object is intended to be enriched with Keycloak data.
* It is not purely an ORM object.
*/
@Serializable
@JsExport
data class User
constructor(
@Serializable(with = BenasherUuidSerializer::class)
val id: Uuid = uuid4(),
data class User(
val id: Uuid = Uuid.random(),
val note: String,
val projects: List<Project> = emptyList(),
val isAdmin: Boolean = false
Expand Down

0 comments on commit e812555

Please sign in to comment.