mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New endpoint for transactions without a budget.
This commit is contained in:
parent
ee6c8786b2
commit
b7ba04dacf
app
Api/V1/Controllers/Models/Budget
Validation/AutoBudget
@ -201,4 +201,70 @@ class ListController extends Controller
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* This endpoint is documented at:
|
||||
* https://api-docs.firefly-iii.org/#/budgets/listTransactionWithoutBudget
|
||||
*
|
||||
* Show all transactions.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function withoutBudget(Request $request): JsonResponse
|
||||
{
|
||||
$pageSize = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data;
|
||||
|
||||
// user can overrule page size with limit parameter.
|
||||
$limit = $this->parameters->get('limit');
|
||||
if (null !== $limit && $limit > 0) {
|
||||
$pageSize = $limit;
|
||||
}
|
||||
|
||||
$type = $request->get('type') ?? 'default';
|
||||
$this->parameters->set('type', $type);
|
||||
|
||||
$types = $this->mapTransactionTypes($this->parameters->get('type'));
|
||||
$manager = $this->getManager();
|
||||
|
||||
/** @var User $admin */
|
||||
$admin = auth()->user();
|
||||
|
||||
// use new group collector:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector
|
||||
->setUser($admin)
|
||||
// filter on budget.
|
||||
->withoutBudget()
|
||||
// all info needed for the API:
|
||||
->withAPIInformation()
|
||||
// set page size:
|
||||
->setLimit($pageSize)
|
||||
// set page to retrieve
|
||||
->setPage($this->parameters->get('page'))
|
||||
// set types of transactions to return.
|
||||
->setTypes($types);
|
||||
|
||||
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
|
||||
$paginator = $collector->getPaginatedGroups();
|
||||
$paginator->setPath(route('api.v1.budgets.without-budget') . $this->buildParams());
|
||||
$transactions = $paginator->getCollection();
|
||||
|
||||
/** @var TransactionGroupTransformer $transformer */
|
||||
$transformer = app(TransactionGroupTransformer::class);
|
||||
$transformer->setParameters($this->parameters);
|
||||
$resource = new FractalCollection($transactions, $transformer, 'transactions');
|
||||
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
|
||||
|
||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,32 +39,32 @@ trait ValidatesAutoBudgetRequest
|
||||
$type = $data['auto_budget_type'] ?? '';
|
||||
$amount = array_key_exists('auto_budget_amount', $data) ? $data['auto_budget_amount'] : null;
|
||||
$period = array_key_exists('auto_budget_period', $data) ? $data['auto_budget_period'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int)$data['auto_budget_currency_id'] : null;
|
||||
$currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int) $data['auto_budget_currency_id'] : null;
|
||||
$currencyCode = array_key_exists('auto_budget_currency_code', $data) ? $data['auto_budget_currency_code'] : null;
|
||||
if (is_numeric($type)) {
|
||||
$type = (int)$type;
|
||||
$type = (int) $type;
|
||||
}
|
||||
if (0 === $type) {
|
||||
if ('' === $type || 0 === $type) {
|
||||
return;
|
||||
}
|
||||
// basic float check:
|
||||
if (!is_numeric($amount)) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ('' === $amount) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget'));
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget'));
|
||||
}
|
||||
if (1 !== bccomp((string)$amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.auto_budget_amount_positive'));
|
||||
if (1 !== bccomp((string) $amount, '0')) {
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.auto_budget_amount_positive'));
|
||||
}
|
||||
if ('' === $period) {
|
||||
$validator->errors()->add('auto_budget_period', (string)trans('validation.auto_budget_period_mandatory'));
|
||||
$validator->errors()->add('auto_budget_period', (string) trans('validation.auto_budget_period_mandatory'));
|
||||
}
|
||||
if (null !== $currencyId && null !== $currencyCode && '' === $currencyCode && 0 === $currencyId) {
|
||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info'));
|
||||
$validator->errors()->add('auto_budget_amount', (string) trans('validation.require_currency_info'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user