Skip to content

Commit

Permalink
delete the anno if langtags are empty after update
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmane committed Feb 7, 2025
1 parent 72c4c13 commit 3d797c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,20 @@ class UpdateRowModel(val connection: DatabaseConnection) extends DatabaseQuery w
}

def deleteCellAnnotation(column: ColumnType[_], rowId: RowId, uuid: UUID, langtag: String): Future[_] = {
val delete =
val deleteLangtag =
s"UPDATE user_table_annotations_${column.table.id} SET langtags = ARRAY_REMOVE(langtags, ?) WHERE row_id = ? AND column_id = ? AND uuid = ?"
val binds = Json.arr(langtag, rowId, column.id, uuid.toString)
// we delete the annotation if langtag array is empty after update
val maybeDeleteWholeAnnotation =
s"DELETE FROM user_table_annotations_${column.table.id} WHERE row_id = ? AND column_id = ? AND uuid = ? AND CARDINALITY(ARRAY_REMOVE(langtags, ?)) < 1"

connection.query(delete, binds)
connection.transactional { t =>
{
for {
(t, result) <- t.query(deleteLangtag, Json.arr(langtag, rowId, column.id, uuid.toString))
(t, _) <- t.query(maybeDeleteWholeAnnotation, Json.arr(rowId, column.id, uuid.toString, langtag))
} yield (t, result)
}
}
}

def addRowPermissions(table: Table, row: Row, rowPermissions: RowPermissionSeq): Future[Option[RowPermissionSeq]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ class CellLevelAnnotationsTest extends TableauxTestBase {
Json.arr("en"),
rowJson2.getJsonArray("annotations").getJsonArray(0).getJsonObject(0).getJsonArray("langtags")
)
assertNull(rowJson3.getJsonArray("annotations").getJsonArray(0).getJsonObject(0))
assertNull(rowJson3.getJsonArray("annotations"))
}
}
}
Expand Down

0 comments on commit 3d797c0

Please sign in to comment.