mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-02 19:16:39 +00:00
Expanded API code, wrote a bunch new transformers as well.
This commit is contained in:
@@ -22,12 +22,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Carbon\Exceptions\InvalidDateException;
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
/**
|
||||
* Class Controller.
|
||||
@@ -36,6 +39,9 @@ class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
/** @var ParameterBag */
|
||||
protected $parameters;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
*
|
||||
@@ -50,5 +56,49 @@ class Controller extends BaseController
|
||||
if (true === $isDemoSite) {
|
||||
throw new FireflyException('The API is not available on the demo site.');
|
||||
}
|
||||
|
||||
// get global parameters
|
||||
$this->parameters = $this->getParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ParameterBag
|
||||
*/
|
||||
private function getParameters(): ParameterBag
|
||||
{
|
||||
$bag = new ParameterBag;
|
||||
$page = (int)request()->get('page');
|
||||
if ($page === 0) {
|
||||
$page = 1;
|
||||
}
|
||||
$bag->set('page', $page);
|
||||
|
||||
$start = request()->get('start');
|
||||
$startDate = null;
|
||||
if (!is_null($start)) {
|
||||
try {
|
||||
$startDate = new Carbon($start);
|
||||
} catch (InvalidDateException $e) {
|
||||
// don't care
|
||||
}
|
||||
}
|
||||
$bag->set('start', $startDate);
|
||||
|
||||
$end = request()->get('end');
|
||||
$endDate = null;
|
||||
if (!is_null($end)) {
|
||||
try {
|
||||
$endDate = new Carbon($end);
|
||||
} catch (InvalidDateException $e) {
|
||||
// don't care
|
||||
}
|
||||
}
|
||||
$bag->set('end', $endDate);
|
||||
|
||||
$type = request()->get('type') ?? 'all';
|
||||
$bag->set('type', $type);
|
||||
|
||||
return $bag;
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user