mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Also test attachments.
This commit is contained in:
@@ -110,6 +110,9 @@ class ShowController extends Controller
|
||||
*/
|
||||
public function show(Account $account): JsonResponse
|
||||
{
|
||||
// get list of accounts. Count it and split it.
|
||||
$this->repository->sortAccounts();
|
||||
$account->refresh();
|
||||
$manager = $this->getManager();
|
||||
|
||||
/** @var AccountTransformer $transformer */
|
||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Transformers\AccountTransformer;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class UpdateController
|
||||
@@ -69,6 +70,7 @@ class UpdateController extends Controller
|
||||
*/
|
||||
public function update(UpdateRequest $request, Account $account): JsonResponse
|
||||
{
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
$data = $request->getUpdateData();
|
||||
$data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type);
|
||||
$account = $this->repository->update($account, $data);
|
||||
|
@@ -34,6 +34,7 @@ use FireflyIII\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use League\Fractal\Resource\Item;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class StoreController
|
||||
@@ -77,6 +78,7 @@ class StoreController extends Controller
|
||||
*/
|
||||
public function store(StoreRequest $request): JsonResponse
|
||||
{
|
||||
Log::debug(sprintf('Now in %s', __METHOD__));
|
||||
$data = $request->getAll();
|
||||
$attachment = $this->repository->store($data);
|
||||
$manager = $this->getManager();
|
||||
|
@@ -45,11 +45,11 @@ class StoreRequest extends FormRequest
|
||||
public function getAll(): array
|
||||
{
|
||||
return [
|
||||
'filename' => $this->string('filename'),
|
||||
'title' => $this->string('title'),
|
||||
'notes' => $this->nlString('notes'),
|
||||
'model' => $this->string('attachable_type'),
|
||||
'model_id' => $this->integer('attachable_id'),
|
||||
'filename' => $this->string('filename'),
|
||||
'title' => $this->string('title'),
|
||||
'notes' => $this->nlString('notes'),
|
||||
'attachable_type' => $this->string('attachable_type'),
|
||||
'attachable_id' => $this->integer('attachable_id'),
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Api\V1\Requests\Models\Attachment;
|
||||
|
||||
use FireflyIII\Rules\IsValidAttachmentModel;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
@@ -43,13 +44,15 @@ class UpdateRequest extends FormRequest
|
||||
*/
|
||||
public function getAll(): array
|
||||
{
|
||||
return [
|
||||
'filename' => $this->string('filename'),
|
||||
'title' => $this->string('title'),
|
||||
'notes' => $this->nlString('notes'),
|
||||
'model' => $this->string('attachable_type'),
|
||||
'model_id' => $this->integer('attachable_id'),
|
||||
$fields = [
|
||||
'filename' => ['filename', 'string'],
|
||||
'title' => ['title', 'string'],
|
||||
'notes' => ['notes', 'nlString'],
|
||||
'attachable_type' => ['attachable_type', 'string'],
|
||||
'attachable_id' => ['attachable_id', 'integer'],
|
||||
];
|
||||
|
||||
return $this->getAllData($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,10 +62,23 @@ class UpdateRequest extends FormRequest
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$models = config('firefly.valid_attachment_models');
|
||||
$models = array_map(
|
||||
|
||||
static function (string $className) {
|
||||
return str_replace('FireflyIII\\Models\\', '', $className);
|
||||
}, $models
|
||||
);
|
||||
$models = implode(',', $models);
|
||||
$model = $this->string('attachable_type');
|
||||
|
||||
|
||||
return [
|
||||
'filename' => 'between:1,255',
|
||||
'title' => 'between:1,255',
|
||||
'notes' => 'between:1,65000',
|
||||
'filename' => 'between:1,255',
|
||||
'title' => 'between:1,255',
|
||||
'notes' => 'between:1,65000',
|
||||
'attachable_type' => sprintf('in:%s', $models),
|
||||
'attachable_id' => ['numeric', new IsValidAttachmentModel($model)],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user