Files
grocy/bootstrap.php

115 lines
4.9 KiB
PHP
Raw Normal View History

2017-04-15 23:16:20 +02:00
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
2018-04-11 19:49:35 +02:00
2018-04-12 21:13:38 +02:00
use \Grocy\Middleware\SessionAuthMiddleware;
use \Grocy\Middleware\JsonMiddleware;
use \Grocy\Middleware\CliMiddleware;
2018-04-11 19:49:35 +02:00
2018-04-12 21:13:38 +02:00
use \Grocy\Services\ApplicationService;
2017-04-15 23:16:20 +02:00
2017-04-20 17:10:21 +02:00
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/data/config.php';
2018-04-11 19:49:35 +02:00
require_once __DIR__ . '/extensions.php';
2017-04-16 23:11:03 +02:00
2018-04-11 19:49:35 +02:00
// Setup base application
2017-07-27 19:11:07 +02:00
if (PHP_SAPI !== 'cli')
{
2018-04-12 21:13:38 +02:00
$appContainer = new \Slim\Container([
2017-07-27 19:11:07 +02:00
'settings' => [
'displayErrorDetails' => true,
'determineRouteBeforeAppMiddleware' => true
],
2018-04-12 21:13:38 +02:00
'view' => function($container)
{
return new \Slim\Views\Blade(__DIR__ . '/views', __DIR__ . '/data/viewcache');
}
]);
$app = new \Slim\App($appContainer);
2017-04-15 23:16:20 +02:00
}
2018-04-11 19:49:35 +02:00
else
2017-07-25 20:03:31 +02:00
{
2018-04-12 21:13:38 +02:00
$app = new \Slim\App();
2018-04-11 19:49:35 +02:00
$app->add(\pavlakis\cli\CliRequest::class);
}
2018-04-11 19:49:35 +02:00
// Add session handling if this is not a demo installation
$applicationService = new ApplicationService();
if (!$applicationService->IsDemoInstallation())
2017-07-25 20:03:31 +02:00
{
2018-04-12 21:13:38 +02:00
$app->add(SessionAuthMiddleware::class);
2018-04-11 19:49:35 +02:00
}
2017-07-25 20:03:31 +02:00
2018-04-11 19:49:35 +02:00
// Base route
$app->get('/', 'Grocy\Controllers\LoginController:Root');
2018-04-11 19:49:35 +02:00
// Login routes
$app->get('/login', 'Grocy\Controllers\LoginController:LoginPage')->setName('login');
$app->post('/login', 'Grocy\Controllers\LoginController:ProcessLogin')->setName('login');
$app->get('/logout', 'Grocy\Controllers\LoginController:Logout');
2017-04-15 23:16:20 +02:00
2018-04-11 19:49:35 +02:00
// Stock routes
$app->get('/stockoverview', 'Grocy\Controllers\StockController:Overview');
$app->get('/purchase', 'Grocy\Controllers\StockController:Purchase');
$app->get('/consume', 'Grocy\Controllers\StockController:Consume');
$app->get('/inventory', 'Grocy\Controllers\StockController:Inventory');
2017-04-15 23:16:20 +02:00
2018-04-11 19:49:35 +02:00
$app->get('/products', 'Grocy\Controllers\StockController:ProductsList');
$app->get('/product/{productId}', 'Grocy\Controllers\StockController:ProductEditForm');
2017-04-15 23:16:20 +02:00
2018-04-11 19:49:35 +02:00
$app->get('/locations', 'Grocy\Controllers\StockController:LocationsList');
$app->get('/location/{locationId}', 'Grocy\Controllers\StockController:LocationEditForm');
2017-07-25 20:03:31 +02:00
2018-04-11 19:49:35 +02:00
$app->get('/quantityunits', 'Grocy\Controllers\StockController:QuantityUnitsList');
$app->get('/quantityunit/{quantityunitId}', 'Grocy\Controllers\StockController:QuantityUnitEditForm');
2018-04-11 19:49:35 +02:00
$app->get('/shoppinglist', 'Grocy\Controllers\StockController:ShoppingList');
$app->get('/shoppinglistitem/{itemId}', 'Grocy\Controllers\StockController:ShoppingListItemEditForm');
2017-07-25 20:03:31 +02:00
2017-04-15 23:16:20 +02:00
2018-04-11 19:49:35 +02:00
// Habit routes
$app->get('/habitsoverview', 'Grocy\Controllers\HabitsController:Overview');
$app->get('/habittracking', 'Grocy\Controllers\HabitsController:TrackHabitExecution');
2017-04-15 23:16:20 +02:00
2018-04-11 19:49:35 +02:00
$app->get('/habits', 'Grocy\Controllers\HabitsController:HabitsList');
$app->get('/habit/{habitId}', 'Grocy\Controllers\HabitsController:HabitEditForm');
2017-04-15 23:16:20 +02:00
2018-04-11 19:49:35 +02:00
// Batterry routes
$app->get('/batteriesoverview', 'Grocy\Controllers\BatteriesController:Overview');
$app->get('/batterytracking', 'Grocy\Controllers\BatteriesController:TrackChargeCycle');
2017-07-25 20:03:31 +02:00
2018-04-11 19:49:35 +02:00
$app->get('/batteries', 'Grocy\Controllers\BatteriesController:BatteriesList');
$app->get('/battery/{batteryId}', 'Grocy\Controllers\BatteriesController:BatteryEditForm');
2018-04-11 19:49:35 +02:00
$app->group('/api', function()
2017-04-15 23:16:20 +02:00
{
2018-04-11 19:49:35 +02:00
$this->get('/get-objects/{entity}', 'Grocy\Controllers\GenericEntityApiController:GetObjects');
$this->get('/get-object/{entity}/{objectId}', 'Grocy\Controllers\GenericEntityApiController:GetObject');
$this->post('/add-object/{entity}', 'Grocy\Controllers\GenericEntityApiController:AddObject');
$this->post('/edit-object/{entity}/{objectId}', 'Grocy\Controllers\GenericEntityApiController:EditObject');
$this->get('/delete-object/{entity}/{objectId}', 'Grocy\Controllers\GenericEntityApiController:DeleteObject');
2017-07-25 20:03:31 +02:00
2018-04-11 19:49:35 +02:00
$this->get('/stock/add-product/{productId}/{amount}', 'Grocy\Controllers\StockApiController:AddProduct');
$this->get('/stock/consume-product/{productId}/{amount}', 'Grocy\Controllers\StockApiController:ConsumeProduct');
$this->get('/stock/inventory-product/{productId}/{newAmount}', 'Grocy\Controllers\StockApiController:InventoryProduct');
$this->get('/stock/get-product-details/{productId}', 'Grocy\Controllers\StockApiController:ProductDetails');
$this->get('/stock/get-current-stock', 'Grocy\Controllers\StockApiController:CurrentStock');
$this->get('/stock/add-missing-products-to-shoppinglist', 'Grocy\Controllers\StockApiController:AddMissingProductsToShoppingList');
2018-04-11 19:49:35 +02:00
$this->get('/habits/track-habit-execution/{habitId}', 'Grocy\Controllers\HabitsApiController:TrackHabitExecution');
$this->get('/habits/get-habit-details/{habitId}', 'Grocy\Controllers\HabitsApiController:HabitDetails');
$this->get('/batteries/track-charge-cycle/{batteryId}', 'Grocy\Controllers\BatteriesApiController:TrackChargeCycle');
$this->get('/batteries/get-battery-details/{batteryId}', 'Grocy\Controllers\BatteriesApiController:BatteryDetails');
})->add(JsonMiddleware::class);
2017-04-15 23:16:20 +02:00
2017-07-27 19:11:07 +02:00
$app->group('/cli', function()
{
2018-04-11 19:49:35 +02:00
$this->get('/recreatedemo', 'Grocy\Controllers\CliController:RecreateDemo');
})->add(CliMiddleware::class);
2017-07-27 19:11:07 +02:00
2017-04-15 23:16:20 +02:00
$app->run();