mirror of
https://github.com/grocy/grocy.git
synced 2026-04-05 20:36:15 +02:00
lazy loading of batteries service
This commit is contained in:
parent
b0d602d13c
commit
ac210fe092
|
|
@ -9,10 +9,18 @@ class BatteriesApiController extends BaseApiController
|
||||||
public function __construct(\Slim\Container $container)
|
public function __construct(\Slim\Container $container)
|
||||||
{
|
{
|
||||||
parent::__construct($container);
|
parent::__construct($container);
|
||||||
$this->BatteriesService = new BatteriesService();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected $BatteriesService;
|
protected $BatteriesService = null;
|
||||||
|
|
||||||
|
protected function getBatteriesService()
|
||||||
|
{
|
||||||
|
if($this->BatteriesService == null)
|
||||||
|
{
|
||||||
|
$this->BatteriesService = new BatteriesService();
|
||||||
|
}
|
||||||
|
return $this->BatteriesService;
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +34,7 @@ class BatteriesApiController extends BaseApiController
|
||||||
$trackedTime = $requestBody['tracked_time'];
|
$trackedTime = $requestBody['tracked_time'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$chargeCycleId = $this->BatteriesService->TrackChargeCycle($args['batteryId'], $trackedTime);
|
$chargeCycleId = $this->getBatteriesService()->TrackChargeCycle($args['batteryId'], $trackedTime);
|
||||||
return $this->ApiResponse($this->getDatabase()->battery_charge_cycles($chargeCycleId));
|
return $this->ApiResponse($this->getDatabase()->battery_charge_cycles($chargeCycleId));
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
|
|
@ -39,7 +47,7 @@ class BatteriesApiController extends BaseApiController
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return $this->ApiResponse($this->BatteriesService->GetBatteryDetails($args['batteryId']));
|
return $this->ApiResponse($this->getBatteriesService()->GetBatteryDetails($args['batteryId']));
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
{
|
{
|
||||||
|
|
@ -49,14 +57,14 @@ class BatteriesApiController extends BaseApiController
|
||||||
|
|
||||||
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
{
|
{
|
||||||
return $this->ApiResponse($this->BatteriesService->GetCurrent());
|
return $this->ApiResponse($this->getBatteriesService()->GetCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function UndoChargeCycle(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
public function UndoChargeCycle(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->ApiResponse($this->BatteriesService->UndoChargeCycle($args['chargeCycleId']));
|
$this->ApiResponse($this->getBatteriesService()->UndoChargeCycle($args['chargeCycleId']));
|
||||||
return $this->EmptyApiResponse($response);
|
return $this->EmptyApiResponse($response);
|
||||||
}
|
}
|
||||||
catch (\Exception $ex)
|
catch (\Exception $ex)
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,18 @@ class BatteriesController extends BaseController
|
||||||
public function __construct(\Slim\Container $container)
|
public function __construct(\Slim\Container $container)
|
||||||
{
|
{
|
||||||
parent::__construct($container);
|
parent::__construct($container);
|
||||||
$this->BatteriesService = new BatteriesService();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected $BatteriesService;
|
protected $BatteriesService = null;
|
||||||
protected $UserfieldsService;
|
|
||||||
|
protected function getBatteriesService()
|
||||||
|
{
|
||||||
|
if($this->BatteriesService == null)
|
||||||
|
{
|
||||||
|
$this->BatteriesService = new BatteriesService();
|
||||||
|
}
|
||||||
|
return $this->BatteriesService;
|
||||||
|
}
|
||||||
|
|
||||||
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
public function Overview(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +29,7 @@ class BatteriesController extends BaseController
|
||||||
|
|
||||||
return $this->renderPage($response, 'batteriesoverview', [
|
return $this->renderPage($response, 'batteriesoverview', [
|
||||||
'batteries' => $this->getDatabase()->batteries()->orderBy('name'),
|
'batteries' => $this->getDatabase()->batteries()->orderBy('name'),
|
||||||
'current' => $this->BatteriesService->GetCurrent(),
|
'current' => $this->getBatteriesService()->GetCurrent(),
|
||||||
'nextXDays' => $nextXDays,
|
'nextXDays' => $nextXDays,
|
||||||
'userfields' => $this->getUserfieldsService()->GetFields('batteries'),
|
'userfields' => $this->getUserfieldsService()->GetFields('batteries'),
|
||||||
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('batteries')
|
'userfieldValues' => $this->getUserfieldsService()->GetAllValues('batteries')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user