diff --git a/controllers/StockApiController.php b/controllers/StockApiController.php index 2f1b682e..371c86d7 100644 --- a/controllers/StockApiController.php +++ b/controllers/StockApiController.php @@ -124,11 +124,6 @@ class StockApiController extends BaseApiController throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)'); } - if (!array_key_exists('id', $requestBody)) - { - throw new \Exception('A stock row id is required'); - } - if (!array_key_exists('amount', $requestBody)) { throw new \Exception('An amount is required'); @@ -152,7 +147,7 @@ class StockApiController extends BaseApiController $locationId = $requestBody['location_id']; } - $bookingId = $this->StockService->EditStockEntry($requestBody['id'], $requestBody['amount'], $bestBeforeDate, $locationId, $price, $requestBody['open']); + $bookingId = $this->StockService->EditStockEntry($args['entryId'], $requestBody['amount'], $bestBeforeDate, $locationId, $price, $requestBody['open']); return $this->ApiResponse($this->Database->stock_log($bookingId)); } catch (\Exception $ex) diff --git a/grocy.openapi.json b/grocy.openapi.json index 66214e02..bd701c4b 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -1050,86 +1050,9 @@ } } } - }, - "put": { - "summary": "Edits the stock entry", - "tags": [ - "Stock" - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "id": { - "type": "number", - "format": "number", - "description": "The stock table id" - }, - "amount": { - "type": "number", - "format": "number", - "description": "The amount to add - please note that when tare weight handling for the product is enabled, this needs to be the amount including the container weight (gross), the amount to be posted will be automatically calculated based on what is in stock and the defined tare weight" - }, - "best_before_date": { - "type": "string", - "format": "date", - "description": "The best before date of the product to add, when omitted, the current date is used" - }, - "location_id": { - "type": "number", - "format": "integer", - "description": "If omitted, the default location of the product is used" - }, - "price": { - "type": "number", - "format": "number", - "description": "The price per purchase quantity unit in configured currency" - }, - "open": { - "type": "boolean", - "description": "If the stock entry was already opened or not" - } - }, - "example": { - "id": 2, - "amount": 1, - "best_before_date": "2019-01-19", - "location_id": 2, - "price": "1.99", - "open": false - } - } - } - } - }, - "responses": { - "200": { - "description": "The operation was successful", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/StockLogEntry" - } - } - } - }, - "400": { - "description": "The operation was not successful (possible errors are: Not existing product, invalid transaction type)", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GenericErrorResponse" - } - } - } - } - } } }, - "/stock/{entryId}/entry": { + "/stock/entry/{entryId}": { "get": { "summary": "Returns details of the given stock", "tags": [ @@ -1168,6 +1091,90 @@ } } } + }, + "put": { + "summary": "Edits the stock entry", + "tags": [ + "Stock" + ], + "parameters": [ + { + "in": "path", + "name": "entryId", + "required": true, + "description": "A valid stock row id", + "schema": { + "type": "integer" + } + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "amount": { + "type": "number", + "format": "number", + "description": "The amount to add - please note that when tare weight handling for the product is enabled, this needs to be the amount including the container weight (gross), the amount to be posted will be automatically calculated based on what is in stock and the defined tare weight" + }, + "best_before_date": { + "type": "string", + "format": "date", + "description": "The best before date of the product to add, when omitted, the current date is used" + }, + "price": { + "type": "number", + "format": "number", + "description": "The price per purchase quantity unit in configured currency" + }, + "open": { + "type": "boolean", + "description": "If the stock entry was already opened or not" + }, + "location_id": { + "type": "number", + "format": "integer", + "description": "If omitted, the default location of the product is used" + } + }, + "example": { + "id": "2", + "amount": "1", + "best_before_date": "2021-07-19", + "purchased_date": "2020-01-01", + "price": "22.03", + "open": false, + "location_id": "4" + } + } + } + } + }, + "responses": { + "200": { + "description": "The operation was successful", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/StockEntry" + } + } + } + }, + "400": { + "description": "The operation was not successful (possible errors are: Not existing product, invalid transaction type)", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GenericErrorResponse" + } + } + } + } + } } }, "/stock/volatile": { diff --git a/public/viewjs/stockdetail.js b/public/viewjs/stockdetail.js index 0772bd4a..a27b9c9c 100644 --- a/public/viewjs/stockdetail.js +++ b/public/viewjs/stockdetail.js @@ -116,7 +116,7 @@ $(document).on("click", ".stock-name-cell", function(e) function RefreshStockDetailRow(stockRowId) { - Grocy.Api.Get("stock/" + stockRowId + "/entry", + Grocy.Api.Get("stock/entry/" + stockRowId, function(result) { var stockRow = $('#stock-' + stockRowId + '-row'); diff --git a/public/viewjs/stockedit.js b/public/viewjs/stockedit.js index ef1790d7..e7da8594 100644 --- a/public/viewjs/stockedit.js +++ b/public/viewjs/stockedit.js @@ -26,9 +26,8 @@ jsonData.open = $("#open").is(":checked"); var stockRowId = GetUriParam('stockRowId'); - jsonData.id = stockRowId; - Grocy.Api.Put("stock", jsonData, + Grocy.Api.Put("stock/entry/" + stockRowId, jsonData, function(result) { var successMessage = __t('Stock entry successfully updated') + '
' + __t("Undo") + ''; @@ -84,7 +83,7 @@ if (Grocy.Components.DateTimePicker) } var stockRowId = GetUriParam('stockRowId'); -Grocy.Api.Get("stock/" + stockRowId + "/entry", +Grocy.Api.Get("stock/entry/" + stockRowId, function (stockEntry) { Grocy.Components.LocationPicker.SetId(stockEntry.location_id); diff --git a/routes.php b/routes.php index 3032605b..967814ab 100644 --- a/routes.php +++ b/routes.php @@ -161,8 +161,8 @@ $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:EditStockEntry'); + $this->get('/stock/entry/{entryId}', '\Grocy\Controllers\StockApiController:StockEntry'); + $this->put('/stock/entry/{entryId}', '\Grocy\Controllers\StockApiController:EditStockEntry'); $this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatileStock'); $this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails'); $this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries'); diff --git a/views/stockdetail.blade.php b/views/stockdetail.blade.php index 1b11535b..fe3e3560 100644 --- a/views/stockdetail.blade.php +++ b/views/stockdetail.blade.php @@ -64,10 +64,10 @@ data-stockrow-id="{{ $currentStockEntry->id }}"> + @endif - @endif