From 94e35ef9fdd19e0632272abc2cadf5de49ff642c Mon Sep 17 00:00:00 2001 From: Kurt Riddlesperger Date: Wed, 15 Jan 2020 17:41:14 -0600 Subject: [PATCH] Stock updates --- controllers/StockApiController.php | 5 ++++ grocy.openapi.json | 42 +++++++++++++++++++++++++++++- public/viewjs/stockdetail.js | 2 +- public/viewjs/stockedit.js | 2 +- routes.php | 1 + services/StockService.php | 5 ++++ 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/controllers/StockApiController.php b/controllers/StockApiController.php index 12b3270d..0ece5ab2 100644 --- a/controllers/StockApiController.php +++ b/controllers/StockApiController.php @@ -580,6 +580,11 @@ class StockApiController extends BaseApiController return $this->ApiResponse($this->StockService->GetProductStockLocations($args['productId'])); } + public function StockEntry(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) + { + return $this->ApiResponse($this->StockService->GetStockEntry($args['entryId'])); + } + public function StockBooking(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) { try diff --git a/grocy.openapi.json b/grocy.openapi.json index 2c981663..bce3ef34 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -1124,6 +1124,47 @@ } } }, + "/stock/{entryId}/entry": { + "get": { + "summary": "Returns details of the given stock", + "tags": [ + "Stock" + ], + "parameters": [ + { + "in": "path", + "name": "entryId", + "required": true, + "description": "A valid stock row id", + "schema": { + "type": "integer" + } + } + ], + "responses": { + "200": { + "description": "A StockEntry Response object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/StockEntry" + } + } + } + }, + "400": { + "description": "The operation was not successful (possible errors are: Not existing product)", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GenericErrorResponse" + } + } + } + } + } + } + }, "/stock/volatile": { "get": { "summary": "Returns all products which are expiring soon, are already expired or currently missing", @@ -3203,7 +3244,6 @@ "quantity_unit_conversions", "shopping_list", "shopping_lists", - "stock", "recipes", "recipes_pos", "recipes_nestings", diff --git a/public/viewjs/stockdetail.js b/public/viewjs/stockdetail.js index 90178f58..1b878b8e 100644 --- a/public/viewjs/stockdetail.js +++ b/public/viewjs/stockdetail.js @@ -215,7 +215,7 @@ $(document).on("click", ".product-add-to-shopping-list-button", function(e) function RefreshStockDetailRow(stockRowId) { - Grocy.Api.Get("objects/stock/" + stockRowId, + Grocy.Api.Get("stock/" + stockRowId + "/entry", function(result) { var stockRow = $('#stock-' + stockRowId + '-row'); diff --git a/public/viewjs/stockedit.js b/public/viewjs/stockedit.js index 24bea2b8..8932b687 100644 --- a/public/viewjs/stockedit.js +++ b/public/viewjs/stockedit.js @@ -1,6 +1,6 @@ $(document).ready(function() { var stockRowId = GetUriParam('stockRowId'); - Grocy.Api.Get("objects/stock/" + stockRowId, + Grocy.Api.Get("stock/" + stockRowId + "/entry", function(stockEntry) { Grocy.Components.LocationPicker.SetId(stockEntry.location_id); diff --git a/routes.php b/routes.php index 24f1db80..679b11fc 100644 --- a/routes.php +++ b/routes.php @@ -161,6 +161,7 @@ $app->group('/api', function() if (GROCY_FEATURE_FLAG_STOCK) { $this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock'); + $this->get('/stock/{entryId}/entry', '\Grocy\Controllers\StockApiController:StockEntry'); $this->put('/stock', '\Grocy\Controllers\StockApiController:EditStock'); $this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatileStock'); $this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails'); diff --git a/services/StockService.php b/services/StockService.php index efde1419..70b8cb5c 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -170,6 +170,11 @@ class StockService extends BaseService return $returnData; } + public function GetStockEntry($entryId) + { + return $this->Database->stock()->where('id', $entryId)->fetch(); + } + public function GetProductStockEntries($productId, $excludeOpened = false) { // In order of next use: