implemented moving of locations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-22 21:16:25 +02:00
parent 7b259e7425
commit eafa7a5b5f
4 changed files with 38 additions and 5 deletions

View File

@@ -292,7 +292,7 @@ public class SqliteDb extends BaseDb implements StockDb {
if (location.id() == 0) { // new location
try {
var rs = insertInto(TABLE_LOCATIONS,OWNER,PARENT_LOCATION_ID,NAME,DESCRIPTION)
.values(location.owner().dbCode(),location.parent(),location.name(),null)
.values(location.owner().dbCode(),location.parent(),location.name(),location.description())
.execute(db).getGeneratedKeys();
long id = 0;
if (rs.next()) id = rs.getLong(1);
@@ -303,7 +303,17 @@ public class SqliteDb extends BaseDb implements StockDb {
throw databaseException("Failed to save new location ({0})",location.name());
}
} else {
throw databaseException("Updating locations not implemented");
try {
update(TABLE_LOCATIONS)
.set(OWNER, PARENT_LOCATION_ID, NAME, DESCRIPTION)
.where(ID,equal(location.id()))
.prepare(db)
.apply(location.owner().dbCode(), location.parent(), location.name(), location.description())
.close();
return location.clear();
} catch (SQLException e){
throw databaseException("Updating location \"{0}\" not implemented",location.name());
}
}
}

View File

@@ -242,7 +242,7 @@ public class StockModule extends BaseHandler implements StockService {
var owner = location.owner().resolve();
if (!assigned(owner,user)) throw forbidden("You are not allowed to alter the location of \"{0}\"!",location.name());
var target = stockDb.loadLocation(locationId.longValue());
var target = stockDb.loadLocation(destLocationId.longValue());
var locOwner = target.resolve().owner().resolve();
if (!assigned(locOwner,user)) throw forbidden("You are not allowed to modify \"{0}\"!",target.name());