mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve account list and view.
This commit is contained in:
96
app/Api/V1/Requests/Models/Account/ShowRequest.php
Normal file
96
app/Api/V1/Requests/Models/Account/ShowRequest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/*
|
||||
* ShowRequest.php
|
||||
* Copyright (c) 2025 james@firefly-iii.org
|
||||
*
|
||||
* This file is part of Firefly III (https://github.com/firefly-iii).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests\Models\Account;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Support\Facades\Preferences;
|
||||
use FireflyIII\Support\Http\Api\AccountFilter;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ShowRequest extends FormRequest
|
||||
{
|
||||
use ConvertsDataTypes;
|
||||
use AccountFilter;
|
||||
|
||||
public function getParameters(): array
|
||||
{
|
||||
$limit = $this->convertInteger('limit');
|
||||
if (0 === $limit) {
|
||||
// get default for user:
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
/** @var Preference $pageSize */
|
||||
$limit = (int)Preferences::getForUser($user, 'listPageSize', 50)->data;
|
||||
}
|
||||
|
||||
$page = $this->convertInteger('page');
|
||||
$page = min(max(1, $page), 2 ** 16);
|
||||
|
||||
return [
|
||||
'type' => $this->convertString('type', 'all'),
|
||||
'limit' => $limit,
|
||||
'sort' => $this->convertString('sort', 'order'),
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$keys = join(',', array_keys($this->types));
|
||||
return [
|
||||
'date' => 'date',
|
||||
'start' => 'date|present_with:end|before_or_equal:end|before:2038-01-17|after:1970-01-02',
|
||||
'end' => 'date|present_with:start|after_or_equal:start|before:2038-01-17|after:1970-01-02',
|
||||
'sort' => 'in:active,iban,name,order,-active,-iban,-name,-order', // TODO improve me.
|
||||
'type' => sprintf('in:%s', $keys),
|
||||
'limit' => 'number|min:1|max:131337',
|
||||
'page' => 'number|min:1|max:131337',
|
||||
];
|
||||
}
|
||||
|
||||
public function withValidator(Validator $validator): void
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator): void {
|
||||
if ($validator->failed()) {
|
||||
return;
|
||||
}
|
||||
$data = $validator->getData();
|
||||
if (array_key_exists('date', $data) && array_key_exists('start', $data) && array_key_exists('end', $data)) {
|
||||
// assume valid dates, before we got here.
|
||||
$start = Carbon::parse($data['start'], config('app.timezone'))->startOfDay();
|
||||
$end = Carbon::parse($data['end'], config('app.timezone'))->endOfDay();
|
||||
$date = Carbon::parse($data['date'], config('app.timezone'));
|
||||
if (!$date->between($start, $end)) {
|
||||
$validator->errors()->add('date', (string)trans('validation.between_date'));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@@ -78,7 +78,7 @@ class StoreRequest extends FormRequest
|
||||
'object_group_id' => 'numeric|belongsToUser:object_groups,id',
|
||||
'object_group_title' => ['min:1', 'max:255'],
|
||||
'target_amount' => ['required', new IsValidZeroOrMoreAmount()],
|
||||
'start_date' => 'date|nullable',
|
||||
'start_date' => 'required|date|after:1970-01-01|before:2038-01-17',
|
||||
'transaction_currency_id' => 'exists:transaction_currencies,id|required_without:transaction_currency_code',
|
||||
'transaction_currency_code' => 'exists:transaction_currencies,code|required_without:transaction_currency_id',
|
||||
'target_date' => 'date|nullable|after:start_date',
|
||||
|
Reference in New Issue
Block a user