Stock updates

This commit is contained in:
Kurt Riddlesperger 2020-01-15 17:41:14 -06:00
parent 36a6c56f5c
commit 94e35ef9fd
6 changed files with 54 additions and 3 deletions

View File

@ -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

View File

@ -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",

View File

@ -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');

View File

@ -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);

View File

@ -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');

View File

@ -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: