refactored moving of locations, implemented editing of location details, implemented raising locations to the top level
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -289,10 +289,11 @@ public class SqliteDb extends BaseDb implements StockDb {
|
||||
|
||||
@Override
|
||||
public DbLocation save(DbLocation location) {
|
||||
var parentId = location.parent() == 0 ? null : location.parent();
|
||||
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(),location.description())
|
||||
.values(location.owner().dbCode(),location.parent() == 0 ? null : parentId,location.name(),location.description())
|
||||
.execute(db).getGeneratedKeys();
|
||||
long id = 0;
|
||||
if (rs.next()) id = rs.getLong(1);
|
||||
@@ -308,7 +309,7 @@ public class SqliteDb extends BaseDb implements StockDb {
|
||||
.set(OWNER, PARENT_LOCATION_ID, NAME, DESCRIPTION)
|
||||
.where(ID,equal(location.id()))
|
||||
.prepare(db)
|
||||
.apply(location.owner().dbCode(), location.parent(), location.name(), location.description())
|
||||
.apply(location.owner().dbCode(), parentId, location.name(), location.description())
|
||||
.close();
|
||||
return location.clear();
|
||||
} catch (SQLException e){
|
||||
|
||||
@@ -248,10 +248,12 @@ public class StockModule extends BaseHandler implements StockService {
|
||||
if (!assigned(owner,user)) throw forbidden("You are not allowed to edit \"{0}\"!",location.name());
|
||||
|
||||
if (json.has(PARENT_LOCATION_ID) && json.get(PARENT_LOCATION_ID) instanceof Number parentId){
|
||||
var target = stockDb.loadLocation(parentId.longValue());
|
||||
var targetOwner = target.owner().resolve();
|
||||
if (!assigned(targetOwner,user)) throw forbidden("You are not allowed to edit \"{0}\"!",target.name());
|
||||
if (!targetOwner.equals(owner)) throw unprocessable("You may not move locations from one owner ({0}) to another ({1})",owner,targetOwner);
|
||||
if (parentId.longValue() != 0L) {
|
||||
var target = stockDb.loadLocation(parentId.longValue());
|
||||
var targetOwner = target.owner().resolve();
|
||||
if (!assigned(targetOwner, user)) throw forbidden("You are not allowed to edit \"{0}\"!", target.name());
|
||||
if (!targetOwner.equals(owner)) throw unprocessable("You may not move locations from one owner ({0}) to another ({1})", owner, targetOwner);
|
||||
}
|
||||
}
|
||||
|
||||
location = stockDb.save(location.patch(json));
|
||||
|
||||
Reference in New Issue
Block a user