mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
refactor to be stock/entry/{entryId}
This commit is contained in:
parent
101355cae2
commit
7028a9950f
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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') + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBookingEntry(\'' + result.id + '\',\'' + stockRowId + '\')"><i class="fas fa-undo"></i> ' + __t("Undo") + '</a>';
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@
|
|||
data-stockrow-id="{{ $currentStockEntry->id }}">
|
||||
<i class="fas fa-box-open"></i>
|
||||
</a>
|
||||
@endif
|
||||
<a class="btn btn-info btn-sm show-as-dialog-link" href="{{ $U('/stockedit?embedded&product=' . $currentStockEntry->product_id . '&stockRowId=' . $currentStockEntry->id) }}" data-toggle="tooltip" data-placement="left" title="{{ $__t('Edit stock entry') }}">
|
||||
<i class="fas fa-edit"></i>
|
||||
</a>
|
||||
@endif
|
||||
<div class="dropdown d-inline-block">
|
||||
<button class="btn btn-sm btn-light text-secondary" type="button" data-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-v"></i>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user