implemented deletion of item properties

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-15 21:13:08 +02:00
parent a001074783
commit 21c5a72349
4 changed files with 15 additions and 7 deletions

View File

@@ -51,14 +51,18 @@ public class SqliteDb extends BaseDb implements StockDb {
}
@Override
public Property addProperty(long ownerId, long itemId, long existingPropId, Object value) {
public Property setProperty(long ownerId, long itemId, long existingPropId, Object value) {
try {
Property prop = null;
var rs = select(ALL).from(TABLE_PROPERTIES).where(ID,equal(existingPropId)).exec(db);
if (rs.next()) prop = Property.of(rs);
rs.close();
if (prop == null) throw databaseException("Failed to add new property to item {0}",itemId);
replaceInto(TABLE_ITEM_PROPERTIES,OWNER,ITEM_ID,PROPERTY_ID,VALUE).values(ownerId,itemId,existingPropId,value).execute(db);
if ("".equals(value)){
delete().from(TABLE_ITEM_PROPERTIES).where(OWNER,equal(ownerId)).where(ITEM_ID,equal(itemId)).where(PROPERTY_ID,equal(existingPropId)).execute(db);
} else {
replaceInto(TABLE_ITEM_PROPERTIES,OWNER,ITEM_ID,PROPERTY_ID,VALUE).values(ownerId,itemId,existingPropId,value).execute(db);
}
return prop.value(value);
} catch (SQLException e) {
throw databaseException("Failed to add new property to item {0}",itemId);

View File

@@ -6,7 +6,6 @@ import de.srsoftware.umbrella.core.model.*;
import java.util.Collection;
public interface StockDb {
Property addProperty(long ownerId, long itemId, long existingPropId, Object value);
Property addNewProperty(long ownerId, long itemId, String name, Object value, String unit);
Collection<Location> listChildLocations(long parentId);
Collection<Location> listCompanyLocations(Company company);
@@ -14,6 +13,6 @@ public interface StockDb {
Collection<Property> listProperties();
Collection<Location> listUserLocations(UmbrellaUser userId);
Item loadItem(Mappable owner, long itemId);
Item save(Item item);
Property setProperty(long ownerId, long itemId, long existingPropId, Object value);
}

View File

@@ -182,7 +182,7 @@ public class StockModule extends BaseHandler implements StockService {
Property property = null;
if (propData.get("existing_prop_id") instanceof Number existingPropId && existingPropId.longValue() != 0L){
property = stockDb.addProperty(ownerId,itemId.longValue(),existingPropId.longValue(),value);
property = stockDb.setProperty(ownerId,itemId.longValue(),existingPropId.longValue(),value);
} else {
if (!(propData.get("new_prop") instanceof JSONObject newProp)) throw unprocessable("data must contain either add_prop.existing_prop_id or add_prop.new_prop!");
if (!(newProp.get(NAME) instanceof String name) || name.isBlank()) throw unprocessable("data.add_prop.new_prop does not contain name!");