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'])); 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) public function StockBooking(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
try 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": { "/stock/volatile": {
"get": { "get": {
"summary": "Returns all products which are expiring soon, are already expired or currently missing", "summary": "Returns all products which are expiring soon, are already expired or currently missing",
@ -3203,7 +3244,6 @@
"quantity_unit_conversions", "quantity_unit_conversions",
"shopping_list", "shopping_list",
"shopping_lists", "shopping_lists",
"stock",
"recipes", "recipes",
"recipes_pos", "recipes_pos",
"recipes_nestings", "recipes_nestings",

View File

@ -215,7 +215,7 @@ $(document).on("click", ".product-add-to-shopping-list-button", function(e)
function RefreshStockDetailRow(stockRowId) function RefreshStockDetailRow(stockRowId)
{ {
Grocy.Api.Get("objects/stock/" + stockRowId, Grocy.Api.Get("stock/" + stockRowId + "/entry",
function(result) function(result)
{ {
var stockRow = $('#stock-' + stockRowId + '-row'); var stockRow = $('#stock-' + stockRowId + '-row');

View File

@ -1,6 +1,6 @@
$(document).ready(function() { $(document).ready(function() {
var stockRowId = GetUriParam('stockRowId'); var stockRowId = GetUriParam('stockRowId');
Grocy.Api.Get("objects/stock/" + stockRowId, Grocy.Api.Get("stock/" + stockRowId + "/entry",
function(stockEntry) function(stockEntry)
{ {
Grocy.Components.LocationPicker.SetId(stockEntry.location_id); Grocy.Components.LocationPicker.SetId(stockEntry.location_id);

View File

@ -161,6 +161,7 @@ $app->group('/api', function()
if (GROCY_FEATURE_FLAG_STOCK) if (GROCY_FEATURE_FLAG_STOCK)
{ {
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock'); $this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
$this->get('/stock/{entryId}/entry', '\Grocy\Controllers\StockApiController:StockEntry');
$this->put('/stock', '\Grocy\Controllers\StockApiController:EditStock'); $this->put('/stock', '\Grocy\Controllers\StockApiController:EditStock');
$this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatileStock'); $this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatileStock');
$this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails'); $this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');

View File

@ -170,6 +170,11 @@ class StockService extends BaseService
return $returnData; return $returnData;
} }
public function GetStockEntry($entryId)
{
return $this->Database->stock()->where('id', $entryId)->fetch();
}
public function GetProductStockEntries($productId, $excludeOpened = false) public function GetProductStockEntries($productId, $excludeOpened = false)
{ {
// In order of next use: // In order of next use: