mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
New endpoint for transactions without a budget.
This commit is contained in:
@@ -201,4 +201,70 @@ class ListController extends Controller
|
|||||||
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE);
|
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'] ?? '';
|
$type = $data['auto_budget_type'] ?? '';
|
||||||
$amount = array_key_exists('auto_budget_amount', $data) ? $data['auto_budget_amount'] : null;
|
$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;
|
$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;
|
$currencyCode = array_key_exists('auto_budget_currency_code', $data) ? $data['auto_budget_currency_code'] : null;
|
||||||
if (is_numeric($type)) {
|
if (is_numeric($type)) {
|
||||||
$type = (int)$type;
|
$type = (int) $type;
|
||||||
}
|
}
|
||||||
if (0 === $type) {
|
if ('' === $type || 0 === $type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// basic float check:
|
// basic float check:
|
||||||
if (!is_numeric($amount)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' === $amount) {
|
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')) {
|
if (1 !== bccomp((string) $amount, '0')) {
|
||||||
$validator->errors()->add('auto_budget_amount', (string)trans('validation.auto_budget_amount_positive'));
|
$validator->errors()->add('auto_budget_amount', (string) trans('validation.auto_budget_amount_positive'));
|
||||||
}
|
}
|
||||||
if ('' === $period) {
|
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) {
|
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'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user