mirror of
https://github.com/grocy/grocy.git
synced 2025-08-18 03:25:50 +00:00
Upgrade Slim Framework to v4 (closes #561)
This commit is contained in:
@@ -6,7 +6,7 @@ use \Grocy\Services\StockService;
|
||||
|
||||
class StockApiController extends BaseApiController
|
||||
{
|
||||
public function __construct(\Slim\Container $container)
|
||||
public function __construct(\DI\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->StockService = new StockService();
|
||||
@@ -14,11 +14,11 @@ class StockApiController extends BaseApiController
|
||||
|
||||
protected $StockService;
|
||||
|
||||
public function ProductDetails(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ProductDetails(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetProductDetails($args['productId']));
|
||||
return $this->ApiResponse($response, $this->StockService->GetProductDetails($args['productId']));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -26,12 +26,12 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function ProductDetailsByBarcode(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ProductDetailsByBarcode(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
$productId = $this->StockService->GetProductIdFromBarcode($args['barcode']);
|
||||
return $this->ApiResponse($this->StockService->GetProductDetails($productId));
|
||||
return $this->ApiResponse($response, $this->StockService->GetProductDetails($productId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -39,11 +39,11 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function ProductPriceHistory(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ProductPriceHistory(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetProductPriceHistory($args['productId']));
|
||||
return $this->ApiResponse($response, $this->StockService->GetProductPriceHistory($args['productId']));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -51,7 +51,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function AddProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function AddProduct(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
@@ -92,7 +92,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price, $locationId);
|
||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||
return $this->ApiResponse($response, $this->Database->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -100,7 +100,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function AddProductByBarcode(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function AddProductByBarcode(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -113,7 +113,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function EditStockEntry(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function EditStockEntry(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
@@ -148,7 +148,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->EditStockEntry($args['entryId'], $requestBody['amount'], $bestBeforeDate, $locationId, $price, $requestBody['open'], $requestBody['purchased_date']);
|
||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||
return $this->ApiResponse($response, $this->Database->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -156,7 +156,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function TransferProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function TransferProduct(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
@@ -189,7 +189,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->TransferProduct($args['productId'], $requestBody['amount'], $requestBody['location_id_from'], $requestBody['location_id_to'], $specificStockEntryId);
|
||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||
return $this->ApiResponse($response, $this->Database->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -197,7 +197,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function TransferProductByBarcode(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function TransferProductByBarcode(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -210,7 +210,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function ConsumeProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ConsumeProduct(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
@@ -257,7 +257,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->ConsumeProduct($args['productId'], $requestBody['amount'], $spoiled, $transactionType, $specificStockEntryId, $recipeId, $locationId);
|
||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||
return $this->ApiResponse($response, $this->Database->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -265,7 +265,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function ConsumeProductByBarcode(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ConsumeProductByBarcode(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -278,7 +278,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function InventoryProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function InventoryProduct(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
@@ -313,7 +313,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId, $price);
|
||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||
return $this->ApiResponse($response, $this->Database->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -321,7 +321,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function InventoryProductByBarcode(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function InventoryProductByBarcode(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -334,7 +334,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function OpenProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function OpenProduct(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
@@ -357,7 +357,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->OpenProduct($args['productId'], $requestBody['amount'], $specificStockEntryId);
|
||||
return $this->ApiResponse($this->Database->stock_log($bookingId));
|
||||
return $this->ApiResponse($response, $this->Database->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -365,7 +365,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function OpenProductByBarcode(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function OpenProductByBarcode(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -378,12 +378,12 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function CurrentStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function CurrentStock(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetCurrentStock());
|
||||
return $this->ApiResponse($response, $this->StockService->GetCurrentStock());
|
||||
}
|
||||
|
||||
public function CurrentVolatileStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function CurrentVolatileStock(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$nextXDays = 5;
|
||||
if (isset($request->getQueryParams()['expiring_days']) && !empty($request->getQueryParams()['expiring_days']) && is_numeric($request->getQueryParams()['expiring_days']))
|
||||
@@ -394,14 +394,14 @@ class StockApiController extends BaseApiController
|
||||
$expiringProducts = $this->StockService->GetExpiringProducts($nextXDays, true);
|
||||
$expiredProducts = $this->StockService->GetExpiringProducts(-1);
|
||||
$missingProducts = $this->StockService->GetMissingProducts();
|
||||
return $this->ApiResponse(array(
|
||||
return $this->ApiResponse($response, array(
|
||||
'expiring_products' => $expiringProducts,
|
||||
'expired_products' => $expiredProducts,
|
||||
'missing_products' => $missingProducts
|
||||
));
|
||||
}
|
||||
|
||||
public function AddMissingProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function AddMissingProductsToShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -422,7 +422,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function ClearShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ClearShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -444,7 +444,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
|
||||
|
||||
public function AddProductToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function AddProductToShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -485,7 +485,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function RemoveProductFromShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function RemoveProductFromShoppingList(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -521,7 +521,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function ExternalBarcodeLookup(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ExternalBarcodeLookup(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -531,7 +531,7 @@ class StockApiController extends BaseApiController
|
||||
$addFoundProduct = true;
|
||||
}
|
||||
|
||||
return $this->ApiResponse($this->StockService->ExternalBarcodeLookup($args['barcode'], $addFoundProduct));
|
||||
return $this->ApiResponse($response, $this->StockService->ExternalBarcodeLookup($args['barcode'], $addFoundProduct));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -539,11 +539,11 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function UndoBooking(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function UndoBooking(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->ApiResponse($this->StockService->UndoBooking($args['bookingId']));
|
||||
$this->ApiResponse($response, $this->StockService->UndoBooking($args['bookingId']));
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
@@ -552,11 +552,11 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function UndoTransaction(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function UndoTransaction(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->ApiResponse($this->StockService->UndoTransaction($args['transactionId']));
|
||||
$this->ApiResponse($response, $this->StockService->UndoTransaction($args['transactionId']));
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
@@ -565,7 +565,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function ProductStockEntries(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ProductStockEntries(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
$allowSubproductSubstitution = false;
|
||||
if (isset($request->getQueryParams()['include_sub_products']) && filter_var($request->getQueryParams()['include_sub_products'], FILTER_VALIDATE_BOOLEAN))
|
||||
@@ -573,20 +573,20 @@ class StockApiController extends BaseApiController
|
||||
$allowSubproductSubstitution = true;
|
||||
}
|
||||
|
||||
return $this->ApiResponse($this->StockService->GetProductStockEntries($args['productId'], false, $allowSubproductSubstitution));
|
||||
return $this->ApiResponse($response, $this->StockService->GetProductStockEntries($args['productId'], false, $allowSubproductSubstitution));
|
||||
}
|
||||
|
||||
public function ProductStockLocations(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function ProductStockLocations(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetProductStockLocations($args['productId']));
|
||||
return $this->ApiResponse($response, $this->StockService->GetProductStockLocations($args['productId']));
|
||||
}
|
||||
|
||||
public function StockEntry(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function StockEntry(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetStockEntry($args['entryId']));
|
||||
return $this->ApiResponse($response, $this->StockService->GetStockEntry($args['entryId']));
|
||||
}
|
||||
|
||||
public function StockBooking(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function StockBooking(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -597,7 +597,7 @@ class StockApiController extends BaseApiController
|
||||
throw new \Exception('Stock booking does not exist');
|
||||
}
|
||||
|
||||
return $this->ApiResponse($stockLogRow);
|
||||
return $this->ApiResponse($response, $stockLogRow);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
@@ -605,7 +605,7 @@ class StockApiController extends BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
public function StockTransactions(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
public function StockTransactions(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -616,7 +616,7 @@ class StockApiController extends BaseApiController
|
||||
throw new \Exception('No transaction was found by the given transaction id');
|
||||
}
|
||||
|
||||
return $this->ApiResponse($transactionRows);
|
||||
return $this->ApiResponse($response, $transactionRows);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
|
Reference in New Issue
Block a user