Stelios Papamichail
09/29/2024, 7:41 PMStelios Papamichail
09/29/2024, 8:18 PMoverride suspend fun addDissertation(phdDissertationDTO: PhdDissertationDTO): PhdDissertationDTO =
suspendTransaction {
try {
val phdDissertation =
PhdDissertationEntity.new {
title = phdDissertationDTO.title
abstractGR = phdDissertationDTO.abstractGR
abstractEN = phdDissertationDTO.abstractEN
date = phdDissertationDTO.date
url = phdDissertationDTO.url
language = phdDissertationDTO.language
views = phdDissertationDTO.views.toLongOrNull() ?: 0
reads = phdDissertationDTO.reads.toLongOrNull() ?: 0
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
// Add tags
phdDissertation.tags = SizedCollection(phdDissertationDTO.tags.map { tag ->
PhdTagEntity.find { PhdTagsTable.title eq tag.lowercase() }.firstOrNull() ?: PhdTagEntity.new {
title = tag.lowercase()
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// Add authors
phdDissertation.authors = SizedCollection(phdDissertationDTO.authors.map { author ->
PhdAuthorEntity.find { PhdAuthorsTable.fullName eq author.lowercase() }.firstOrNull() ?: PhdAuthorEntity.new {
fullName = author.lowercase()
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// Add scientific fields
phdDissertation.scientificFields = SizedCollection(phdDissertationDTO.scientificFields.map { field ->
PhdScientificFieldEntity.find { PhdScientificFieldsTable.field eq field.lowercase() }.firstOrNull()
?: PhdScientificFieldEntity.new {
title = field.lowercase()
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// Add exam board members
phdDissertation.examBoardMembers = SizedCollection(phdDissertationDTO.examBoardMembers.map { member ->
PhdExamBoardMemberEntity.find { PhdExamBoardTable.examinerFullName eq member.lowercase() }.firstOrNull()
?: PhdExamBoardMemberEntity.new {
fullName = member.lowercase()
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
// add institutions
phdDissertation.institutions =
SizedCollection(phdDissertationDTO.institutions.map { institution ->
PhdInstitutionEntity.find { PhdInstitutionsTable.title eq institution.lowercase() }
.firstOrNull()
?: PhdInstitutionEntity.new {
title = institution.lowercase()
updatedAt = Clock.System.now()
createdAt = Clock.System.now()
}
})
return@suspendTransaction phdDissertation.mapToDto()
} catch (e: Exception) {
throw InsertionException(e.localizedMessage)
}
}
The update functions work fine, I imagine that's to be expected due to the data being present.Chantal Loncle
09/29/2024, 11:04 PMdatabaseGenerated()
?
Documentation for more details.Stelios Papamichail
09/30/2024, 8:31 PMStelios Papamichail
09/30/2024, 8:56 PMPhdDissertationsTable.update({ PhdDissertationsTable.id eq phdDissertation.id }) {
it[updatedAt] = Clock.System.now()
}
where phdDissertation is the entity returned via the insertion, the trigger does not seem to fire (but it does fire for normal updates via a diff endpoint call).