mirror of
https://codeberg.org/selfsigned-ash/antifed
synced 2026-07-21 18:49:34 +02:00
⚡ Changes action update dto to partial
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user