@ -50,7 +50,7 @@ public class StockModule extends BaseHandler implements StockService {
@@ -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 {
@@ -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 {
@@ -209,4 +216,4 @@ public class StockModule extends BaseHandler implements StockService {
public Collection < Object > redefineMe ( long company_id ) {
return List . of ( ) ;
}
}
}