Skip to content

Commit

Permalink
fix: use db to set priority if missing in payload
Browse files Browse the repository at this point in the history
  • Loading branch information
smnhgn committed Jan 20, 2025
1 parent a0b108b commit cbec214
Showing 1 changed file with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,16 @@ class CellAnnotationConfigModel(override protected[this] val connection: Databas
| is_multilang,
| is_dashboard)
|VALUES
| (?, ?, ?, ?, ?, ?, ?) RETURNING name""".stripMargin
| (?, COALESCE(?, (SELECT MAX(priority) FROM $table), 0) + 1, ?, ?, ?, ?, ?) RETURNING name""".stripMargin

for {
_ <- checkUniqueName(name)
newPriority <- getNewPriority()
result <- connection.query(
insert,
Json
.arr(
name,
priority.getOrElse(newPriority),
priority.getOrElse(null),
fgColor,
bgColor,
displayName.getJson.toString,
Expand Down Expand Up @@ -186,14 +185,4 @@ class CellAnnotationConfigModel(override protected[this] val connection: Databas
))
})
}

private def getNewPriority(): Future[Int] = {
val sql = s"SELECT MAX(priority) FROM $table"

for {
maxPriority <- connection.selectSingleValue[Int](sql)
} yield {
maxPriority + 1
}
}
}

0 comments on commit cbec214

Please sign in to comment.