Rework API to be more RESTful (references #139)

This commit is contained in:
Bernd Bestel 2019-01-19 14:51:51 +01:00
parent 0ce8d706a6
commit bfa59dd29c
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
52 changed files with 1110 additions and 1143 deletions

View File

@ -18,10 +18,14 @@ class BaseApiController extends BaseController
return json_encode($data); return json_encode($data);
} }
protected function VoidApiActionResponse($response, $success = true, $status = 200, $errorMessage = '') protected function EmptyApiResponse($response, $status = 204)
{
return $response->withStatus($status);
}
protected function GenericErrorResponse($response, $errorMessage, $status = 400)
{ {
return $response->withStatus($status)->withJson(array( return $response->withStatus($status)->withJson(array(
'success' => $success,
'error_message' => $errorMessage 'error_message' => $errorMessage
)); ));
} }

View File

@ -16,20 +16,22 @@ class BatteriesApiController extends BaseApiController
public function TrackChargeCycle(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function TrackChargeCycle(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$trackedTime = date('Y-m-d H:i:s'); $requestBody = $request->getParsedBody();
if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']) && IsIsoDateTime($request->getQueryParams()['tracked_time']))
{
$trackedTime = $request->getQueryParams()['tracked_time'];
}
try try
{ {
$trackedTime = date('Y-m-d H:i:s');
if (array_key_exists('tracked_time', $requestBody) && IsIsoDateTime($requestBody['tracked_time']))
{
$trackedTime = $requestBody['tracked_time'];
}
$chargeCycleId = $this->BatteriesService->TrackChargeCycle($args['batteryId'], $trackedTime); $chargeCycleId = $this->BatteriesService->TrackChargeCycle($args['batteryId'], $trackedTime);
return $this->ApiResponse(array('charge_cycle_id' => $chargeCycleId)); return $this->ApiResponse(array('charge_cycle_id' => $chargeCycleId));
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -41,7 +43,7 @@ class BatteriesApiController extends BaseApiController
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -55,11 +57,11 @@ class BatteriesApiController extends BaseApiController
try try
{ {
$this->ApiResponse($this->BatteriesService->UndoChargeCycle($args['chargeCycleId'])); $this->ApiResponse($this->BatteriesService->UndoChargeCycle($args['chargeCycleId']));
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
} }

View File

@ -16,26 +16,28 @@ class ChoresApiController extends BaseApiController
public function TrackChoreExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function TrackChoreExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$trackedTime = date('Y-m-d H:i:s'); $requestBody = $request->getParsedBody();
if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']) && IsIsoDateTime($request->getQueryParams()['tracked_time']))
{
$trackedTime = $request->getQueryParams()['tracked_time'];
}
$doneBy = GROCY_USER_ID;
if (isset($request->getQueryParams()['done_by']) && !empty($request->getQueryParams()['done_by']))
{
$doneBy = $request->getQueryParams()['done_by'];
}
try try
{ {
$trackedTime = date('Y-m-d H:i:s');
if (array_key_exists('tracked_time', $requestBody) && IsIsoDateTime($requestBody['tracked_time']))
{
$trackedTime = $requestBody['tracked_time'];
}
$doneBy = GROCY_USER_ID;
if (array_key_exists('done_by', $requestBody) && !empty($requestBody['done_by']))
{
$doneBy = $requestBody['done_by'];
}
$choreExecutionId = $this->ChoresService->TrackChore($args['choreId'], $trackedTime, $doneBy); $choreExecutionId = $this->ChoresService->TrackChore($args['choreId'], $trackedTime, $doneBy);
return $this->ApiResponse(array('chore_execution_id' => $choreExecutionId)); return $this->ApiResponse(array('chore_execution_id' => $choreExecutionId));
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -47,7 +49,7 @@ class ChoresApiController extends BaseApiController
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -61,11 +63,11 @@ class ChoresApiController extends BaseApiController
try try
{ {
$this->ApiResponse($this->ChoresService->UndoChoreExecution($args['executionId'])); $this->ApiResponse($this->ChoresService->UndoChoreExecution($args['executionId']));
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
} }

View File

@ -30,11 +30,11 @@ class FilesApiController extends BaseApiController
$data = $request->getBody()->getContents(); $data = $request->getBody()->getContents();
file_put_contents($this->FilesService->GetFilePath($args['group'], $fileName), $data); file_put_contents($this->FilesService->GetFilePath($args['group'], $fileName), $data);
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -61,12 +61,12 @@ class FilesApiController extends BaseApiController
} }
else else
{ {
return $this->VoidApiActionResponse($response, false, 404, 'File not found'); return $this->GenericErrorResponse($response, 'File not found', 404);
} }
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -89,11 +89,11 @@ class FilesApiController extends BaseApiController
unlink($filePath); unlink($filePath);
} }
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
} }

View File

