Keep category orders unique while reordering

Reordering first moves every category to a temporary negative position, then assigns the final ones, so two categories never share a position mid-update. Deleting a category no longer renumbers the system category.
This commit is contained in:
AntsyLich
2026-09-27 22:37:39 +06:00
parent 986f46c09a
commit 4df0e6b168
2 changed files with 7 additions and 1 deletions
@@ -77,6 +77,9 @@ class CategoryRepositoryImpl(
override suspend fun updateAllOrders(orderedIds: List<Long>) {
database.transaction {
orderedIds.forEachIndexed { index, categoryId ->
database.categoriesQueries.updateOrder(order = -index - 2L, categoryId = categoryId)
}
orderedIds.forEachIndexed { index, categoryId ->
database.categoriesQueries.updateOrder(order = index.toLong(), categoryId = categoryId)
}