Changes action update dto to partial

This commit is contained in:
Daniel Svitan
2025-05-11 19:06:00 +02:00
parent 957e031073
commit e4e2312595
2 changed files with 15 additions and 7 deletions
+13 -6
View File
@@ -46,6 +46,13 @@ class NewActionDTO(
val authId: String
)
@Serializable
class UpdateActionDTO(
val name: String?,
val kind: String?,
val source: String?
)
@Serializable
class RunActionDTO(
val pin: String,
@@ -124,22 +131,22 @@ class ActionService {
}
}
fun update(id: UUID, action: NewActionDTO) {
fun update(id: UUID, action: UpdateActionDTO) {
val oldAction = read(id) ?: throw NotFoundException("action not found")
transaction {
val now = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
Actions.update({ Actions.id eq id }) {
it[name] = action.name
it[kind] = ActionKind.from(action.kind).toString()
it[aSource] = action.source
if (action.name != null) it[name] = action.name
if (action.kind != null) it[kind] = ActionKind.from(action.kind).toString()
if (action.source != null) it[aSource] = action.source
it[updatedAt] = now
}
}
if (action.kind == ActionKind.SCRIPT.toString()) {
if (action.kind == ActionKind.SCRIPT.toString() && action.source != null) {
ExecutorService.writeFile(id, action.source)
} else if (oldAction.kind == ActionKind.SCRIPT) {
} else if (action.kind == ActionKind.TEXT.toString() && oldAction.kind == ActionKind.SCRIPT) {
ExecutorService.deleteFile(id)
}
}