@ -12,7 +12,7 @@ class GenericEntityApiController extends BaseApiController
} }
else else
{ {
return $this->VoidApiActionResponse($response, false, 400, 'Entity does not exist or is not exposed'); return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
} }
} }
@ -24,7 +24,7 @@ class GenericEntityApiController extends BaseApiController
} }
else else
{ {
return $this->VoidApiActionResponse($response, false, 400, 'Entity does not exist or is not exposed'); return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
} }
} }
@ -44,16 +44,16 @@ class GenericEntityApiController extends BaseApiController
$newRow = $this->Database->{$args['entity']}()->createRow($requestBody); $newRow = $this->Database->{$args['entity']}()->createRow($requestBody);
$newRow->save(); $newRow->save();
$success = $newRow->isClean(); $success = $newRow->isClean();
return $this->ApiResponse(array('success' => $success)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
else else
{ {
return $this->VoidApiActionResponse($response, false, 400, 'Entity does not exist or is not exposed'); return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
} }
} }
@ -73,16 +73,16 @@ class GenericEntityApiController extends BaseApiController
$row = $this->Database->{$args['entity']}($args['objectId']); $row = $this->Database->{$args['entity']}($args['objectId']);
$row->update($requestBody); $row->update($requestBody);
$success = $row->isClean(); $success = $row->isClean();
return $this->ApiResponse(array('success' => $success)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
else else
{ {
return $this->VoidApiActionResponse($response, false, 400, 'Entity does not exist or is not exposed'); return $this->GenericErrorResponse($response, 'Entity does not exist or is not exposed');
} }
} }
@ -93,11 +93,11 @@ class GenericEntityApiController extends BaseApiController
$row = $this->Database->{$args['entity']}($args['objectId']); $row = $this->Database->{$args['entity']}($args['objectId']);
$row->delete(); $row->delete();
$success = $row->isClean(); $success = $row->isClean();
return $this->ApiResponse(array('success' => $success)); return $this->EmptyApiResponse($response);
} }
else else
{ {
return $this->VoidApiActionResponse($response, false, 400, 'Entity does not exist or is not exposed'); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }

View File

@ -17,7 +17,7 @@ class RecipesApiController extends BaseApiController
public function AddNotFulfilledProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function AddNotFulfilledProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$this->RecipesService->AddNotFulfilledProductsToShoppingList($args['recipeId']); $this->RecipesService->AddNotFulfilledProductsToShoppingList($args['recipeId']);
return $this->VoidApiActionResponse($response); return $this->EmptyApiResponse($response);
} }
public function ConsumeRecipe(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function ConsumeRecipe(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
@ -25,11 +25,11 @@ class RecipesApiController extends BaseApiController
try try
{ {
$this->RecipesService->ConsumeRecipe($args['recipeId']); $this->RecipesService->ConsumeRecipe($args['recipeId']);
return $this->VoidApiActionResponse($response); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
} }

View File

@ -22,7 +22,7 @@ class StockApiController extends BaseApiController
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -34,107 +34,155 @@ class StockApiController extends BaseApiController
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
public function AddProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function AddProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$bestBeforeDate = date('Y-m-d'); $requestBody = $request->getParsedBody();
if (isset($request->getQueryParams()['bestbeforedate']) && !empty($request->getQueryParams()['bestbeforedate']) && IsIsoDate($request->getQueryParams()['bestbeforedate']))
{
$bestBeforeDate = $request->getQueryParams()['bestbeforedate'];
}
$price = null;
if (isset($request->getQueryParams()['price']) && !empty($request->getQueryParams()['price']) && is_numeric($request->getQueryParams()['price']))
{
$price = $request->getQueryParams()['price'];
}
$transactionType = StockService::TRANSACTION_TYPE_PURCHASE;
if (isset($request->getQueryParams()['transactiontype']) && !empty($request->getQueryParams()['transactiontype']))
{
$transactionType = $request->getQueryParams()['transactiontype'];
}
try try
{ {
$bookingId = $this->StockService->AddProduct($args['productId'], $args['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price); if ($requestBody === null)
{
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
if (!array_key_exists('amount', $requestBody))
{
throw new \Exception('An amount is required');
}
$bestBeforeDate = date('Y-m-d');
if (array_key_exists('best_before_date', $requestBody) && IsIsoDate($requestBody['best_before_date']))
{
$bestBeforeDate = $requestBody['best_before_date'];
}
$price = null;
if (array_key_exists('price', $requestBody) && is_numeric($requestBody['price']))
{
$price = $requestBody['price'];
}
$transactionType = StockService::TRANSACTION_TYPE_PURCHASE;
if (array_key_exists('transaction_type', $requestBody) && !empty($requestBody['transactiontype']))
{
$transactionType = $requestBody['transactiontype'];
}
$bookingId = $this->StockService->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price);
return $this->ApiResponse(array('booking_id' => $bookingId)); return $this->ApiResponse(array('booking_id' => $bookingId));
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
public function ConsumeProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function ConsumeProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$spoiled = false; $requestBody = $request->getParsedBody();
if (isset($request->getQueryParams()['spoiled']) && !empty($request->getQueryParams()['spoiled']) && $request->getQueryParams()['spoiled'] == '1')
{
$spoiled = true;
}
$transactionType = StockService::TRANSACTION_TYPE_CONSUME;
if (isset($request->getQueryParams()['transactiontype']) && !empty($request->getQueryParams()['transactiontype']))
{
$transactionType = $request->getQueryParams()['transactiontype'];
}
$specificStockEntryId = "default";
if (isset($request->getQueryParams()['stock_entry_id']) && !empty($request->getQueryParams()['stock_entry_id']))
{
$specificStockEntryId = $request->getQueryParams()['stock_entry_id'];
}
try try
{ {
$bookingId = $this->StockService->ConsumeProduct($args['productId'], $args['amount'], $spoiled, $transactionType, $specificStockEntryId); if ($requestBody === null)
{
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
if (!array_key_exists('amount', $requestBody))
{
throw new \Exception('An amount is required');
}
$spoiled = false;
if (array_key_exists('spoiled', $requestBody))
{
$spoiled = $requestBody['spoiled'];
}
$transactionType = StockService::TRANSACTION_TYPE_CONSUME;
if (array_key_exists('transaction_type', $requestBody) && !empty($requestBody['transactiontype']))
{
$transactionType = $requestBody['transactiontype'];
}
$specificStockEntryId = 'default';
if (array_key_exists('stock_entry_id', $requestBody) && !empty($requestBody['stock_entry_id']))
{
$specificStockEntryId = $requestBody['stock_entry_id'];
}
$bookingId = $this->StockService->ConsumeProduct($args['productId'], $requestBody['amount'], $spoiled, $transactionType, $specificStockEntryId);
return $this->ApiResponse(array('booking_id' => $bookingId)); return $this->ApiResponse(array('booking_id' => $bookingId));
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
public function InventoryProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function InventoryProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$bestBeforeDate = date('Y-m-d'); $requestBody = $request->getParsedBody();
if (isset($request->getQueryParams()['bestbeforedate']) && !empty($request->getQueryParams()['bestbeforedate']) && IsIsoDate($request->getQueryParams()['bestbeforedate']))
{
$bestBeforeDate = $request->getQueryParams()['bestbeforedate'];
}
try try
{ {
$bookingId = $this->StockService->InventoryProduct($args['productId'], $args['newAmount'], $bestBeforeDate); if ($requestBody === null)
{
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
if (!array_key_exists('new_amount', $requestBody))
{
throw new \Exception('An new amount is required');
}
$bestBeforeDate = date('Y-m-d');
if (array_key_exists('best_before_date', $requestBody) && IsIsoDate($requestBody['best_before_date']))
{
$bestBeforeDate = $requestBody['best_before_date'];
}
$bookingId = $this->StockService->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate);
return $this->ApiResponse(array('booking_id' => $bookingId)); return $this->ApiResponse(array('booking_id' => $bookingId));
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
public function OpenProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function OpenProduct(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$specificStockEntryId = "default"; $requestBody = $request->getParsedBody();
if (isset($request->getQueryParams()['stock_entry_id']) && !empty($request->getQueryParams()['stock_entry_id']))
{
$specificStockEntryId = $request->getQueryParams()['stock_entry_id'];
}
try try
{ {
$bookingId = $this->StockService->OpenProduct($args['productId'], $args['amount'], $specificStockEntryId); if ($requestBody === null)
{
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
}
if (!array_key_exists('amount', $requestBody))
{
throw new \Exception('An amount is required');
}
$specificStockEntryId = 'default';
if (array_key_exists('stock_entry_id', $requestBody) && !empty($requestBody['stock_entry_id']))
{
$specificStockEntryId = $requestBody['stock_entry_id'];
}
$bookingId = $this->StockService->OpenProduct($args['productId'], $requestBody['amount'], $specificStockEntryId);
return $this->ApiResponse(array('booking_id' => $bookingId)); return $this->ApiResponse(array('booking_id' => $bookingId));
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -164,13 +212,13 @@ class StockApiController extends BaseApiController
public function AddMissingProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function AddMissingProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$this->StockService->AddMissingProductsToShoppingList(); $this->StockService->AddMissingProductsToShoppingList();
return $this->VoidApiActionResponse($response); return $this->EmptyApiResponse($response);
} }
public function ClearShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function ClearShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$this->StockService->ClearShoppingList(); $this->StockService->ClearShoppingList();
return $this->VoidApiActionResponse($response); return $this->EmptyApiResponse($response);
} }
public function ExternalBarcodeLookup(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function ExternalBarcodeLookup(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
@ -187,7 +235,7 @@ class StockApiController extends BaseApiController
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -196,11 +244,11 @@ class StockApiController extends BaseApiController
try try
{ {
$this->ApiResponse($this->StockService->UndoBooking($args['bookingId'])); $this->ApiResponse($this->StockService->UndoBooking($args['bookingId']));
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }

View File

@ -30,11 +30,11 @@ class SystemApiController extends BaseApiController
$requestBody = $request->getParsedBody(); $requestBody = $request->getParsedBody();
$this->LocalizationService->LogMissingLocalization(GROCY_CULTURE, $requestBody['text']); $this->LocalizationService->LogMissingLocalization(GROCY_CULTURE, $requestBody['text']);
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
} }

View File

@ -21,20 +21,22 @@ class TasksApiController extends BaseApiController
public function MarkTaskAsCompleted(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) public function MarkTaskAsCompleted(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
{ {
$doneTime = date('Y-m-d H:i:s'); $requestBody = $request->getParsedBody();
if (isset($request->getQueryParams()['done_time']) && !empty($request->getQueryParams()['done_time']) && IsIsoDateTime($request->getQueryParams()['done_time']))
{
$doneTime = $request->getQueryParams()['done_time'];
}
try try
{ {
$doneTime = date('Y-m-d H:i:s');
if (array_key_exists('done_time', $requestBody) && IsIsoDateTime($requestBody['done_time']))
{
$doneTime = $requestBody['done_time'];
}
$this->TasksService->MarkTaskAsCompleted($args['taskId'], $doneTime); $this->TasksService->MarkTaskAsCompleted($args['taskId'], $doneTime);
return $this->VoidApiActionResponse($response); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
} }

View File

@ -22,7 +22,7 @@ class UsersApiController extends BaseApiController
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -38,11 +38,11 @@ class UsersApiController extends BaseApiController
} }
$this->UsersService->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']); $this->UsersService->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -51,11 +51,11 @@ class UsersApiController extends BaseApiController
try try
{ {
$this->UsersService->DeleteUser($args['userId']); $this->UsersService->DeleteUser($args['userId']);
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -66,11 +66,11 @@ class UsersApiController extends BaseApiController
try try
{ {
$this->UsersService->EditUser($args['userId'], $requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']); $this->UsersService->EditUser($args['userId'], $requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -83,7 +83,7 @@ class UsersApiController extends BaseApiController
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
@ -94,11 +94,11 @@ class UsersApiController extends BaseApiController
$requestBody = $request->getParsedBody(); $requestBody = $request->getParsedBody();
$value = $this->UsersService->SetUserSetting(GROCY_USER_ID, $args['settingKey'], $requestBody['value']); $value = $this->UsersService->SetUserSetting(GROCY_USER_ID, $args['settingKey'], $requestBody['value']);
return $this->ApiResponse(array('success' => true)); return $this->EmptyApiResponse($response);
} }
catch (\Exception $ex) catch (\Exception $ex)
{ {
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage()); return $this->GenericErrorResponse($response, $ex->getMessage());
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -125,12 +125,19 @@ Grocy.Api.Get = function(apiFunction, success, error)
{ {
if (xhr.readyState === XMLHttpRequest.DONE) if (xhr.readyState === XMLHttpRequest.DONE)
{ {
if (xhr.status === 200) if (xhr.status === 200 || xhr.status === 204)
{ {
if (success) if (success)
{
if (xhr.status === 200)
{ {
success(JSON.parse(xhr.responseText)); success(JSON.parse(xhr.responseText));
} }
else
{
success({ });
}
}
} }
else else
{ {
@ -155,12 +162,19 @@ Grocy.Api.Post = function(apiFunction, jsonData, success, error)
{ {
if (xhr.readyState === XMLHttpRequest.DONE) if (xhr.readyState === XMLHttpRequest.DONE)
{ {
if (xhr.status === 200) if (xhr.status === 200 || xhr.status === 204)
{ {
if (success) if (success)
{
if (xhr.status === 200)
{ {
success(JSON.parse(xhr.responseText)); success(JSON.parse(xhr.responseText));
} }
else
{
success({ });
}
}
} }
else else
{ {
@ -186,12 +200,19 @@ Grocy.Api.Put = function(apiFunction, jsonData, success, error)
{ {
if (xhr.readyState === XMLHttpRequest.DONE) if (xhr.readyState === XMLHttpRequest.DONE)
{ {
if (xhr.status === 200) if (xhr.status === 200 || xhr.status === 204)
{ {
if (success) if (success)
{
if (xhr.status === 200)
{ {
success(JSON.parse(xhr.responseText)); success(JSON.parse(xhr.responseText));
} }
else
{
success({ });
}
}
} }
else else
{ {
@ -217,12 +238,19 @@ Grocy.Api.Delete = function(apiFunction, jsonData, success, error)
{ {
if (xhr.readyState === XMLHttpRequest.DONE) if (xhr.readyState === XMLHttpRequest.DONE)
{ {
if (xhr.status === 200) if (xhr.status === 200 || xhr.status === 204)
{ {
if (success) if (success)
{
if (xhr.status === 200)
{ {
success(JSON.parse(xhr.responseText)); success(JSON.parse(xhr.responseText));
} }
else
{
success({ });
}
}
} }
else else
{ {
@ -386,7 +414,7 @@ $(".user-setting-control").on("change", function()
jsonData = { }; jsonData = { };
jsonData.value = value; jsonData.value = value;
Grocy.Api.Post('user/settings/' + settingKey, jsonData, Grocy.Api.Put('user/settings/' + settingKey, jsonData,
function(result) function(result)
{ {
// Nothing to do... // Nothing to do...

View File

@ -1,4 +1,4 @@
Grocy.Api.Get('system/get-db-changed-time', Grocy.Api.Get('system/db-changed-time',
function(result) function(result)
{ {
Grocy.DatabaseChangedTime = moment(result.changed_time); Grocy.DatabaseChangedTime = moment(result.changed_time);
@ -14,7 +14,7 @@
// when there is no unsaved form data and when the user enabled auto reloading // when there is no unsaved form data and when the user enabled auto reloading
setInterval(function() setInterval(function()
{ {
Grocy.Api.Get('system/get-db-changed-time', Grocy.Api.Get('system/db-changed-time',
function(result) function(result)
{ {
var newDbChangedTime = moment(result.changed_time); var newDbChangedTime = moment(result.changed_time);

View File

@ -52,7 +52,7 @@ $(document).on('click', '.battery-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/batteries/' + objectId, Grocy.Api.Delete('objects/batteries/' + objectId, { },
function(result) function(result)
{ {
window.location.href = U('/batteries'); window.location.href = U('/batteries');

View File

@ -56,7 +56,7 @@ $(document).on('click', '.undo-battery-execution-button', function(e)
var element = $(e.currentTarget); var element = $(e.currentTarget);
var chargeCycleId = $(e.currentTarget).attr('data-charge-cycle-id'); var chargeCycleId = $(e.currentTarget).attr('data-charge-cycle-id');
Grocy.Api.Post('batteries/' + chargeCycleId.toString() + '/undo', Grocy.Api.Post('batteries/' + chargeCycleId.toString() + '/undo', { },
function(result) function(result)
{ {
element.closest("tr").addClass("text-muted"); element.closest("tr").addClass("text-muted");

View File

@ -66,7 +66,7 @@ $(document).on('click', '.track-charge-cycle-button', function(e)
var batteryName = $(e.currentTarget).attr('data-battery-name'); var batteryName = $(e.currentTarget).attr('data-battery-name');
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss'); var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Post('batteries/' + batteryId + '/charged?tracked_time=' + trackedTime, Grocy.Api.Post('batteries/' + batteryId + '/charge', { 'tracked_time': trackedTime },
function() function()
{ {
Grocy.Api.Get('batteries/' + batteryId, Grocy.Api.Get('batteries/' + batteryId,

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/batteries', jsonData, Grocy.Api.Post('objects/batteries', jsonData,
function(result) function(result)
{ {
window.location.href = U('/batteries'); window.location.href = U('/batteries');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Put('object/batteries/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/batteries/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/batteries'); window.location.href = U('/batteries');

View File

@ -8,7 +8,7 @@
Grocy.Api.Get('batteries/' + jsonForm.battery_id, Grocy.Api.Get('batteries/' + jsonForm.battery_id,
function (batteryDetails) function (batteryDetails)
{ {
Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge?tracked_time=' + $('#tracked_time').find('input').val(), Grocy.Api.Post('batteries/' + jsonForm.battery_id + '/charge', { 'tracked_time': $('#tracked_time').find('input').val() },
function(result) function(result)
{ {
Grocy.FrontendHelpers.EndUiBusy("batterytracking-form"); Grocy.FrontendHelpers.EndUiBusy("batterytracking-form");
@ -92,7 +92,7 @@ $('#tracked_time').find('input').on('keypress', function (e)
function UndoChargeCycle(chargeCycleId) function UndoChargeCycle(chargeCycleId)
{ {
Grocy.Api.Post('batteries' + chargeCycleId.toString() + '/undo', Grocy.Api.Post('batteries/' + chargeCycleId.toString() + '/undo', { },
function(result) function(result)
{ {
toastr.success(L("Charge cycle successfully undone")); toastr.success(L("Charge cycle successfully undone"));

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/chores', jsonData, Grocy.Api.Post('objects/chores', jsonData,
function(result) function(result)
{ {
window.location.href = U('/chores'); window.location.href = U('/chores');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Put('object/chores/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/chores/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/chores'); window.location.href = U('/chores');

View File

@ -52,7 +52,7 @@ $(document).on('click', '.chore-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/chores/' + objectId, Grocy.Api.Delete('objects/chores/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/chores'); window.location.href = U('/chores');

View File

@ -56,7 +56,7 @@ $(document).on('click', '.undo-chore-execution-button', function(e)
var element = $(e.currentTarget); var element = $(e.currentTarget);
var executionId = $(e.currentTarget).attr('data-execution-id'); var executionId = $(e.currentTarget).attr('data-execution-id');
Grocy.Api.Post('chores/' + executionId.toString() + '/undo', Grocy.Api.Post('chores/' + executionId.toString() + '/undo', { },
function(result) function(result)
{ {
element.closest("tr").addClass("text-muted"); element.closest("tr").addClass("text-muted");

View File

@ -66,7 +66,7 @@ $(document).on('click', '.track-chore-button', function(e)
var choreName = $(e.currentTarget).attr('data-chore-name'); var choreName = $(e.currentTarget).attr('data-chore-name');
var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss'); var trackedTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Post('chores/' + choreId + '/execute?tracked_time=' + trackedTime, Grocy.Api.Post('chores/' + choreId + '/execute', { 'tracked_time': trackedTime },
function() function()
{ {
Grocy.Api.Get('chores/' + choreId, Grocy.Api.Get('chores/' + choreId,

View File

@ -8,7 +8,7 @@
Grocy.Api.Get('chores/' + jsonForm.chore_id, Grocy.Api.Get('chores/' + jsonForm.chore_id,
function (choreDetails) function (choreDetails)
{ {
Grocy.Api.Post('chores/' + jsonForm.chore_id + '/execute?tracked_time=' + Grocy.Components.DateTimePicker.GetValue() + "&done_by=" + Grocy.Components.UserPicker.GetValue(), Grocy.Api.Post('chores/' + jsonForm.chore_id + '/execute', { 'tracked_time': Grocy.Components.DateTimePicker.GetValue(), 'done_by': Grocy.Components.UserPicker.GetValue() },
function(result) function(result)
{ {
Grocy.FrontendHelpers.EndUiBusy("choretracking-form"); Grocy.FrontendHelpers.EndUiBusy("choretracking-form");
@ -89,7 +89,7 @@ Grocy.Components.DateTimePicker.GetInputElement().on('keypress', function(e)
function UndoChoreExecution(executionId) function UndoChoreExecution(executionId)
{ {
Grocy.Api.Post('chores/' + executionId.toString() + '/undo', Grocy.Api.Post('chores/' + executionId.toString() + '/undo', { },
function(result) function(result)
{ {
toastr.success(L("Chore execution successfully undone")); toastr.success(L("Chore execution successfully undone"));

View File

@ -2,7 +2,7 @@ Grocy.Components.ProductCard = { };
Grocy.Components.ProductCard.Refresh = function(productId) Grocy.Components.ProductCard.Refresh = function(productId)
{ {
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(productDetails) function(productDetails)
{ {
var stockAmount = productDetails.stock_amount || '0'; var stockAmount = productDetails.stock_amount || '0';
@ -58,7 +58,7 @@ Grocy.Components.ProductCard.Refresh = function(productId)
} }
); );
Grocy.Api.Get('stock/' + productId + '/pricehistory', Grocy.Api.Get('stock/products/' + productId + '/price-history',
function(priceHistoryDataPoints) function(priceHistoryDataPoints)
{ {
if (priceHistoryDataPoints.length > 0) if (priceHistoryDataPoints.length > 0)

View File

@ -10,23 +10,21 @@
jsonForm.amount = 1; jsonForm.amount = 1;
} }
var spoiled = 0; var apiUrl = 'stock/products/' + jsonForm.product_id + '/consume';
if ($('#spoiled').is(':checked'))
{
spoiled = 1;
}
var apiUrl = 'stock/' + jsonForm.product_id + '/consume/' + jsonForm.amount + '?spoiled=' + spoiled; var jsonData = {};
jsonData.amount = jsonForm.amount;
jsonData.spoiled = $('#spoiled').is(':checked');
if ($("#use_specific_stock_entry").is(":checked")) if ($("#use_specific_stock_entry").is(":checked"))
{ {
apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry; jsonData.stock_entry_id = jsonForm.specific_stock_entry;
} }
Grocy.Api.Get('stock/' + jsonForm.product_id, Grocy.Api.Get('stock/products/' + jsonForm.product_id,
function(productDetails) function(productDetails)
{ {
Grocy.Api.Post(apiUrl, Grocy.Api.Post(apiUrl, jsonData,
function(result) function(result)
{ {
$("#specific_stock_entry").find("option").remove().end().append("<option></option>"); $("#specific_stock_entry").find("option").remove().end().append("<option></option>");
@ -70,17 +68,20 @@ $('#save-mark-as-open-button').on('click', function(e)
jsonForm.amount = 1; jsonForm.amount = 1;
} }
var apiUrl = 'stock/' + jsonForm.product_id + '/open/' + jsonForm.amount; var apiUrl = 'stock/products/' + jsonForm.product_id + '/open';
jsonData = { };
jsonData.amount = jsonForm.amount;
if ($("#use_specific_stock_entry").is(":checked")) if ($("#use_specific_stock_entry").is(":checked"))
{ {
apiUrl += "&stock_entry_id=" + jsonForm.specific_stock_entry; jsonData.stock_entry_id = jsonForm.specific_stock_entry;
} }
Grocy.Api.Get('stock/' + jsonForm.product_id, Grocy.Api.Get('stock/products/' + jsonForm.product_id,
function(productDetails) function(productDetails)
{ {
Grocy.Api.Post(apiUrl, Grocy.Api.Post(apiUrl, jsonData,
function(result) function(result)
{ {
$("#specific_stock_entry").find("option").remove().end().append("<option></option>"); $("#specific_stock_entry").find("option").remove().end().append("<option></option>");
@ -126,7 +127,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(productDetails) function(productDetails)
{ {
$('#amount').attr('max', productDetails.stock_amount); $('#amount').attr('max', productDetails.stock_amount);
@ -161,7 +162,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
} }
); );
Grocy.Api.Get("stock/" + productId, Grocy.Api.Get("stock/products/" + productId + '/entries',
function(stockEntries) function(stockEntries)
{ {
stockEntries.forEach(stockEntry => stockEntries.forEach(stockEntry =>
@ -249,7 +250,7 @@ $("#use_specific_stock_entry").on("change", function()
function UndoStockBooking(bookingId) function UndoStockBooking(bookingId)
{ {
Grocy.Api.Post('booking/' + bookingId.toString() + '/undo', Grocy.Api.Post('stock/bookings/' + bookingId.toString() + '/undo', { },
function(result) function(result)
{ {
toastr.success(L("Booking successfully undone")); toastr.success(L("Booking successfully undone"));

View File

@ -34,7 +34,7 @@ equipmentTable.on('select', function(e, dt, type, indexes)
function DisplayEquipment(id) function DisplayEquipment(id)
{ {
Grocy.Api.Get('object/equipment/' + id, Grocy.Api.Get('objects/equipment/' + id,
function(equipmentItem) function(equipmentItem)
{ {
$(".selected-equipment-name").text(equipmentItem.name); $(".selected-equipment-name").text(equipmentItem.name);
@ -98,7 +98,7 @@ $(document).on('click', '.equipment-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/equipment/' + objectId, Grocy.Api.Delete('objects/equipment/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/equipment'); window.location.href = U('/equipment');

View File

@ -18,7 +18,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/equipment', jsonData, Grocy.Api.Post('objects/equipment', jsonData,
function(result) function(result)
{ {
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)
@ -51,7 +51,7 @@
{ {
if (Grocy.DeleteInstructionManualOnSave) if (Grocy.DeleteInstructionManualOnSave)
{ {
Grocy.Api.DeleteFile(Grocy.InstructionManualFileNameName, 'equipmentmanuals', Grocy.Api.DeleteFile(Grocy.InstructionManualFileNameName, 'equipmentmanuals', {},
function(result) function(result)
{ {
// Nothing to do // Nothing to do
@ -64,7 +64,7 @@
); );
}; };
Grocy.Api.Put('object/equipment/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/equipment/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave) if (jsonData.hasOwnProperty("instruction_manual_file_name") && !Grocy.DeleteInstructionManualOnSave)

View File

@ -5,10 +5,14 @@
var jsonForm = $('#inventory-form').serializeJSON(); var jsonForm = $('#inventory-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("inventory-form"); Grocy.FrontendHelpers.BeginUiBusy("inventory-form");
Grocy.Api.Get('stock/' + jsonForm.product_id, Grocy.Api.Get('stock/products/' + jsonForm.product_id,
function (productDetails) function (productDetails)
{ {
Grocy.Api.Post('stock/' + jsonForm.product_id + '/inventory/' + jsonForm.new_amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue(), var jsonData = { };
jsonData.new_amount = jsonForm.new_amount;
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
function(result) function(result)
{ {
var addBarcode = GetUriParam('addbarcodetoselection'); var addBarcode = GetUriParam('addbarcodetoselection');
@ -24,7 +28,7 @@
productDetails.product.barcode += ',' + addBarcode; productDetails.product.barcode += ',' + addBarcode;
} }
Grocy.Api.Put('object/products/' + productDetails.product.id, productDetails.product, Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
function (result) { }, function (result) { },
function(xhr) function(xhr)
{ {
@ -73,7 +77,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(productDetails) function(productDetails)
{ {
$('#new_amount').attr('not-equal', productDetails.stock_amount); $('#new_amount').attr('not-equal', productDetails.stock_amount);
@ -157,7 +161,7 @@ $('#new_amount').on('keyup', function(e)
if (productId) if (productId)
{ {
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(productDetails) function(productDetails)
{ {
var productStockAmount = parseInt(productDetails.stock_amount || '0'); var productStockAmount = parseInt(productDetails.stock_amount || '0');

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/locations', jsonData, Grocy.Api.Post('objects/locations', jsonData,
function(result) function(result)
{ {
window.location.href = U('/locations'); window.location.href = U('/locations');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Put('object/locations/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/locations/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/locations'); window.location.href = U('/locations');

View File

@ -52,7 +52,7 @@ $(document).on('click', '.location-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/locations/' + objectId, Grocy.Api.Delete('objects/locations/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/locations'); window.location.href = U('/locations');

View File

@ -58,7 +58,7 @@ $(document).on('click', '.apikey-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/api_keys/' + objectId, Grocy.Api.Delete('objects/api_keys/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/manageapikeys'); window.location.href = U('/manageapikeys');

View File

@ -25,7 +25,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/products', jsonData, Grocy.Api.Post('objects/products', jsonData,
function (result) function (result)
{ {
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave) if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
@ -58,7 +58,7 @@
{ {
if (Grocy.DeleteProductPictureOnSave) if (Grocy.DeleteProductPictureOnSave)
{ {
Grocy.Api.DeleteFile(Grocy.ProductPictureFileName, 'productpictures', Grocy.Api.DeleteFile(Grocy.ProductPictureFileName, 'productpictures', {},
function(result) function(result)
{ {
// Nothing to do // Nothing to do
@ -71,7 +71,7 @@
); );
}; };
Grocy.Api.Put('object/products/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/products/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave) if (jsonData.hasOwnProperty("picture_file_name") && !Grocy.DeleteProductPictureOnSave)
@ -110,7 +110,7 @@ $('#barcode-taginput').tagsManager({
if (Grocy.EditMode === 'edit') if (Grocy.EditMode === 'edit')
{ {
Grocy.Api.Get('object/products/' + Grocy.EditObjectId, Grocy.Api.Get('objects/products/' + Grocy.EditObjectId,
function (product) function (product)
{ {
if (product.barcode !== null && product.barcode.length > 0) if (product.barcode !== null && product.barcode.length > 0)

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/product_groups', jsonData, Grocy.Api.Post('objects/product_groups', jsonData,
function(result) function(result)
{ {
window.location.href = U('/productgroups'); window.location.href = U('/productgroups');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Put('object/product_groups/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/product_groups/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/productgroups'); window.location.href = U('/productgroups');

View File

@ -52,7 +52,7 @@ $(document).on('click', '.product-group-delete-button', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/product_groups/' + objectId, Grocy.Api.Delete('objects/product_groups/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/productgroups'); window.location.href = U('/productgroups');

View File

@ -36,7 +36,7 @@ $(document).on('click', '.product-delete-button', function (e)
var objectName = $(e.currentTarget).attr('data-product-name'); var objectName = $(e.currentTarget).attr('data-product-name');
var objectId = $(e.currentTarget).attr('data-product-id'); var objectId = $(e.currentTarget).attr('data-product-id');
Grocy.Api.Get('stock/' + objectId, Grocy.Api.Get('stock/products/' + objectId,
function(productDetails) function(productDetails)
{ {
var stockAmount = productDetails.stock_amount || '0'; var stockAmount = productDetails.stock_amount || '0';
@ -59,7 +59,7 @@ $(document).on('click', '.product-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/products/' + objectId, Grocy.Api.Delete('objects/products/' + objectId, {},
function (result) function (result)
{ {
window.location.href = U('/products'); window.location.href = U('/products');

View File

@ -5,7 +5,7 @@
var jsonForm = $('#purchase-form').serializeJSON(); var jsonForm = $('#purchase-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("purchase-form"); Grocy.FrontendHelpers.BeginUiBusy("purchase-form");
Grocy.Api.Get('stock/' + jsonForm.product_id, Grocy.Api.Get('stock/products/' + jsonForm.product_id,
function(productDetails) function(productDetails)
{ {
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock; var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
@ -16,7 +16,12 @@
price = parseFloat(jsonForm.price).toFixed(2); price = parseFloat(jsonForm.price).toFixed(2);
} }
Grocy.Api.Post('stock/' + jsonForm.product_id + '/add/' + amount + '?bestbeforedate=' + Grocy.Components.DateTimePicker.GetValue() + '&price=' + price, var jsonData = {};
jsonData.amount = amount;
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
jsonData.price = price;
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/add', jsonData,
function(result) function(result)
{ {
var addBarcode = GetUriParam('addbarcodetoselection'); var addBarcode = GetUriParam('addbarcodetoselection');
@ -32,7 +37,7 @@
productDetails.product.barcode += ',' + addBarcode; productDetails.product.barcode += ',' + addBarcode;
} }
Grocy.Api.Put('object/products/' + productDetails.product.id, productDetails.product, Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
function (result) { }, function (result) { },
function(xhr) function(xhr)
{ {
@ -89,7 +94,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(productDetails) function(productDetails)
{ {
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/quantity_units', jsonData, Grocy.Api.Post('objects/quantity_units', jsonData,
function(result) function(result)
{ {
window.location.href = U('/quantityunits'); window.location.href = U('/quantityunits');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Put('object/quantity_units/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/quantity_units/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/quantityunits'); window.location.href = U('/quantityunits');

View File

@ -52,7 +52,7 @@ $(document).on('click', '.quantityunit-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/quantity_units/' + objectId, Grocy.Api.Delete('objects/quantity_units/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/quantityunits'); window.location.href = U('/quantityunits');

View File

@ -5,7 +5,7 @@
var jsonData = $('#recipe-form').serializeJSON(); var jsonData = $('#recipe-form').serializeJSON();
Grocy.FrontendHelpers.BeginUiBusy("recipe-form"); Grocy.FrontendHelpers.BeginUiBusy("recipe-form");
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipes'); window.location.href = U('/recipes');
@ -113,8 +113,8 @@ $(document).on('click', '.recipe-pos-delete-button', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { }); Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Delete('object/recipes_pos/' + objectId, Grocy.Api.Delete('objects/recipes_pos/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
@ -150,8 +150,8 @@ $(document).on('click', '.recipe-include-delete-button', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { }); Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function() { }, function() { });
Grocy.Api.Delete('object/recipes_nestings/' + objectId, Grocy.Api.Delete('objects/recipes_nestings/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
@ -178,10 +178,10 @@ $(document).on('click', '.recipe-pos-order-missing-button', function(e)
jsonData.amount = productAmount; jsonData.amount = productAmount;
jsonData.note = L('Added for recipe #1', recipeName); jsonData.note = L('Added for recipe #1', recipeName);
Grocy.Api.Post('object/shopping_list', jsonData, Grocy.Api.Post('objects/shopping_list', jsonData,
function(result) function(result)
{ {
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { }); Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), function () { }, function () { });
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
}, },
function(xhr) function(xhr)
@ -202,7 +202,7 @@ $(document).on('click', '.recipe-pos-edit-button', function (e)
{ {
var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id'); var recipePosId = $(e.currentTarget).attr('data-recipe-pos-id');
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId); window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/' + recipePosId);
@ -219,7 +219,7 @@ $(document).on('click', '.recipe-include-edit-button', function (e)
var id = $(e.currentTarget).attr('data-recipe-include-id'); var id = $(e.currentTarget).attr('data-recipe-include-id');
var recipeId = $(e.currentTarget).attr('data-recipe-included-recipe-id'); var recipeId = $(e.currentTarget).attr('data-recipe-included-recipe-id');
console.log(recipeId); console.log(recipeId);
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
$("#recipe-include-editform-title").text(L("Edit included recipe")); $("#recipe-include-editform-title").text(L("Edit included recipe"));
@ -238,7 +238,7 @@ $(document).on('click', '.recipe-include-edit-button', function (e)
$("#recipe-pos-add-button").on("click", function(e) $("#recipe-pos-add-button").on("click", function(e)
{ {
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new'); window.location.href = U('/recipe/' + Grocy.EditObjectId + '/pos/new');
@ -252,7 +252,7 @@ $("#recipe-pos-add-button").on("click", function(e)
$("#recipe-include-add-button").on("click", function(e) $("#recipe-include-add-button").on("click", function(e)
{ {
Grocy.Api.Put('object/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(), Grocy.Api.Put('objects/recipes/' + Grocy.EditObjectId, $('#recipe-form').serializeJSON(),
function(result) function(result)
{ {
$("#recipe-include-editform-title").text(L("Add included recipe")); $("#recipe-include-editform-title").text(L("Add included recipe"));
@ -280,7 +280,7 @@ $('#save-recipe-include-button').on('click', function(e)
if (editMode === 'create') if (editMode === 'create')
{ {
Grocy.Api.Post('object/recipes_nestings', jsonData, Grocy.Api.Post('objects/recipes_nestings', jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);
@ -293,7 +293,7 @@ $('#save-recipe-include-button').on('click', function(e)
} }
else else
{ {
Grocy.Api.Put('object/recipes_nestings/' + nestingId, jsonData, Grocy.Api.Put('objects/recipes_nestings/' + nestingId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectId); window.location.href = U('/recipe/' + Grocy.EditObjectId);

View File

@ -9,7 +9,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/recipes_pos', jsonData, Grocy.Api.Post('objects/recipes_pos', jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectParentId); window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
@ -23,7 +23,7 @@
} }
else else
{ {
Grocy.Api.Put('object/recipes_pos/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/recipes_pos/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/recipe/' + Grocy.EditObjectParentId); window.location.href = U('/recipe/' + Grocy.EditObjectParentId);
@ -45,7 +45,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function (productDetails) function (productDetails)
{ {
if (!$("#only_check_single_unit_in_stock").is(":checked")) if (!$("#only_check_single_unit_in_stock").is(":checked"))

View File

@ -63,7 +63,7 @@ $("#selectedRecipeDeleteButton").on('click', function(e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/recipes/' + objectId, Grocy.Api.Delete('objects/recipes/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/recipes'); window.location.href = U('/recipes');
@ -101,7 +101,7 @@ $(document).on('click', '.recipe-order-missing-button', function(e)
{ {
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Post('recipes/' + objectId + '/shoppinglist', Grocy.Api.Post('recipes/' + objectId + '/add-not-fulfilled-products-to-shoppinglist', { },
function(result) function(result)
{ {
window.location.href = U('/recipes'); window.location.href = U('/recipes');
@ -140,7 +140,7 @@ $("#selectedRecipeConsumeButton").on('click', function(e)
{ {
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Get('recipes/' + objectId + '/consume', Grocy.Api.Post('recipes/' + objectId + '/consume', { },
function(result) function(result)
{ {
Grocy.FrontendHelpers.EndUiBusy(); Grocy.FrontendHelpers.EndUiBusy();

View File

@ -64,7 +64,7 @@ $(document).on('click', '.shoppinglist-delete-button', function (e)
var shoppingListItemId = $(e.currentTarget).attr('data-shoppinglist-id'); var shoppingListItemId = $(e.currentTarget).attr('data-shoppinglist-id');
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Delete('object/shopping_list/' + shoppingListItemId, Grocy.Api.Delete('objects/shopping_list/' + shoppingListItemId, {},
function(result) function(result)
{ {
$('#shoppinglistitem-' + shoppingListItemId + '-row').fadeOut(500, function() $('#shoppinglistitem-' + shoppingListItemId + '-row').fadeOut(500, function()
@ -84,7 +84,7 @@ $(document).on('click', '.shoppinglist-delete-button', function (e)
$(document).on('click', '#add-products-below-min-stock-amount', function(e) $(document).on('click', '#add-products-below-min-stock-amount', function(e)
{ {
Grocy.Api.Post('stock/shoppinglist', Grocy.Api.Post('stock/shoppinglist/add-missing-products', { },
function(result) function(result)
{ {
window.location.href = U('/shoppinglist'); window.location.href = U('/shoppinglist');
@ -116,7 +116,7 @@ $(document).on('click', '#clear-shopping-list', function(e)
{ {
Grocy.FrontendHelpers.BeginUiBusy(); Grocy.FrontendHelpers.BeginUiBusy();
Grocy.Api.Post('stock/clearshoppinglist', Grocy.Api.Post('stock/shoppinglist/clear', { },
function(result) function(result)
{ {
$('#shoppinglist-table tbody tr').fadeOut(500, function() $('#shoppinglist-table tbody tr').fadeOut(500, function()

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/shopping_list', jsonData, Grocy.Api.Post('objects/shopping_list', jsonData,
function(result) function(result)
{ {
window.location.href = U('/shoppinglist'); window.location.href = U('/shoppinglist');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Put('object/shopping_list/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/shopping_list/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/shoppinglist'); window.location.href = U('/shoppinglist');
@ -43,7 +43,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
{ {
Grocy.Components.ProductCard.Refresh(productId); Grocy.Components.ProductCard.Refresh(productId);
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function (productDetails) function (productDetails)
{ {
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);

View File

@ -56,7 +56,7 @@ $(document).on('click', '.undo-stock-booking-button', function(e)
var element = $(e.currentTarget); var element = $(e.currentTarget);
var bookingId = $(e.currentTarget).attr('data-booking-id'); var bookingId = $(e.currentTarget).attr('data-booking-id');
Grocy.Api.Get('booking/' + bookingId.toString() + '/undo', Grocy.Api.Post('stock/bookings/' + bookingId.toString() + '/undo', { },
function(result) function(result)
{ {
element.closest("tr").addClass("text-muted"); element.closest("tr").addClass("text-muted");

View File

@ -92,10 +92,10 @@ $(document).on('click', '.product-consume-button', function(e)
var productQuName = $(e.currentTarget).attr('data-product-qu-name'); var productQuName = $(e.currentTarget).attr('data-product-qu-name');
var consumeAmount = $(e.currentTarget).attr('data-consume-amount'); var consumeAmount = $(e.currentTarget).attr('data-consume-amount');
Grocy.Api.Post('stock/' + productId + '/consume/' + consumeAmount, Grocy.Api.Post('stock/products/' + productId + '/consume', { 'amount': consumeAmount },
function() function()
{ {
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(result) function(result)
{ {
var productRow = $('#product-' + productId + '-row'); var productRow = $('#product-' + productId + '-row');
@ -189,10 +189,10 @@ $(document).on('click', '.product-open-button', function(e)
var productQuName = $(e.currentTarget).attr('data-product-qu-name'); var productQuName = $(e.currentTarget).attr('data-product-qu-name');
var button = $(e.currentTarget); var button = $(e.currentTarget);
Grocy.Api.Get('stock/' + productId + 'open/1', Grocy.Api.Post('stock/products/' + productId + '/open', { 'amount': 1 },
function() function()
{ {
Grocy.Api.Get('stock/' + productId, Grocy.Api.Get('stock/products/' + productId,
function(result) function(result)
{ {
var productRow = $('#product-' + productId + '-row'); var productRow = $('#product-' + productId + '-row');

View File

@ -52,7 +52,7 @@ $(document).on('click', '.task-category-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/task_categories/' + objectId, Grocy.Api.Delete('objects/task_categories/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/taskcategories'); window.location.href = U('/taskcategories');

View File

@ -7,7 +7,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/task_categories', jsonData, Grocy.Api.Post('objects/task_categories', jsonData,
function(result) function(result)
{ {
window.location.href = U('/taskcategories'); window.location.href = U('/taskcategories');
@ -21,7 +21,7 @@
} }
else else
{ {
Grocy.Api.Put('object/task_categories/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/task_categories/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/taskcategories'); window.location.href = U('/taskcategories');

View File

@ -11,7 +11,7 @@
if (Grocy.EditMode === 'create') if (Grocy.EditMode === 'create')
{ {
Grocy.Api.Post('object/tasks', jsonData, Grocy.Api.Post('objects/tasks', jsonData,
function(result) function(result)
{ {
window.location.href = U('/tasks'); window.location.href = U('/tasks');
@ -25,7 +25,7 @@
} }
else else
{ {
Grocy.Api.Put('object/tasks/' + Grocy.EditObjectId, jsonData, Grocy.Api.Put('objects/tasks/' + Grocy.EditObjectId, jsonData,
function(result) function(result)
{ {
window.location.href = U('/tasks'); window.location.href = U('/tasks');

View File

@ -70,7 +70,7 @@ $(document).on('click', '.do-task-button', function(e)
var taskName = $(e.currentTarget).attr('data-task-name'); var taskName = $(e.currentTarget).attr('data-task-name');
var doneTime = moment().format('YYYY-MM-DD HH:mm:ss'); var doneTime = moment().format('YYYY-MM-DD HH:mm:ss');
Grocy.Api.Get('tasks/' + taskId + '/complete?done_time=' + doneTime, Grocy.Api.Post('tasks/' + taskId + '/complete', { 'done_time': doneTime },
function() function()
{ {
if (!$("#show-done-tasks").is(":checked")) if (!$("#show-done-tasks").is(":checked"))
@ -123,7 +123,7 @@ $(document).on('click', '.delete-task-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('object/tasks/' + objectId, Grocy.Api.Delete('objects/tasks/' + objectId, {},
function(result) function(result)
{ {
$('#task-' + objectId + '-row').fadeOut(500, function () $('#task-' + objectId + '-row').fadeOut(500, function ()

View File

@ -52,7 +52,7 @@ $(document).on('click', '.user-delete-button', function (e)
{ {
if (result === true) if (result === true)
{ {
Grocy.Api.Delete('users/delete/' + objectId, Grocy.Api.Delete('users/delete/' + objectId, {},
function(result) function(result)
{ {
window.location.href = U('/users'); window.location.href = U('/users');

View File

@ -80,19 +80,19 @@ $app->group('', function()
$app->group('/api', function() $app->group('/api', function()
{ {
// OpenAPI // OpenAPI
$this->get('/get-openapi-specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec'); $this->get('/openapi/specification', '\Grocy\Controllers\OpenApiController:DocumentationSpec');
// Generic entity interaction
$this->get('/object/{entity}', '\Grocy\Controllers\GenericEntityApiController:GetObjects');
$this->get('/object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:GetObject');
$this->post('/object/{entity}', '\Grocy\Controllers\GenericEntityApiController:AddObject');
$this->put('/object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:EditObject');
$this->delete('/object/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:DeleteObject');
// System // System
$this->get('/system/get-db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime'); $this->get('/system/db-changed-time', '\Grocy\Controllers\SystemApiController:GetDbChangedTime');
$this->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization'); $this->post('/system/log-missing-localization', '\Grocy\Controllers\SystemApiController:LogMissingLocalization');
// Generic entity interaction
$this->get('/objects/{entity}', '\Grocy\Controllers\GenericEntityApiController:GetObjects');
$this->get('/objects/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:GetObject');
$this->post('/objects/{entity}', '\Grocy\Controllers\GenericEntityApiController:AddObject');
$this->put('/objects/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:EditObject');
$this->delete('/objects/{entity}/{objectId}', '\Grocy\Controllers\GenericEntityApiController:DeleteObject');
// Files // Files
$this->put('/file/{group}', '\Grocy\Controllers\FilesApiController:UploadFile'); $this->put('/file/{group}', '\Grocy\Controllers\FilesApiController:UploadFile');
$this->get('/file/{group}', '\Grocy\Controllers\FilesApiController:ServeFile'); $this->get('/file/{group}', '\Grocy\Controllers\FilesApiController:ServeFile');
@ -106,36 +106,36 @@ $app->group('/api', function()
// User // User
$this->get('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:GetUserSetting'); $this->get('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:GetUserSetting');
$this->post('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:SetUserSetting'); $this->put('/user/settings/{settingKey}', '\Grocy\Controllers\UsersApiController:SetUserSetting');
// Stock // Stock
$this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatilStock');
$this->get('/stock/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
$this->get('/stock/{productId}/pricehistory', '\Grocy\Controllers\StockApiController:ProductPriceHistory');
$this->get('/stock/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');
$this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock'); $this->get('/stock', '\Grocy\Controllers\StockApiController:CurrentStock');
$this->post('/stock/{productId}/add/{amount}', '\Grocy\Controllers\StockApiController:AddProduct'); $this->get('/stock/volatile', '\Grocy\Controllers\StockApiController:CurrentVolatilStock');
$this->post('/stock/{productId}/consume/{amount}', '\Grocy\Controllers\StockApiController:ConsumeProduct'); $this->get('/stock/products/{productId}', '\Grocy\Controllers\StockApiController:ProductDetails');
$this->post('/stock/{productId}/open/{amount}', '\Grocy\Controllers\StockApiController:OpenProduct'); $this->get('/stock/products/{productId}/entries', '\Grocy\Controllers\StockApiController:ProductStockEntries');
$this->post('/stock/{productId}/inventory/{newAmount}', '\Grocy\Controllers\StockApiController:InventoryProduct'); $this->get('/stock/products/{productId}/price-history', '\Grocy\Controllers\StockApiController:ProductPriceHistory');
$this->post('/stock/shoppinglist', '\Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList'); $this->post('/stock/products/{productId}/add', '\Grocy\Controllers\StockApiController:AddProduct');
$this->post('/stock/clearshoppinglist', '\Grocy\Controllers\StockApiController:ClearShoppingList'); $this->post('/stock/products/{productId}/consume', '\Grocy\Controllers\StockApiController:ConsumeProduct');
$this->get('/barcode/{barcode}', '\Grocy\Controllers\StockApiController:ExternalBarcodeLookup'); $this->post('/stock/products/{productId}/inventory', '\Grocy\Controllers\StockApiController:InventoryProduct');
$this->post('/booking/{bookingId}/undo', '\Grocy\Controllers\StockApiController:UndoBooking'); $this->post('/stock/products/{productId}/open', '\Grocy\Controllers\StockApiController:OpenProduct');
$this->post('/stock/shoppinglist/add-missing-products', '\Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList');
$this->post('/stock/shoppinglist/clear', '\Grocy\Controllers\StockApiController:ClearShoppingList');
$this->post('/stock/bookings/{bookingId}/undo', '\Grocy\Controllers\StockApiController:UndoBooking');
$this->get('/stock/barcodes/external-lookup', '\Grocy\Controllers\StockApiController:ExternalBarcodeLookup');
// Recipes // Recipes
$this->post('/recipes/{recipeId}/shoppinglist', '\Grocy\Controllers\RecipesApiController:AddNotFulfilledProductsToShoppingList'); $this->post('/recipes/{recipeId}/add-not-fulfilled-products-to-shoppinglist', '\Grocy\Controllers\RecipesApiController:AddNotFulfilledProductsToShoppingList');
$this->post('/recipes/{recipeId}/consume', '\Grocy\Controllers\RecipesApiController:ConsumeRecipe'); $this->post('/recipes/{recipeId}/consume', '\Grocy\Controllers\RecipesApiController:ConsumeRecipe');
// Chores // Chores
$this->get('/chores/{choreId}', '\Grocy\Controllers\ChoresApiController:ChoreDetails');
$this->get('/chores', '\Grocy\Controllers\ChoresApiController:Current'); $this->get('/chores', '\Grocy\Controllers\ChoresApiController:Current');
$this->post('/chores/{executionId}/undo', '\Grocy\Controllers\ChoresApiController:UndoChoreExecution'); $this->get('/chores/{choreId}', '\Grocy\Controllers\ChoresApiController:ChoreDetails');
$this->post('/chores/{choreId}/execute', '\Grocy\Controllers\ChoresApiController:TrackChoreExecution'); $this->post('/chores/{choreId}/execute', '\Grocy\Controllers\ChoresApiController:TrackChoreExecution');
$this->post('/chores/{executionId}/undo', '\Grocy\Controllers\ChoresApiController:UndoChoreExecution');
// Batteries // Batteries
$this->get('/batteries/{batteryId}', '\Grocy\Controllers\BatteriesApiController:BatteryDetails');
$this->get('/batteries', '\Grocy\Controllers\BatteriesApiController:Current'); $this->get('/batteries', '\Grocy\Controllers\BatteriesApiController:Current');
$this->get('/batteries/{batteryId}', '\Grocy\Controllers\BatteriesApiController:BatteryDetails');
$this->post('/batteries/{batteryId}/charge', '\Grocy\Controllers\BatteriesApiController:TrackChargeCycle'); $this->post('/batteries/{batteryId}/charge', '\Grocy\Controllers\BatteriesApiController:TrackChargeCycle');
$this->post('/batteries/{chargeCycleId}/undo', '\Grocy\Controllers\BatteriesApiController:UndoChargeCycle'); $this->post('/batteries/{chargeCycleId}/undo', '\Grocy\Controllers\BatteriesApiController:UndoChargeCycle');

View File

@ -22,7 +22,7 @@
<script> <script>
var Grocy = { }; var Grocy = { };
Grocy.OpenApi = { }; Grocy.OpenApi = { };
Grocy.OpenApi.SpecUrl = '{{ $U('/api/get-openapi-specification') }}'; Grocy.OpenApi.SpecUrl = '{{ $U('/api/openapi/specification') }}';
</script> </script>
</head> </head>