FR #496: Removed extra GET entry to include product by default

The '/api/stock' now returns an extra attribute ('product') with the
associated product details.
This commit is contained in:
Gregory SACRE 2020-01-19 00:22:16 +01:00
parent a014b6da06
commit b17b0fc926
4 changed files with 18 additions and 127 deletions

View File

@ -388,11 +388,6 @@ class StockApiController extends BaseApiController
return $this->ApiResponse($this->StockService->GetCurrentStock());
}
public function CurrentStockFull(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
return $this->ApiResponse($this->StockService->GetCurrentStockFull());
}
public function CurrentVolatilStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{
$nextXDays = 5;

View File

@ -1124,29 +1124,6 @@
}
}
},
"/stock/full": {
"get": {
"summary": "Returns all products which are currently in stock incl. product details",
"tags": [
"Stock"
],
"responses": {
"200": {
"description": "An array of CurrentStockResponse objects with product details",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/CurrentStockResponseFull"
}
}
}
}
}
}
}
},
"/stock/volatile": {
"get": {
"summary": "Returns all products which are expiring soon, are already expired or currently missing",
@ -4048,99 +4025,9 @@
"is_aggregated_amount": {
"type": "boolean",
"description": "Indicates wheter this product has sub-products or not / if the fields `amount_aggregated` and `amount_opened_aggregated` are filled"
}
}
},
"CurrentStockResponseFull": {
"type": "object",
"properties": {
"product_id": {
"type": "integer"
},
"amount": {
"type": "number"
},
"amount_aggregated": {
"type": "number"
},
"amount_opened": {
"type": "number"
},
"amount_opened_aggregated": {
"type": "number"
},
"best_before_date": {
"type": "string",
"format": "date",
"description": "The next best before date for this product"
},
"is_aggregated_amount": {
"type": "boolean",
"description": "Indicates wheter this product has sub-products or not / if the fields `amount_aggregated` and `amount_opened_aggregated` are filled"
},
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"location_id": {
"type": "integer"
},
"qu_id_purchase": {
"type": "integer"
},
"qu_id_stock": {
"type": "integer"
},
"enable_tare_weight_handling": {
"type": "integer"
},
"not_check_stock_fulfillment_for_recipes": {
"type": "integer"
},
"product_group_id": {
"type": "integer"
},
"qu_factor_purchase_to_stock": {
"type": "number",
"format": "number"
},
"tare_weight": {
"type": "number",
"format": "number"
},
"barcode": {
"type": "string",
"description": "Can contain multiple barcodes separated by comma"
},
"min_stock_amount": {
"type": "integer",
"minimum": 0,
"default": 0
},
"default_best_before_days": {
"type": "integer",
"minimum": 0,
"default": 0
},
"default_best_before_days_after_open": {
"type": "integer",
"minimum": 0,
"default": 0
},
"picture_file_name": {
"type": "string"
},
"allow_partial_units_in_stock": {
"type": "boolean"
},
"row_created_timestamp": {
"type": "string",
"format": "date-time"
"product": {
"$ref": "#/components/schemas/Product"
}
}
},

View File

@ -162,7 +162,6 @@ $app->group('/api', function()
{
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
$this->put('/stock', '\Grocy\Controllers\StockApiController:EditStock');
$this->get('/stock/full', '\Grocy\Controllers\StockApiController:CurrentStockFull');
$this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatilStock');
$this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
$this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');

View File

@ -27,14 +27,24 @@ class StockService extends BaseService
$sql = 'SELECT * FROM stock_current WHERE best_before_date IS NOT NULL UNION SELECT id, 0, 0, null, 0, 0, 0 FROM ' . $missingProductsView . ' WHERE id NOT IN (SELECT product_id FROM stock_current)';
}
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
}
$current_stock = $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
$stock_array = [];
public function GetCurrentStockFull()
{
$sql = 'select * from stock_current join products on products.id = stock_current.product_id';
foreach ($current_stock as $cur) {
$stock_array[$cur->product_id] = $cur;
}
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
$list_of_product_ids = implode(",", array_keys($stock_array));
$sql = 'SELECT * FROM products WHERE id in (' . $list_of_product_ids . ')';
$products = $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
foreach ($products as $product) {
$stock_array[$product->id]->product = $product;
}
return $stock_array;
}
public function GetCurrentStockLocationContent()