mirror of
https://github.com/grocy/grocy.git
synced 2026-04-06 21:06:15 +02:00
Feature request : api/stock can return detailed products #487
Added a new API: /api/stock/full This API returns the same values as "/api/stock" except that it also gives the details of the corresponding product.
This commit is contained in:
parent
d4bec3bd10
commit
a014b6da06
|
|
@ -388,6 +388,11 @@ class StockApiController extends BaseApiController
|
||||||
return $this->ApiResponse($this->StockService->GetCurrentStock());
|
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)
|
public function CurrentVolatilStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
{
|
{
|
||||||
$nextXDays = 5;
|
$nextXDays = 5;
|
||||||
|
|
|
||||||
|
|
@ -1124,6 +1124,29 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/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": {
|
"/stock/volatile": {
|
||||||
"get": {
|
"get": {
|
||||||
"summary": "Returns all products which are expiring soon, are already expired or currently missing",
|
"summary": "Returns all products which are expiring soon, are already expired or currently missing",
|
||||||
|
|
@ -4028,6 +4051,99 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"CurrentChoreResponse": {
|
"CurrentChoreResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ $app->group('/api', function()
|
||||||
{
|
{
|
||||||
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
|
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
|
||||||
$this->put('/stock', '\Grocy\Controllers\StockApiController:EditStock');
|
$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/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatilStock');
|
||||||
$this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
|
$this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
|
||||||
$this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');
|
$this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,13 @@ class StockService extends BaseService
|
||||||
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetCurrentStockFull()
|
||||||
|
{
|
||||||
|
$sql = 'select * from stock_current join products on products.id = stock_current.product_id';
|
||||||
|
|
||||||
|
return $this->DatabaseService->ExecuteDbQuery($sql)->fetchAll(\PDO::FETCH_OBJ);
|
||||||
|
}
|
||||||
|
|
||||||
public function GetCurrentStockLocationContent()
|
public function GetCurrentStockLocationContent()
|
||||||
{
|
{
|
||||||
$sql = 'SELECT * FROM stock_current_location_content';
|
$sql = 'SELECT * FROM stock_current_location_content';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user