2018-04-11 19:49:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
use \Grocy\Services\BatteriesService;
|
2018-04-11 19:49:35 +02:00
|
|
|
|
|
|
|
class BatteriesApiController extends BaseApiController
|
|
|
|
{
|
|
|
|
public function __construct(\Slim\Container $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
$this->BatteriesService = new BatteriesService();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected $BatteriesService;
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
public function TrackChargeCycle(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
|
|
|
$trackedTime = date('Y-m-d H:i:s');
|
2018-07-11 19:43:05 +02:00
|
|
|
if (isset($request->getQueryParams()['tracked_time']) && !empty($request->getQueryParams()['tracked_time']) && IsIsoDateTime($request->getQueryParams()['tracked_time']))
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
|
|
|
$trackedTime = $request->getQueryParams()['tracked_time'];
|
|
|
|
}
|
|
|
|
|
2018-04-22 14:25:08 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$this->BatteriesService->TrackChargeCycle($args['batteryId'], $trackedTime);
|
|
|
|
return $this->VoidApiActionResponse($response);
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
|
|
|
|
}
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:13:38 +02:00
|
|
|
public function BatteryDetails(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
2018-04-11 19:49:35 +02:00
|
|
|
{
|
2018-04-22 14:25:08 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return $this->ApiResponse($this->BatteriesService->GetBatteryDetails($args['batteryId']));
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
return $this->VoidApiActionResponse($response, false, 400, $ex->getMessage());
|
|
|
|
}
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|
2018-08-04 15:44:58 +02:00
|
|
|
|
|
|
|
public function Current(\Slim\Http\Request $request, \Slim\Http\Response $response, array $args)
|
|
|
|
{
|
|
|
|
return $this->ApiResponse($this->BatteriesService->GetCurrent());
|
|
|
|
}
|
2018-04-11 19:49:35 +02:00
|
|
|
}
|