mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
Clean up controllers
This commit is contained in:
parent
1ec2b26d4b
commit
1cdef09832
|
|
@ -10,12 +10,29 @@ class CalendarApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->CalendarService = new CalendarService();
|
||||
$this->ApiKeyService = new ApiKeyService();
|
||||
}
|
||||
|
||||
protected $CalendarService;
|
||||
protected $ApiKeyService;
|
||||
protected $CalendarService = null;
|
||||
|
||||
protected function getCalendarService()
|
||||
{
|
||||
if($this->CalendarService == null)
|
||||
{
|
||||
$this->CalendarService = new CalendarService();
|
||||
}
|
||||
return $this->CalendarService;
|
||||
}
|
||||
|
||||
protected $ApiKeyService = null;
|
||||
|
||||
protected function getApiKeyService()
|
||||
{
|
||||
if($this->ApiKeyService == null)
|
||||
{
|
||||
$this->ApiKeyService = new ApiKeyService();
|
||||
}
|
||||
return $this->ApiKeyService;
|
||||
}
|
||||
|
||||
public function Ical(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -23,7 +40,7 @@ class CalendarApiController extends BaseApiController
|
|||
{
|
||||
$vCalendar = new \Eluceo\iCal\Component\Calendar('grocy');
|
||||
|
||||
$events = $this->CalendarService->GetEvents();
|
||||
$events = $this->getCalendarService()->GetEvents();
|
||||
foreach($events as $event)
|
||||
{
|
||||
$date = new \DateTime($event['start']);
|
||||
|
|
@ -60,7 +77,7 @@ class CalendarApiController extends BaseApiController
|
|||
try
|
||||
{
|
||||
return $this->ApiResponse(array(
|
||||
'url' => $this->AppContainer->UrlManager->ConstructUrl('/api/calendar/ical?secret=' . $this->ApiKeyService->GetOrCreateApiKey(ApiKeyService::API_KEY_TYPE_SPECIAL_PURPOSE_CALENDAR_ICAL))
|
||||
'url' => $this->AppContainer->UrlManager->ConstructUrl('/api/calendar/ical?secret=' . $this->getApiKeyService()->GetOrCreateApiKey(ApiKeyService::API_KEY_TYPE_SPECIAL_PURPOSE_CALENDAR_ICAL))
|
||||
));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
|
|||
|
|
@ -9,15 +9,23 @@ class CalendarController extends BaseController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->CalendarService = new CalendarService();
|
||||
}
|
||||
|
||||
protected $CalendarService;
|
||||
protected $CalendarService = null;
|
||||
|
||||
protected function getCalendarService()
|
||||
{
|
||||
if($this->CalendarService == null)
|
||||
{
|
||||
$this->CalendarService = new CalendarService();
|
||||
}
|
||||
return $this->CalendarService;
|
||||
}
|
||||
|
||||
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
return $this->renderPage($response, 'calendar', [
|
||||
'fullcalendarEventSources' => $this->CalendarService->GetEvents()
|
||||
'fullcalendarEventSources' => $this->getCalendarService()->GetEvents()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,18 @@ class ChoresApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->ChoresService = new ChoresService();
|
||||
}
|
||||
|
||||
protected $ChoresService;
|
||||
protected $ChoresService = null;
|
||||
|
||||
protected function getChoresService()
|
||||
{
|
||||
if($this->ChoresService == null)
|
||||
{
|
||||
$this->ChoresService = new ChoresService();
|
||||
}
|
||||
return $this->ChoresService;
|
||||
}
|
||||
|
||||
public function TrackChoreExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -32,7 +40,7 @@ class ChoresApiController extends BaseApiController
|
|||
$doneBy = $requestBody['done_by'];
|
||||
}
|
||||
|
||||
$choreExecutionId = $this->ChoresService->TrackChore($args['choreId'], $trackedTime, $doneBy);
|
||||
$choreExecutionId = $this->getChoresService()->TrackChore($args['choreId'], $trackedTime, $doneBy);
|
||||
return $this->ApiResponse($this->getDatabase()->chores_log($choreExecutionId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -45,7 +53,7 @@ class ChoresApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
return $this->ApiResponse($this->ChoresService->GetChoreDetails($args['choreId']));
|
||||
return $this->ApiResponse($this->getChoresService()->GetChoreDetails($args['choreId']));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
|
|
@ -55,14 +63,14 @@ class ChoresApiController extends BaseApiController
|
|||
|
||||
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($this->ChoresService->GetCurrent());
|
||||
return $this->ApiResponse($this->getChoresService()->GetCurrent());
|
||||
}
|
||||
|
||||
public function UndoChoreExecution(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->ApiResponse($this->ChoresService->UndoChoreExecution($args['executionId']));
|
||||
$this->ApiResponse($this->getChoresService()->UndoChoreExecution($args['executionId']));
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -88,12 +96,12 @@ class ChoresApiController extends BaseApiController
|
|||
$chores = $this->getDatabase()->chores();
|
||||
foreach ($chores as $chore)
|
||||
{
|
||||
$this->ChoresService->CalculateNextExecutionAssignment($chore->id);
|
||||
$this->getChoresService()->CalculateNextExecutionAssignment($chore->id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->ChoresService->CalculateNextExecutionAssignment($choreId);
|
||||
$this->getChoresService()->CalculateNextExecutionAssignment($choreId);
|
||||
}
|
||||
|
||||
return $this->EmptyApiResponse($response);
|
||||
|
|
|
|||
|
|
@ -9,10 +9,18 @@ class ChoresController extends BaseController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->ChoresService = new ChoresService();
|
||||
}
|
||||
|
||||
protected $ChoresService;
|
||||
protected $ChoresService = null;
|
||||
|
||||
protected function getChoresService()
|
||||
{
|
||||
if($this->ChoresService == null)
|
||||
{
|
||||
$this->ChoresService = new ChoresService();
|
||||
}
|
||||
return $this->ChoresService;
|
||||
}
|
||||
|
||||
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -21,7 +29,7 @@ class ChoresController extends BaseController
|
|||
|
||||
return $this->renderPage($response, 'choresoverview', [
|
||||
'chores' => $this->getDatabase()->chores()->orderBy('name'),
|
||||
'currentChores' => $this->ChoresService->GetCurrent(),
|
||||
'currentChores' => $this->getChoresService()->GetCurrent(),
|
||||
'nextXDays' => $nextXDays,
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('chores'),
|
||||
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('chores'),
|
||||
|
|
|
|||
|
|
@ -9,10 +9,18 @@ class FilesApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->FilesService = new FilesService();
|
||||
}
|
||||
|
||||
protected $FilesService;
|
||||
protected $FilesService = null;
|
||||
|
||||
protected function getFilesService()
|
||||
{
|
||||
if($this->FilesService == null)
|
||||
{
|
||||
$this->FilesService = new FilesService();
|
||||
}
|
||||
return $this->FilesService;
|
||||
}
|
||||
|
||||
public function UploadFile(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -28,7 +36,7 @@ class FilesApiController extends BaseApiController
|
|||
}
|
||||
|
||||
$data = $request->getBody()->getContents();
|
||||
file_put_contents($this->FilesService->GetFilePath($args['group'], $fileName), $data);
|
||||
file_put_contents($this->getFilesService()->GetFilePath($args['group'], $fileName), $data);
|
||||
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
|
|
@ -71,11 +79,11 @@ class FilesApiController extends BaseApiController
|
|||
$bestFitWidth = $request->getQueryParams()['best_fit_width'];
|
||||
}
|
||||
|
||||
$filePath = $this->FilesService->DownscaleImage($args['group'], $fileName, $bestFitHeight, $bestFitWidth);
|
||||
$filePath = $this->getFilesService()->DownscaleImage($args['group'], $fileName, $bestFitHeight, $bestFitWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
$filePath = $this->FilesService->GetFilePath($args['group'], $fileName);
|
||||
$filePath = $this->getFilesService()->GetFilePath($args['group'], $fileName);
|
||||
}
|
||||
|
||||
if (file_exists($filePath))
|
||||
|
|
@ -109,7 +117,7 @@ class FilesApiController extends BaseApiController
|
|||
throw new \Exception('Invalid filename');
|
||||
}
|
||||
|
||||
$filePath = $this->FilesService->GetFilePath($args['group'], $fileName);
|
||||
$filePath = $this->getFilesService->GetFilePath($args['group'], $fileName);
|
||||
if (file_exists($filePath))
|
||||
{
|
||||
unlink($filePath);
|
||||
|
|
|
|||
|
|
@ -10,15 +10,8 @@ class LoginController extends BaseController
|
|||
{
|
||||
public function __construct(\Slim\Container $container, string $sessionCookieName)
|
||||
{
|
||||
#$fp = fopen('/config/data/sql.log', 'a');
|
||||
#$time_start = microtime(true);
|
||||
parent::__construct($container);
|
||||
#fwrite($fp, "£££ Login controller - parent construstor time : " . round((microtime(true) - $time_start),6) . "\n");
|
||||
#$this->SessionService = SessionService::getInstance();
|
||||
#fwrite($fp, "£££ Login controller - got session service instance : " . round((microtime(true) - $time_start),6) . "\n");
|
||||
$this->SessionCookieName = $sessionCookieName;
|
||||
#fwrite($fp, "£££ Login controller - construction time : " . round((microtime(true) - $time_start),6) . "\n");
|
||||
#fclose($fp);
|
||||
}
|
||||
|
||||
protected $SessionService = null;
|
||||
|
|
@ -35,9 +28,6 @@ class LoginController extends BaseController
|
|||
|
||||
public function ProcessLogin(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
#$fp = fopen('/config/data/sql.log', 'a');
|
||||
#fwrite($fp, "£££ Login controller - ProcessLogin called\n");
|
||||
#fclose($fp);
|
||||
$postParams = $request->getParsedBody();
|
||||
if (isset($postParams['username']) && isset($postParams['password']))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,10 +10,18 @@ class OpenApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->ApiKeyService = new ApiKeyService();
|
||||
}
|
||||
|
||||
protected $ApiKeyService;
|
||||
protected $ApiKeyService = null;
|
||||
|
||||
protected function getApiKeyService()
|
||||
{
|
||||
if($this->ApiKeyService == null)
|
||||
{
|
||||
$this->ApiKeyService = new ApiKeyService();
|
||||
}
|
||||
return $this->ApiKeyService;
|
||||
}
|
||||
|
||||
public function DocumentationUi(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -42,8 +50,8 @@ class OpenApiController extends BaseApiController
|
|||
|
||||
public function CreateNewApiKey(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
$newApiKey = $this->ApiKeyService->CreateApiKey();
|
||||
$newApiKeyId = $this->ApiKeyService->GetApiKeyId($newApiKey);
|
||||
$newApiKey = $this->getApiKeyService()->CreateApiKey();
|
||||
$newApiKeyId = $this->getApiKeyService()->GetApiKeyId($newApiKey);
|
||||
return $response->withRedirect($this->AppContainer->UrlManager->ConstructUrl("/manageapikeys?CreatedApiKeyId=$newApiKeyId"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,18 @@ class RecipesApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->RecipesService = new RecipesService();
|
||||
}
|
||||
|
||||
protected $RecipesService;
|
||||
protected $RecipesService = null;
|
||||
|
||||
protected function getRecipesService()
|
||||
{
|
||||
if($this->RecipesService == null)
|
||||
{
|
||||
$this->RecipesService = new RecipesService();
|
||||
}
|
||||
return $this->RecipesService;
|
||||
}
|
||||
|
||||
public function AddNotFulfilledProductsToShoppingList(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -24,7 +32,7 @@ class RecipesApiController extends BaseApiController
|
|||
$excludedProductIds = $requestBody['excludedProductIds'];
|
||||
}
|
||||
|
||||
$this->RecipesService->AddNotFulfilledProductsToShoppingList($args['recipeId'], $excludedProductIds);
|
||||
$this->getRecipesService()->AddNotFulfilledProductsToShoppingList($args['recipeId'], $excludedProductIds);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +40,7 @@ class RecipesApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$this->RecipesService->ConsumeRecipe($args['recipeId']);
|
||||
$this->getRecipesService()->ConsumeRecipe($args['recipeId']);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -47,10 +55,10 @@ class RecipesApiController extends BaseApiController
|
|||
{
|
||||
if(!isset($args['recipeId']))
|
||||
{
|
||||
return $this->ApiResponse($this->RecipesService->GetRecipesResolved());
|
||||
return $this->ApiResponse($this->getRecipesService()->GetRecipesResolved());
|
||||
}
|
||||
|
||||
$recipeResolved = FindObjectInArrayByPropertyValue($this->RecipesService->GetRecipesResolved(), 'recipe_id', $args['recipeId']);
|
||||
$recipeResolved = FindObjectInArrayByPropertyValue($this->getRecipesService()->GetRecipesResolved(), 'recipe_id', $args['recipeId']);
|
||||
if(!$recipeResolved)
|
||||
{
|
||||
throw new \Exception('Recipe does not exist');
|
||||
|
|
|
|||
|
|
@ -10,12 +10,18 @@ class RecipesController extends BaseController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->RecipesService = new RecipesService();
|
||||
$this->UserfieldsService = new UserfieldsService();
|
||||
}
|
||||
|
||||
protected $RecipesService;
|
||||
protected $UserfieldsService;
|
||||
protected $RecipesService = null;
|
||||
|
||||
protected function getRecipesService()
|
||||
{
|
||||
if($this->RecipesService == null)
|
||||
{
|
||||
$this->RecipesService = new RecipesService();
|
||||
}
|
||||
return $this->RecipesService;
|
||||
}
|
||||
|
||||
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -27,7 +33,7 @@ class RecipesController extends BaseController
|
|||
{
|
||||
$recipes = $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->orderBy('name');
|
||||
}
|
||||
$recipesResolved = $this->RecipesService->GetRecipesResolved();
|
||||
$recipesResolved = $this->getRecipesService()->GetRecipesResolved();
|
||||
|
||||
$selectedRecipe = null;
|
||||
$selectedRecipePositionsResolved = null;
|
||||
|
|
@ -69,8 +75,8 @@ class RecipesController extends BaseController
|
|||
'includedRecipeIdsAbsolute' => $includedRecipeIdsAbsolute,
|
||||
'selectedRecipeTotalCosts' => FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $selectedRecipe->id)->costs,
|
||||
'selectedRecipeTotalCalories' => FindObjectInArrayByPropertyValue($recipesResolved, 'recipe_id', $selectedRecipe->id)->calories,
|
||||
'userfields' => $this->UserfieldsService->GetFields('recipes'),
|
||||
'userfieldValues' => $this->UserfieldsService->GetAllValues('recipes'),
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('recipes'),
|
||||
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('recipes'),
|
||||
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
|
||||
]);
|
||||
}
|
||||
|
|
@ -94,11 +100,11 @@ class RecipesController extends BaseController
|
|||
'mode' => 'edit',
|
||||
'products' => $this->getDatabase()->products(),
|
||||
'quantityunits' => $this->getDatabase()->quantity_units(),
|
||||
'recipePositionsResolved' => $this->RecipesService->GetRecipesPosResolved(),
|
||||
'recipesResolved' => $this->RecipesService->GetRecipesResolved(),
|
||||
'recipePositionsResolved' => $this->getRecipesService()->GetRecipesPosResolved(),
|
||||
'recipesResolved' => $this->getRecipesService()->GetRecipesResolved(),
|
||||
'recipes' => $this->getDatabase()->recipes()->where('type', RecipesService::RECIPE_TYPE_NORMAL)->orderBy('name'),
|
||||
'recipeNestings' => $this->getDatabase()->recipes_nestings()->where('recipe_id', $recipeId),
|
||||
'userfields' => $this->UserfieldsService->GetFields('recipes'),
|
||||
'userfields' => $this->getUserfieldsService()->GetFields('recipes'),
|
||||
'quantityUnitConversionsResolved' => $this->getDatabase()->quantity_unit_conversions_resolved()
|
||||
]);
|
||||
}
|
||||
|
|
@ -157,7 +163,7 @@ class RecipesController extends BaseController
|
|||
'fullcalendarEventSources' => $events,
|
||||
'recipes' => $recipes,
|
||||
'internalRecipes' => $this->getDatabase()->recipes()->whereNot('type', RecipesService::RECIPE_TYPE_NORMAL)->fetchAll(),
|
||||
'recipesResolved' => $this->RecipesService->GetRecipesResolved()
|
||||
'recipesResolved' => $this->getRecipesService()->GetRecipesResolved()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,16 +9,24 @@ class StockApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->StockService = new StockService();
|
||||
}
|
||||
|
||||
protected $StockService;
|
||||
protected $StockService = null;
|
||||
|
||||
protected function getStockService()
|
||||
{
|
||||
if($this->StockService == null)
|
||||
{
|
||||
$this->StockService = new StockService();
|
||||
}
|
||||
return $this->StockService;
|
||||
}
|
||||
|
||||
public function ProductDetails(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetProductDetails($args['productId']));
|
||||
return $this->ApiResponse($this->getStockService()->GetProductDetails($args['productId']));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
|
|
@ -30,8 +38,8 @@ class StockApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$productId = $this->StockService->GetProductIdFromBarcode($args['barcode']);
|
||||
return $this->ApiResponse($this->StockService->GetProductDetails($productId));
|
||||
$productId = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
||||
return $this->ApiResponse($this->getStockService()->GetProductDetails($productId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
|
|
@ -43,7 +51,7 @@ class StockApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetProductPriceHistory($args['productId']));
|
||||
return $this->ApiResponse($this->getStockService()->GetProductPriceHistory($args['productId']));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
|
|
@ -91,7 +99,7 @@ class StockApiController extends BaseApiController
|
|||
$transactionType = $requestBody['transactiontype'];
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price, $locationId);
|
||||
$bookingId = $this->getStockService()->AddProduct($args['productId'], $requestBody['amount'], $bestBeforeDate, $transactionType, date('Y-m-d'), $price, $locationId);
|
||||
return $this->ApiResponse($this->getDatabase()->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -104,7 +112,7 @@ class StockApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$args['productId'] = $this->StockService->GetProductIdFromBarcode($args['barcode']);
|
||||
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
||||
return $this->AddProduct($request, $response, $args);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -159,7 +167,7 @@ class StockApiController extends BaseApiController
|
|||
$recipeId = $requestBody['recipe_id'];
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->ConsumeProduct($args['productId'], $requestBody['amount'], $spoiled, $transactionType, $specificStockEntryId, $recipeId);
|
||||
$bookingId = $this->getStockService()->ConsumeProduct($args['productId'], $requestBody['amount'], $spoiled, $transactionType, $specificStockEntryId, $recipeId);
|
||||
$result = $this->ApiResponse($this->getDatabase()->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -175,7 +183,7 @@ class StockApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$args['productId'] = $this->StockService->GetProductIdFromBarcode($args['barcode']);
|
||||
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
||||
return $this->ConsumeProduct($request, $response, $args);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -218,7 +226,7 @@ class StockApiController extends BaseApiController
|
|||
$price = $requestBody['price'];
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId, $price);
|
||||
$bookingId = $this->getStockService()->InventoryProduct($args['productId'], $requestBody['new_amount'], $bestBeforeDate, $locationId, $price);
|
||||
return $this->ApiResponse($this->getDatabase()->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -231,7 +239,7 @@ class StockApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$args['productId'] = $this->StockService->GetProductIdFromBarcode($args['barcode']);
|
||||
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
||||
return $this->InventoryProduct($request, $response, $args);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -262,7 +270,7 @@ class StockApiController extends BaseApiController
|
|||
$specificStockEntryId = $requestBody['stock_entry_id'];
|
||||
}
|
||||
|
||||
$bookingId = $this->StockService->OpenProduct($args['productId'], $requestBody['amount'], $specificStockEntryId);
|
||||
$bookingId = $this->getStockService()->OpenProduct($args['productId'], $requestBody['amount'], $specificStockEntryId);
|
||||
return $this->ApiResponse($this->getDatabase()->stock_log($bookingId));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -275,7 +283,7 @@ class StockApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$args['productId'] = $this->StockService->GetProductIdFromBarcode($args['barcode']);
|
||||
$args['productId'] = $this->getStockService()->GetProductIdFromBarcode($args['barcode']);
|
||||
return $this->OpenProduct($request, $response, $args);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -286,7 +294,7 @@ class StockApiController extends BaseApiController
|
|||
|
||||
public function CurrentStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetCurrentStock());
|
||||
return $this->ApiResponse($this->getStockService()->GetCurrentStock());
|
||||
}
|
||||
|
||||
public function CurrentVolatilStock(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
|
|
@ -297,9 +305,9 @@ class StockApiController extends BaseApiController
|
|||
$nextXDays = $request->getQueryParams()['expiring_days'];
|
||||
}
|
||||
|
||||
$expiringProducts = $this->StockService->GetExpiringProducts($nextXDays, true);
|
||||
$expiredProducts = $this->StockService->GetExpiringProducts(-1);
|
||||
$missingProducts = $this->StockService->GetMissingProducts();
|
||||
$expiringProducts = $this->getStockService()->GetExpiringProducts($nextXDays, true);
|
||||
$expiredProducts = $this->getStockService()->GetExpiringProducts(-1);
|
||||
$missingProducts = $this->getStockService()->GetMissingProducts();
|
||||
return $this->ApiResponse(array(
|
||||
'expiring_products' => $expiringProducts,
|
||||
'expired_products' => $expiredProducts,
|
||||
|
|
@ -319,7 +327,7 @@ class StockApiController extends BaseApiController
|
|||
$listId = intval($requestBody['list_id']);
|
||||
}
|
||||
|
||||
$this->StockService->AddMissingProductsToShoppingList($listId);
|
||||
$this->getStockService()->AddMissingProductsToShoppingList($listId);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -340,7 +348,7 @@ class StockApiController extends BaseApiController
|
|||
$listId = intval($requestBody['list_id']);
|
||||
}
|
||||
|
||||
$this->StockService->ClearShoppingList($listId);
|
||||
$this->getStockService()->ClearShoppingList($listId);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -382,7 +390,7 @@ class StockApiController extends BaseApiController
|
|||
throw new \Exception("No product id was supplied");
|
||||
}
|
||||
|
||||
$this->StockService->AddProductToShoppingList($productId, $amount, $note, $listId);
|
||||
$this->getStockService()->AddProductToShoppingList($productId, $amount, $note, $listId);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -418,7 +426,7 @@ class StockApiController extends BaseApiController
|
|||
throw new \Exception("No product id was supplied");
|
||||
}
|
||||
|
||||
$this->StockService->RemoveProductFromShoppingList($productId, $amount, $listId);
|
||||
$this->getStockService()->RemoveProductFromShoppingList($productId, $amount, $listId);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -437,7 +445,7 @@ class StockApiController extends BaseApiController
|
|||
$addFoundProduct = true;
|
||||
}
|
||||
|
||||
return $this->ApiResponse($this->StockService->ExternalBarcodeLookup($args['barcode'], $addFoundProduct));
|
||||
return $this->ApiResponse($this->getStockService()->ExternalBarcodeLookup($args['barcode'], $addFoundProduct));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
|
|
@ -460,7 +468,7 @@ class StockApiController extends BaseApiController
|
|||
|
||||
public function ProductStockEntries(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($this->StockService->GetProductStockEntries($args['productId']));
|
||||
return $this->ApiResponse($this->getStockService()->GetProductStockEntries($args['productId']));
|
||||
}
|
||||
|
||||
public function StockBooking(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
|
|
|
|||
|
|
@ -10,11 +10,7 @@ class StockController extends BaseController
|
|||
|
||||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
#$fp = fopen('/www/data/sql.log', 'a');
|
||||
#fwrite($fp, "!!!constructing StockController\n");
|
||||
#fclose($fp);
|
||||
parent::__construct($container);
|
||||
#$this->StockService = new StockService();
|
||||
}
|
||||
|
||||
protected $StockService = null;
|
||||
|
|
@ -57,15 +53,10 @@ class StockController extends BaseController
|
|||
|
||||
public function Consume(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
#$fp = fopen('/www/data/sql.log', 'a');
|
||||
#fwrite($fp, "???executing consume stock");
|
||||
#$time_start = microtime(true);
|
||||
$result = $this->renderPage($response, 'consume', [
|
||||
'products' => $this->getDatabase()->products()->orderBy('name'),
|
||||
'recipes' => $this->getDatabase()->recipes()->orderBy('name')
|
||||
]);
|
||||
#fwrite($fp, "???Total execution time in seconds: " . round((microtime(true) - $time_start),6) . "\n");
|
||||
#fclose($fp);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,35 +2,19 @@
|
|||
|
||||
namespace Grocy\Controllers;
|
||||
|
||||
#use \Grocy\Services\DatabaseService;
|
||||
#use \Grocy\Services\ApplicationService;
|
||||
|
||||
class SystemApiController extends BaseApiController
|
||||
{
|
||||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
#$this->ApplicationService = ApplicationService::getInstance();
|
||||
}
|
||||
|
||||
#protected $DatabaseService;
|
||||
#protected $ApplicationService;
|
||||
|
||||
public function GetDbChangedTime(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
#$fp = fopen('/config/data/sql.log', 'a');
|
||||
#fwrite($fp, "---- getting db changed time ----\n");
|
||||
#$time_start = microtime(true);
|
||||
$response = $this->ApiResponse(array(
|
||||
'changed_time' => $this->getDatabaseService()->GetDbChangedTime()
|
||||
));
|
||||
#fwrite($fp, "----Total execution time in seconds: " . round((microtime(true) - $time_start),4) . "\n");
|
||||
#fwrite($fp, "---- time obtained ----\n");
|
||||
#fclose($fp);
|
||||
return $response;
|
||||
#return $this->ApiResponse(array(
|
||||
# 'changed_time' => $this->getDatabaseService()->GetDbChangedTime()
|
||||
#));
|
||||
}
|
||||
|
||||
public function LogMissingLocalization(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,15 @@
|
|||
|
||||
namespace Grocy\Controllers;
|
||||
|
||||
#use \Grocy\Services\ApplicationService;
|
||||
use \Grocy\Services\DatabaseMigrationService;
|
||||
use \Grocy\Services\DemoDataGeneratorService;
|
||||
|
||||
class SystemController extends BaseController
|
||||
{
|
||||
#protected $ApplicationService;
|
||||
|
||||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
#$this->ApplicationService = ApplicationService::getInstance();
|
||||
}
|
||||
|
||||
public function Root(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
|
|
|
|||
|
|
@ -9,14 +9,22 @@ class TasksApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->TasksService = new TasksService();
|
||||
}
|
||||
|
||||
protected $TasksService;
|
||||
protected $TasksService = null;
|
||||
|
||||
protected function getTasksService()
|
||||
{
|
||||
if($this->TasksService == null)
|
||||
{
|
||||
$this->TasksService = new TasksService();
|
||||
}
|
||||
return $this->TasksService;
|
||||
}
|
||||
|
||||
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
return $this->ApiResponse($this->TasksService->GetCurrent());
|
||||
return $this->ApiResponse($this->getTasksService()->GetCurrent());
|
||||
}
|
||||
|
||||
public function MarkTaskAsCompleted(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
|
|
@ -31,7 +39,7 @@ class TasksApiController extends BaseApiController
|
|||
$doneTime = $requestBody['done_time'];
|
||||
}
|
||||
|
||||
$this->TasksService->MarkTaskAsCompleted($args['taskId'], $doneTime);
|
||||
$this->getTasksService()->MarkTaskAsCompleted($args['taskId'], $doneTime);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -44,7 +52,7 @@ class TasksApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$this->TasksService->UndoTask($args['taskId']);
|
||||
$this->getTasksService()->UndoTask($args['taskId']);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
|
|||
|
|
@ -9,10 +9,18 @@ class TasksController extends BaseController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->TasksService = new TasksService();
|
||||
}
|
||||
|
||||
protected $TasksService;
|
||||
protected $TasksService = null;
|
||||
|
||||
protected function getTasksService()
|
||||
{
|
||||
if($this->TasksService == null)
|
||||
{
|
||||
$this->TasksService = new TasksService();
|
||||
}
|
||||
return $this->TasksService;
|
||||
}
|
||||
|
||||
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
|
|
@ -22,7 +30,7 @@ class TasksController extends BaseController
|
|||
}
|
||||
else
|
||||
{
|
||||
$tasks = $this->TasksService->GetCurrent();
|
||||
$tasks = $this->getTasksService()->GetCurrent();
|
||||
}
|
||||
|
||||
$usersService = $this->getUsersService();
|
||||
|
|
|
|||
|
|
@ -9,16 +9,24 @@ class UsersApiController extends BaseApiController
|
|||
public function __construct(\Slim\Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->UsersService = new UsersService();
|
||||
}
|
||||
|
||||
protected $UsersService;
|
||||
protected $UsersService = null;
|
||||
|
||||
protected function getUsersService()
|
||||
{
|
||||
if($this->UsersService == null)
|
||||
{
|
||||
$this->UsersService = new UsersService();
|
||||
}
|
||||
return $this->UsersService;
|
||||
}
|
||||
|
||||
public function GetUsers(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->ApiResponse($this->UsersService->GetUsersAsDto());
|
||||
return $this->ApiResponse($this->getUsersService()->GetUsersAsDto());
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
{
|
||||
|
|
@ -37,7 +45,7 @@ class UsersApiController extends BaseApiController
|
|||
throw new \Exception('Request body could not be parsed (probably invalid JSON format or missing/wrong Content-Type header)');
|
||||
}
|
||||
|
||||
$this->UsersService->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
|
||||
$this->getUsersService()->CreateUser($requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -50,7 +58,7 @@ class UsersApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$this->UsersService->DeleteUser($args['userId']);
|
||||
$this->getUsersService()->DeleteUser($args['userId']);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -65,7 +73,7 @@ class UsersApiController extends BaseApiController
|
|||
|
||||
try
|
||||
{
|
||||
$this->UsersService->EditUser($args['userId'], $requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
|
||||
$this->getUsersService()->EditUser($args['userId'], $requestBody['username'], $requestBody['first_name'], $requestBody['last_name'], $requestBody['password']);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -78,7 +86,7 @@ class UsersApiController extends BaseApiController
|
|||
{
|
||||
try
|
||||
{
|
||||
$value = $this->UsersService->GetUserSetting(GROCY_USER_ID, $args['settingKey']);
|
||||
$value = $this->getUsersService()->GetUserSetting(GROCY_USER_ID, $args['settingKey']);
|
||||
return $this->ApiResponse(array('value' => $value));
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
@ -93,7 +101,7 @@ class UsersApiController extends BaseApiController
|
|||
{
|
||||
$requestBody = $request->getParsedBody();
|
||||
|
||||
$value = $this->UsersService->SetUserSetting(GROCY_USER_ID, $args['settingKey'], $requestBody['value']);
|
||||
$value = $this->getUsersService()->SetUserSetting(GROCY_USER_ID, $args['settingKey'], $requestBody['value']);
|
||||
return $this->EmptyApiResponse($response);
|
||||
}
|
||||
catch (\Exception $ex)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user