mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Added a new API endpoint to get all stock entries per location
References https://www.reddit.com/r/grocy/comments/srfwfs
This commit is contained in:
parent
2457c2c2fd
commit
66bd3f0d59
@ -52,4 +52,5 @@
|
||||
|
||||
### API
|
||||
|
||||
- Added a new endpoint `/stock/locations/{locationId}/entries` to get all stock entries of a given location (similiar to the already existing endpoint `/stock/products/{productId}/entries`)
|
||||
- Endpoint `/recipes/{recipeId}/consume`: Fixed that consuming partially fulfilled recipes was possible, although an error was already returned in that case (and potentially some of the in-stock ingredients were consumed in fact)
|
||||
|
@ -631,6 +631,11 @@ class StockApiController extends BaseApiController
|
||||
return $this->FilteredApiResponse($response, $this->getStockService()->GetProductStockEntries($args['productId'], false, $allowSubproductSubstitution, true), $request->getQueryParams());
|
||||
}
|
||||
|
||||
public function LocationStockEntries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
return $this->FilteredApiResponse($response, $this->getStockService()->GetLocationStockEntries($args['locationId']), $request->getQueryParams());
|
||||
}
|
||||
|
||||
public function ProductStockLocations(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$allowSubproductSubstitution = false;
|
||||
|
@ -2792,6 +2792,72 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/stock/locations/{locationId}/entries": {
|
||||
"get": {
|
||||
"summary": "Returns all stock entries of the given location",
|
||||
"tags": [
|
||||
"Stock"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"in": "path",
|
||||
"name": "locationId",
|
||||
"required": true,
|
||||
"description": "A valid location id",
|
||||
"schema": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/query"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/order"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/limit"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/offset"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "An array of StockEntry objects",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/StockEntry"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "The operation was not successful (possible errors are: Not existing location)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error400"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "The operation was not successful (possible errors are invalid field names or conditions in filter parameters provided)",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Error500"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/stock/shoppinglist/add-missing-products": {
|
||||
"post": {
|
||||
"summary": "Adds currently missing products (below defined min. stock amount) to the given shopping list",
|
||||
|
@ -209,6 +209,7 @@ $app->group('/api', function (RouteCollectorProxy $group) {
|
||||
$group->post('/stock/products/by-barcode/{barcode}/transfer', '\Grocy\Controllers\StockApiController:TransferProductByBarcode');
|
||||
$group->post('/stock/products/by-barcode/{barcode}/inventory', '\Grocy\Controllers\StockApiController:InventoryProductByBarcode');
|
||||
$group->post('/stock/products/by-barcode/{barcode}/open', '\Grocy\Controllers\StockApiController:OpenProductByBarcode');
|
||||
$group->get('/stock/locations/{locationId}/entries', '\Grocy\Controllers\StockApiController:LocationStockEntries');
|
||||
$group->get('/stock/bookings/{bookingId}', '\Grocy\Controllers\StockApiController:StockBooking');
|
||||
$group->post('/stock/bookings/{bookingId}/undo', '\Grocy\Controllers\StockApiController:UndoBooking');
|
||||
$group->get('/stock/transactions/{transactionId}', '\Grocy\Controllers\StockApiController:StockTransactions');
|
||||
|
@ -820,6 +820,16 @@ class StockService extends BaseService
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function GetLocationStockEntries($locationId)
|
||||
{
|
||||
if (!$this->LocationExists($locationId))
|
||||
{
|
||||
throw new \Exception('Location does not exist');
|
||||
}
|
||||
|
||||
return $this->getDatabase()->stock()->where('location_id', $locationId);
|
||||
}
|
||||
|
||||
public function GetProductStockEntriesForLocation($productId, $locationId, $excludeOpened = false, $allowSubproductSubstitution = false)
|
||||
{
|
||||
$stockEntries = $this->GetProductStockEntries($productId, $excludeOpened, $allowSubproductSubstitution, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user