mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-20 11:48:27 -06:00
Code cleanup [skip ci]
This commit is contained in:
parent
b8774a7af3
commit
2630732b8a
@ -95,8 +95,8 @@ class AttachmentController extends Controller
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @throws FireflyException
|
||||
* @return LaravelResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function download(Attachment $attachment): LaravelResponse
|
||||
{
|
||||
@ -187,8 +187,8 @@ class AttachmentController extends Controller
|
||||
*
|
||||
* @param AttachmentStoreRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(AttachmentStoreRequest $request): JsonResponse
|
||||
{
|
||||
|
@ -207,8 +207,8 @@ class BillController extends Controller
|
||||
*
|
||||
* @param BillRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(BillRequest $request): JsonResponse
|
||||
{
|
||||
|
@ -23,8 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Controllers;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Api\V1\Requests\BudgetLimitRequest;
|
||||
use FireflyIII\Api\V1\Requests\BudgetStoreRequest;
|
||||
use FireflyIII\Api\V1\Requests\BudgetUpdateRequest;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@ -214,9 +212,9 @@ class BudgetController extends Controller
|
||||
*
|
||||
* @param BudgetStoreRequest $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function store(BudgetStoreRequest $request): JsonResponse
|
||||
{
|
||||
|
@ -244,9 +244,9 @@ class BudgetLimitController extends Controller
|
||||
*/
|
||||
public function update(BudgetLimitRequest $request, BudgetLimit $budgetLimit): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
$budgetLimit = $this->blRepository->update($budgetLimit, $data);
|
||||
$manager = $this->getManager();
|
||||
$data = $request->getAll();
|
||||
$budgetLimit = $this->blRepository->update($budgetLimit, $data);
|
||||
$manager = $this->getManager();
|
||||
|
||||
/** @var BudgetLimitTransformer $transformer */
|
||||
$transformer = app(BudgetLimitTransformer::class);
|
||||
|
@ -177,8 +177,8 @@ class CategoryController extends Controller
|
||||
*
|
||||
* @param CategoryRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(CategoryRequest $request): JsonResponse
|
||||
{
|
||||
|
@ -74,23 +74,6 @@ class ConfigurationController extends Controller
|
||||
return response()->json(['data' => $configData])->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the configuration.
|
||||
*
|
||||
* @param ConfigurationRequest $request
|
||||
* @param string $name
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(ConfigurationRequest $request, string $name): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
app('fireflyconfig')->set($name, $data['value']);
|
||||
$configData = $this->getConfigData();
|
||||
|
||||
return response()->json(['data' => $configData])->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all config values.
|
||||
*
|
||||
@ -114,4 +97,21 @@ class ConfigurationController extends Controller
|
||||
'single_user_mode' => null === $singleUser ? null : $singleUser->data,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the configuration.
|
||||
*
|
||||
* @param ConfigurationRequest $request
|
||||
* @param string $name
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function update(ConfigurationRequest $request, string $name): JsonResponse
|
||||
{
|
||||
$data = $request->getAll();
|
||||
app('fireflyconfig')->set($name, $data['value']);
|
||||
$configData = $this->getConfigData();
|
||||
|
||||
return response()->json(['data' => $configData])->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,8 @@ abstract class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
protected ParameterBag $parameters;
|
||||
|
||||
protected const CONTENT_TYPE = 'application/vnd.api+json';
|
||||
protected ParameterBag $parameters;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
@ -66,43 +65,6 @@ abstract class Controller extends BaseController
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to help build URI's.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final protected function buildParams(): string
|
||||
{
|
||||
$return = '?';
|
||||
$params = [];
|
||||
foreach ($this->parameters as $key => $value) {
|
||||
if ('page' === $key) {
|
||||
continue;
|
||||
}
|
||||
if ($value instanceof Carbon) {
|
||||
$params[$key] = $value->format('Y-m-d');
|
||||
continue;
|
||||
}
|
||||
$params[$key] = $value;
|
||||
}
|
||||
$return .= http_build_query($params);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Manager
|
||||
*/
|
||||
final protected function getManager(): Manager
|
||||
{
|
||||
// create some objects:
|
||||
$manager = new Manager;
|
||||
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to grab all parameters from the URI.
|
||||
*
|
||||
@ -145,4 +107,41 @@ abstract class Controller extends BaseController
|
||||
return $bag;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to help build URI's.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
final protected function buildParams(): string
|
||||
{
|
||||
$return = '?';
|
||||
$params = [];
|
||||
foreach ($this->parameters as $key => $value) {
|
||||
if ('page' === $key) {
|
||||
continue;
|
||||
}
|
||||
if ($value instanceof Carbon) {
|
||||
$params[$key] = $value->format('Y-m-d');
|
||||
continue;
|
||||
}
|
||||
$params[$key] = $value;
|
||||
}
|
||||
$return .= http_build_query($params);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Manager
|
||||
*/
|
||||
final protected function getManager(): Manager
|
||||
{
|
||||
// create some objects:
|
||||
$manager = new Manager;
|
||||
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v1';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
return $manager;
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||
@ -198,7 +197,7 @@ class CurrencyController extends Controller
|
||||
$manager = $this->getManager();
|
||||
|
||||
/** @var BillRepositoryInterface $billRepos */
|
||||
$billRepos = app(BillRepositoryInterface::class);
|
||||
$billRepos = app(BillRepositoryInterface::class);
|
||||
$pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
||||
$unfiltered = $billRepos->getBills();
|
||||
|
||||
@ -450,7 +449,7 @@ class CurrencyController extends Controller
|
||||
// get list of budgets. Count it and split it.
|
||||
/** @var RecurringRepositoryInterface $recurringRepos */
|
||||
$recurringRepos = app(RecurringRepositoryInterface::class);
|
||||
$unfiltered = $recurringRepos->getAll();
|
||||
$unfiltered = $recurringRepos->getAll();
|
||||
|
||||
// filter selection
|
||||
$collection = $unfiltered->filter(
|
||||
@ -500,7 +499,7 @@ class CurrencyController extends Controller
|
||||
|
||||
// get list of budgets. Count it and split it.
|
||||
/** @var RuleRepositoryInterface $ruleRepos */
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$ruleRepos = app(RuleRepositoryInterface::class);
|
||||
$unfiltered = $ruleRepos->getAll();
|
||||
|
||||
$collection = $unfiltered->filter(
|
||||
|
@ -69,8 +69,8 @@ class CurrencyExchangeRateController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
|
@ -80,9 +80,9 @@ class LinkTypeController extends Controller
|
||||
*
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(LinkType $linkType): JsonResponse
|
||||
{
|
||||
@ -152,8 +152,8 @@ class LinkTypeController extends Controller
|
||||
*
|
||||
* @param LinkTypeRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(LinkTypeRequest $request): JsonResponse
|
||||
{
|
||||
@ -242,8 +242,8 @@ class LinkTypeController extends Controller
|
||||
* @param LinkTypeRequest $request
|
||||
* @param LinkType $linkType
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(LinkTypeRequest $request, LinkType $linkType): JsonResponse
|
||||
{
|
||||
|
@ -204,8 +204,8 @@ class PiggyBankController extends Controller
|
||||
*
|
||||
* @param PiggyBankStoreRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(PiggyBankStoreRequest $request): JsonResponse
|
||||
{
|
||||
|
@ -151,8 +151,8 @@ class RecurrenceController extends Controller
|
||||
*
|
||||
* @param RecurrenceStoreRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(RecurrenceStoreRequest $request): JsonResponse
|
||||
{
|
||||
@ -226,9 +226,9 @@ class RecurrenceController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function trigger(): JsonResponse
|
||||
{
|
||||
@ -238,7 +238,7 @@ class RecurrenceController extends Controller
|
||||
$result = $recurring->fire();
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
throw new FireflyException('200022: Error in cron job.',0, $e);
|
||||
throw new FireflyException('200022: Error in cron job.', 0, $e);
|
||||
}
|
||||
if (false === $result) {
|
||||
return response()->json([], 204);
|
||||
|
@ -101,8 +101,8 @@ class SummaryController extends Controller
|
||||
/**
|
||||
* @param DateRequest $request
|
||||
*
|
||||
* @throws Exception
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function basic(DateRequest $request): JsonResponse
|
||||
{
|
||||
@ -130,30 +130,6 @@ class SummaryController extends Controller
|
||||
return response()->json($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if date is outside session range.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
|
||||
{
|
||||
$result = false;
|
||||
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
|
||||
$result = true;
|
||||
}
|
||||
// start and end in the past? use $end
|
||||
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
@ -322,8 +298,8 @@ class SummaryController extends Controller
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @throws Exception
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getLeftToSpendInfo(Carbon $start, Carbon $end): array
|
||||
{
|
||||
@ -429,4 +405,28 @@ class SummaryController extends Controller
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if date is outside session range.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function notInDateRange(Carbon $date, Carbon $start, Carbon $end): bool // Validate a preference
|
||||
{
|
||||
$result = false;
|
||||
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
|
||||
$result = true;
|
||||
}
|
||||
// start and end in the past? use $end
|
||||
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Log;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class TransactionController
|
||||
*/
|
||||
@ -234,6 +235,19 @@ class TransactionController extends Controller
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single transaction, by transaction journal.
|
||||
*
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function showByJournal(TransactionJournal $transactionJournal): JsonResponse
|
||||
{
|
||||
return $this->show($transactionJournal->transactionGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single transaction.
|
||||
*
|
||||
@ -269,19 +283,6 @@ class TransactionController extends Controller
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single transaction, by transaction journal.
|
||||
*
|
||||
* @param TransactionJournal $transactionJournal
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function showByJournal(TransactionJournal $transactionJournal): JsonResponse
|
||||
{
|
||||
return $this->show($transactionJournal->transactionGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new transaction.
|
||||
*
|
||||
|
@ -157,8 +157,8 @@ class TransactionLinkController extends Controller
|
||||
*
|
||||
* @param TransactionLinkRequest $request
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(TransactionLinkRequest $request): JsonResponse
|
||||
{
|
||||
@ -188,8 +188,8 @@ class TransactionLinkController extends Controller
|
||||
* @param TransactionLinkRequest $request
|
||||
* @param TransactionJournalLink $journalLink
|
||||
*
|
||||
* @throws FireflyException
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(TransactionLinkRequest $request, TransactionJournalLink $journalLink): JsonResponse
|
||||
{
|
||||
|
@ -68,9 +68,9 @@ class UserController extends Controller
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(User $user): JsonResponse
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user