implemented tags for items

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-10-16 23:04:52 +02:00
parent 554b0459fa
commit 8d40c8c9f1
5 changed files with 63 additions and 19 deletions

View File

@@ -5,11 +5,10 @@ public class Constants {
private Constants(){}
public static final String BELOW = "below";
public static final String CONFIG_DATABASE = "umbrella.modules.stock.database";
public static final String ITEM_ID = "item_id";
public static final String ITEMS_AT = "items_at";
public static final String ITEMS = "items";
public static final String LOCATIONS = "locations";
public static final String OF_USER = "of_user";
public static final String PROPERTY_ID = "prop_id";
@@ -17,4 +16,4 @@ public class Constants {
public static final String TABLE_ITEM_PROPERTIES = "item_props";
public static final String TABLE_LOCATIONS = "locations";
public static final String TABLE_PROPERTIES = "properties";
}
}

View File

@@ -50,7 +50,7 @@ public class StockModule extends BaseHandler implements StockService {
case LOCATION -> {
try {
var location = Location.of(Long.parseLong(path.pop()));
yield getItemsAtLocation(user.get(), location, ex);
yield getLocationEntities(location, ex);
} catch (Exception e){
yield super.doGet(path,ex);
}
@@ -97,11 +97,18 @@ public class StockModule extends BaseHandler implements StockService {
private boolean getChildLocations(UmbrellaUser user, long parentId, HttpExchange ex) throws IOException {
LOG.log(WARNING,"No security check implemented for {0}.getChildLocations(user, parentId, ex)!",getClass().getSimpleName()); // TODO check, that user is allowed to request that location
return sendContent(ex, stockDb.listChildLocations(parentId).stream().sorted(comparing(l -> l.name().toLowerCase())).map(DbLocation::toMap));
}
private boolean getItemsAtLocation(UmbrellaUser user, Location location, HttpExchange ex) throws IOException {
return sendContent(ex, stockDb.listItemsAt(location).stream().map(Item::toMap).toList());
private boolean getLocationEntities(Location location, HttpExchange ex) throws IOException {
var items = stockDb.listItemsAt(location).stream().map(Item::toMap).toList();
var owner = location.resolve().owner();
List<Long> userIds = switch (owner.type()){
case COMPANY -> companyService().getMembers(owner.id()).stream().map(UmbrellaUser::id).toList();
case USER -> List.of(owner.id());
case null, default -> throw unprocessable("Unprocessable owner type: {0}",owner.type());
};
return sendContent(ex,Map.of(ITEMS,items,USERS,userIds));
}
private boolean getLocations(Path path, UmbrellaUser user, HttpExchange ex) throws IOException {
@@ -209,4 +216,4 @@ public class StockModule extends BaseHandler implements StockService {
public Collection<Object> redefineMe(long company_id) {
return List.of();
}
}
}