diff --git a/app/Api/V1/Controllers/Models/Account/StoreController.php b/app/Api/V1/Controllers/Models/Account/StoreController.php index 481782338a..f6f1c99335 100644 --- a/app/Api/V1/Controllers/Models/Account/StoreController.php +++ b/app/Api/V1/Controllers/Models/Account/StoreController.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\Account; use FireflyIII\Api\V1\Controllers\Controller; -use FireflyIII\Api\V1\Requests\AccountStoreRequest; +use FireflyIII\Api\V1\Requests\Models\Account\StoreRequest; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Transformers\AccountTransformer; use Illuminate\Http\JsonResponse; @@ -61,11 +61,11 @@ class StoreController extends Controller /** * Store a new instance. * - * @param AccountStoreRequest $request + * @param StoreRequest $request * * @return JsonResponse */ - public function store(AccountStoreRequest $request): JsonResponse + public function store(StoreRequest $request): JsonResponse { $data = $request->getAllAccountData(); $account = $this->repository->store($data); diff --git a/app/Api/V1/Controllers/Models/Account/UpdateController.php b/app/Api/V1/Controllers/Models/Account/UpdateController.php index 14665a5843..c7628391c3 100644 --- a/app/Api/V1/Controllers/Models/Account/UpdateController.php +++ b/app/Api/V1/Controllers/Models/Account/UpdateController.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V1\Controllers\Models\Account; use FireflyIII\Api\V1\Controllers\Controller; -use FireflyIII\Api\V1\Requests\AccountUpdateRequest; +use FireflyIII\Api\V1\Requests\Models\Account\UpdateRequest; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Transformers\AccountTransformer; @@ -62,12 +62,12 @@ class UpdateController extends Controller /** * Update account. * - * @param AccountUpdateRequest $request + * @param UpdateRequest $request * @param Account $account * * @return JsonResponse */ - public function update(AccountUpdateRequest $request, Account $account): JsonResponse + public function update(UpdateRequest $request, Account $account): JsonResponse { $data = $request->getUpdateData(); $data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type); diff --git a/app/Api/V1/Controllers/Models/Attachment/DestroyController.php b/app/Api/V1/Controllers/Models/Attachment/DestroyController.php new file mode 100644 index 0000000000..977556ffcf --- /dev/null +++ b/app/Api/V1/Controllers/Models/Attachment/DestroyController.php @@ -0,0 +1,77 @@ +. + */ + +namespace FireflyIII\Api\V1\Controllers\Models\Attachment; + + +use FireflyIII\Api\V1\Controllers\Controller; +use FireflyIII\Api\V1\Middleware\ApiDemoUser; +use FireflyIII\Models\Attachment; +use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; +use FireflyIII\User; +use Illuminate\Http\JsonResponse; + +/** + * Class DestroyController + */ +class DestroyController extends Controller +{ + private AttachmentRepositoryInterface $repository; + + + /** + * DestroyController constructor. + * + * @codeCoverageIgnore + */ + public function __construct() + { + parent::__construct(); + $this->middleware(ApiDemoUser::class)->except(['delete', 'download', 'show', 'index']); + $this->middleware( + function ($request, $next) { + /** @var User $user */ + $user = auth()->user(); + $this->repository = app(AttachmentRepositoryInterface::class); + $this->repository->setUser($user); + + + return $next($request); + } + ); + } + + /** + * Remove the specified resource from storage. + * + * @codeCoverageIgnore + * + * @param Attachment $attachment + * + * @return JsonResponse + */ + public function destroy(Attachment $attachment): JsonResponse + { + $this->repository->destroy($attachment); + + return response()->json([], 204); + } +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/AttachmentController.php b/app/Api/V1/Controllers/Models/Attachment/ShowController.php similarity index 62% rename from app/Api/V1/Controllers/AttachmentController.php rename to app/Api/V1/Controllers/Models/Attachment/ShowController.php index aba389d7b3..cc49aa53ba 100644 --- a/app/Api/V1/Controllers/AttachmentController.php +++ b/app/Api/V1/Controllers/Models/Attachment/ShowController.php @@ -1,7 +1,7 @@ . */ -declare(strict_types=1); +namespace FireflyIII\Api\V1\Controllers\Models\Attachment; -namespace FireflyIII\Api\V1\Controllers; +use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Middleware\ApiDemoUser; -use FireflyIII\Api\V1\Requests\AttachmentStoreRequest; -use FireflyIII\Api\V1\Requests\AttachmentUpdateRequest; use FireflyIII\Exceptions\FireflyException; -use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Models\Attachment; use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; use FireflyIII\Transformers\AttachmentTransformer; use FireflyIII\User; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Request; use Illuminate\Http\Response as LaravelResponse; use Illuminate\Pagination\LengthAwarePaginator; use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Resource\Collection as FractalCollection; use League\Fractal\Resource\Item; -use Log; -use function strlen; /** - * Class AttachmentController. + * Class ShowController */ -class AttachmentController extends Controller +class ShowController extends Controller { - /** @var AttachmentRepositoryInterface The attachment repository */ - private $repository; + private AttachmentRepositoryInterface $repository; /** - * AccountController constructor. + * ShowController constructor. * * @codeCoverageIgnore */ @@ -73,22 +66,6 @@ class AttachmentController extends Controller ); } - /** - * Remove the specified resource from storage. - * - * @codeCoverageIgnore - * - * @param Attachment $attachment - * - * @return JsonResponse - */ - public function delete(Attachment $attachment): JsonResponse - { - $this->repository->destroy($attachment); - - return response()->json([], 204); - } - /** * Download an attachment. * @@ -144,7 +121,7 @@ class AttachmentController extends Controller // types to get, page size: $pageSize = (int) app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; - // get list of accounts. Count it and split it. + // get list of attachments. Count it and split it. $collection = $this->repository->get(); $count = $collection->count(); $attachments = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); @@ -163,6 +140,8 @@ class AttachmentController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); } + + /** * Display the specified resource. * @@ -181,76 +160,4 @@ class AttachmentController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); } - - /** - * Store a newly created resource in storage. - * - * @param AttachmentStoreRequest $request - * - * @return JsonResponse - * @throws FireflyException - */ - public function store(AttachmentStoreRequest $request): JsonResponse - { - $data = $request->getAll(); - $attachment = $this->repository->store($data); - $manager = $this->getManager(); - - /** @var AttachmentTransformer $transformer */ - $transformer = app(AttachmentTransformer::class); - $transformer->setParameters($this->parameters); - - $resource = new Item($attachment, $transformer, 'attachments'); - - return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); - } - - /** - * Update the specified resource in storage. - * - * @param AttachmentUpdateRequest $request - * @param Attachment $attachment - * - * @return JsonResponse - */ - public function update(AttachmentUpdateRequest $request, Attachment $attachment): JsonResponse - { - $data = $request->getAll(); - $this->repository->update($attachment, $data); - $manager = $this->getManager(); - - /** @var AttachmentTransformer $transformer */ - $transformer = app(AttachmentTransformer::class); - $transformer->setParameters($this->parameters); - - $resource = new Item($attachment, $transformer, 'attachments'); - - return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); - } - - /** - * Upload an attachment. - * - * @codeCoverageIgnore - * - * @param Request $request - * @param Attachment $attachment - * - * @return JsonResponse - */ - public function upload(Request $request, Attachment $attachment): JsonResponse - { - /** @var AttachmentHelperInterface $helper */ - $helper = app(AttachmentHelperInterface::class); - $body = $request->getContent(); - if ('' === $body) { - Log::error('Body of attachment is empty.'); - - return response()->json([], 422); - } - $helper->saveAttachmentFromApi($attachment, $body); - - return response()->json([], 204); - } - -} +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/Models/Attachment/StoreController.php b/app/Api/V1/Controllers/Models/Attachment/StoreController.php new file mode 100644 index 0000000000..20cc6b3c5f --- /dev/null +++ b/app/Api/V1/Controllers/Models/Attachment/StoreController.php @@ -0,0 +1,117 @@ +. + */ + +namespace FireflyIII\Api\V1\Controllers\Models\Attachment; + + +use FireflyIII\Api\V1\Controllers\Controller; +use FireflyIII\Api\V1\Middleware\ApiDemoUser; +use FireflyIII\Api\V1\Requests\Models\Attachment\StoreRequest; +use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; +use FireflyIII\Models\Attachment; +use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; +use FireflyIII\Transformers\AttachmentTransformer; +use FireflyIII\User; +use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; +use League\Fractal\Resource\Item; + +/** + * Class StoreController + */ +class StoreController extends Controller +{ + private AttachmentRepositoryInterface $repository; + + + /** + * StoreController constructor. + * + * @codeCoverageIgnore + */ + public function __construct() + { + parent::__construct(); + $this->middleware(ApiDemoUser::class)->except(['delete', 'download', 'show', 'index']); + $this->middleware( + function ($request, $next) { + /** @var User $user */ + $user = auth()->user(); + $this->repository = app(AttachmentRepositoryInterface::class); + $this->repository->setUser($user); + + + return $next($request); + } + ); + } + + + + /** + * Store a newly created resource in storage. + * + * @param StoreRequest $request + * + * @return JsonResponse + * @throws FireflyException + */ + public function store(StoreRequest $request): JsonResponse + { + $data = $request->getAll(); + $attachment = $this->repository->store($data); + $manager = $this->getManager(); + + /** @var AttachmentTransformer $transformer */ + $transformer = app(AttachmentTransformer::class); + $transformer->setParameters($this->parameters); + + $resource = new Item($attachment, $transformer, 'attachments'); + + return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); + } + + /** + * Upload an attachment. + * + * @codeCoverageIgnore + * + * @param Request $request + * @param Attachment $attachment + * + * @return JsonResponse + */ + public function upload(Request $request, Attachment $attachment): JsonResponse + { + /** @var AttachmentHelperInterface $helper */ + $helper = app(AttachmentHelperInterface::class); + $body = $request->getContent(); + if ('' === $body) { + Log::error('Body of attachment is empty.'); + + return response()->json([], 422); + } + $helper->saveAttachmentFromApi($attachment, $body); + + return response()->json([], 204); + } +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/Models/Attachment/UpdateController.php b/app/Api/V1/Controllers/Models/Attachment/UpdateController.php new file mode 100644 index 0000000000..209a2c6b65 --- /dev/null +++ b/app/Api/V1/Controllers/Models/Attachment/UpdateController.php @@ -0,0 +1,89 @@ +. + */ + +namespace FireflyIII\Api\V1\Controllers\Models\Attachment; + + +use FireflyIII\Api\V1\Controllers\Controller; +use FireflyIII\Api\V1\Middleware\ApiDemoUser; +use FireflyIII\Api\V1\Requests\Models\Attachment\UpdateRequest; +use FireflyIII\Models\Attachment; +use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; +use FireflyIII\Transformers\AttachmentTransformer; +use FireflyIII\User; +use Illuminate\Http\JsonResponse; +use League\Fractal\Resource\Item; + +/** + * Class UpdateController + */ +class UpdateController extends Controller +{ + private AttachmentRepositoryInterface $repository; + + + /** + * UpdateController constructor. + * + * @codeCoverageIgnore + */ + public function __construct() + { + parent::__construct(); + $this->middleware(ApiDemoUser::class)->except(['delete', 'download', 'show', 'index']); + $this->middleware( + function ($request, $next) { + /** @var User $user */ + $user = auth()->user(); + $this->repository = app(AttachmentRepositoryInterface::class); + $this->repository->setUser($user); + + + return $next($request); + } + ); + } + + + + /** + * Update the specified resource in storage. + * + * @param UpdateRequest $request + * @param Attachment $attachment + * + * @return JsonResponse + */ + public function update(UpdateRequest $request, Attachment $attachment): JsonResponse + { + $data = $request->getAll(); + $this->repository->update($attachment, $data); + $manager = $this->getManager(); + + /** @var AttachmentTransformer $transformer */ + $transformer = app(AttachmentTransformer::class); + $transformer->setParameters($this->parameters); + + $resource = new Item($attachment, $transformer, 'attachments'); + + return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); + } +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/Models/AvailableBudget/DestroyController.php b/app/Api/V1/Controllers/Models/AvailableBudget/DestroyController.php new file mode 100644 index 0000000000..79f264d4cf --- /dev/null +++ b/app/Api/V1/Controllers/Models/AvailableBudget/DestroyController.php @@ -0,0 +1,72 @@ +. + */ + +namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget; + + +use FireflyIII\Api\V1\Controllers\Controller; +use FireflyIII\Models\AvailableBudget; +use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; +use FireflyIII\User; +use Illuminate\Http\JsonResponse; + +/** + * Class DestroyController + */ +class DestroyController extends Controller +{ + private AvailableBudgetRepositoryInterface $abRepository; + + /** + * AvailableBudgetController constructor. + * + * @codeCoverageIgnore + */ + public function __construct() + { + parent::__construct(); + $this->middleware( + function ($request, $next) { + /** @var User $user */ + $user = auth()->user(); + $this->abRepository = app(AvailableBudgetRepositoryInterface::class); + $this->abRepository->setUser($user); + + return $next($request); + } + ); + } + /** + * Remove the specified resource from storage. + * + * @param AvailableBudget $availableBudget + * + * @codeCoverageIgnore + * + * @return JsonResponse + */ + public function destroy(AvailableBudget $availableBudget): JsonResponse + { + $this->abRepository->destroyAvailableBudget($availableBudget); + + return response()->json([], 204); + } +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/AvailableBudgetController.php b/app/Api/V1/Controllers/Models/AvailableBudget/ShowController.php similarity index 53% rename from app/Api/V1/Controllers/AvailableBudgetController.php rename to app/Api/V1/Controllers/Models/AvailableBudget/ShowController.php index 4a1d8e8955..459e6816ca 100644 --- a/app/Api/V1/Controllers/AvailableBudgetController.php +++ b/app/Api/V1/Controllers/Models/AvailableBudget/ShowController.php @@ -1,7 +1,7 @@ . */ -declare(strict_types=1); +namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget; -namespace FireflyIII\Api\V1\Controllers; -use FireflyIII\Api\V1\Requests\AvailableBudgetRequest; -use FireflyIII\Factory\TransactionCurrencyFactory; +use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Models\AvailableBudget; -use FireflyIII\Models\TransactionCurrency; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Transformers\AvailableBudgetTransformer; use FireflyIII\User; @@ -37,9 +34,9 @@ use League\Fractal\Resource\Collection as FractalCollection; use League\Fractal\Resource\Item; /** - * Class AvailableBudgetController. + * Class ShowController */ -class AvailableBudgetController extends Controller +class ShowController extends Controller { private AvailableBudgetRepositoryInterface $abRepository; @@ -63,22 +60,6 @@ class AvailableBudgetController extends Controller ); } - /** - * Remove the specified resource from storage. - * - * @param AvailableBudget $availableBudget - * - * @codeCoverageIgnore - * - * @return JsonResponse - */ - public function delete(AvailableBudget $availableBudget): JsonResponse - { - $this->abRepository->destroyAvailableBudget($availableBudget); - - return response()->json([], 204); - } - /** * Display a listing of the resource. * @@ -135,77 +116,4 @@ class AvailableBudgetController extends Controller return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); } - /** - * Store a newly created resource in storage. - * - * @param AvailableBudgetRequest $request - * - * @return JsonResponse - */ - public function store(AvailableBudgetRequest $request): JsonResponse - { - $data = $request->getAll(); - $data['start']->startOfDay(); - $data['end']->endOfDay(); - - /** @var TransactionCurrencyFactory $factory */ - $factory = app(TransactionCurrencyFactory::class); - $currency = $factory->find($data['currency_id'], $data['currency_code']); - - if (null === $currency) { - $currency = app('amount')->getDefaultCurrency(); - } - $data['currency'] = $currency; - $availableBudget = $this->abRepository->store($data); - $manager = $this->getManager(); - - /** @var AvailableBudgetTransformer $transformer */ - $transformer = app(AvailableBudgetTransformer::class); - $transformer->setParameters($this->parameters); - - $resource = new Item($availableBudget, $transformer, 'available_budgets'); - - return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); - } - - - /** - * Update the specified resource in storage. - * - * @param AvailableBudgetRequest $request - * @param AvailableBudget $availableBudget - * - * @return JsonResponse - */ - public function update(AvailableBudgetRequest $request, AvailableBudget $availableBudget): JsonResponse - { - $data = $request->getAll(); - - /** @var TransactionCurrencyFactory $factory */ - $factory = app(TransactionCurrencyFactory::class); - /** @var TransactionCurrency $currency */ - $currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null); - - if (null === $currency) { - // use default currency: - $currency = app('amount')->getDefaultCurrency(); - } - $currency->enabled = true; - $currency->save(); - unset($data['currency_code']); - $data['currency_id'] = $currency->id; - - - $this->abRepository->updateAvailableBudget($availableBudget, $data); - $manager = $this->getManager(); - - /** @var AvailableBudgetTransformer $transformer */ - $transformer = app(AvailableBudgetTransformer::class); - $transformer->setParameters($this->parameters); - - $resource = new Item($availableBudget, $transformer, 'available_budgets'); - - return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); - - } -} +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/Models/AvailableBudget/StoreController.php b/app/Api/V1/Controllers/Models/AvailableBudget/StoreController.php new file mode 100644 index 0000000000..ac60e870e8 --- /dev/null +++ b/app/Api/V1/Controllers/Models/AvailableBudget/StoreController.php @@ -0,0 +1,92 @@ +. + */ + +namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget; + + +use FireflyIII\Api\V1\Controllers\Controller; +use FireflyIII\Api\V1\Requests\Models\AvailableBudget\Request; +use FireflyIII\Factory\TransactionCurrencyFactory; +use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; +use FireflyIII\Transformers\AvailableBudgetTransformer; +use FireflyIII\User; +use Illuminate\Http\JsonResponse; +use League\Fractal\Resource\Item; + +/** + * Class StoreController + */ +class StoreController extends Controller +{ + private AvailableBudgetRepositoryInterface $abRepository; + + /** + * AvailableBudgetController constructor. + * + * @codeCoverageIgnore + */ + public function __construct() + { + parent::__construct(); + $this->middleware( + function ($request, $next) { + /** @var User $user */ + $user = auth()->user(); + $this->abRepository = app(AvailableBudgetRepositoryInterface::class); + $this->abRepository->setUser($user); + + return $next($request); + } + ); + } + /** + * Store a newly created resource in storage. + * + * @param Request $request + * + * @return JsonResponse + */ + public function store(Request $request): JsonResponse + { + $data = $request->getAll(); + $data['start']->startOfDay(); + $data['end']->endOfDay(); + + /** @var TransactionCurrencyFactory $factory */ + $factory = app(TransactionCurrencyFactory::class); + $currency = $factory->find($data['currency_id'], $data['currency_code']); + + if (null === $currency) { + $currency = app('amount')->getDefaultCurrency(); + } + $data['currency'] = $currency; + $availableBudget = $this->abRepository->store($data); + $manager = $this->getManager(); + + /** @var AvailableBudgetTransformer $transformer */ + $transformer = app(AvailableBudgetTransformer::class); + $transformer->setParameters($this->parameters); + + $resource = new Item($availableBudget, $transformer, 'available_budgets'); + + return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); + } +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/Models/AvailableBudget/UpdateController.php b/app/Api/V1/Controllers/Models/AvailableBudget/UpdateController.php new file mode 100644 index 0000000000..37d53c4b32 --- /dev/null +++ b/app/Api/V1/Controllers/Models/AvailableBudget/UpdateController.php @@ -0,0 +1,102 @@ +. + */ + +namespace FireflyIII\Api\V1\Controllers\Models\AvailableBudget; + + +use FireflyIII\Api\V1\Controllers\Controller; +use FireflyIII\Api\V1\Requests\AvailableBudget\Request; +use FireflyIII\Factory\TransactionCurrencyFactory; +use FireflyIII\Models\AvailableBudget; +use FireflyIII\Models\TransactionCurrency; +use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; +use FireflyIII\Transformers\AvailableBudgetTransformer; +use FireflyIII\User; +use Illuminate\Http\JsonResponse; +use League\Fractal\Resource\Item; + +/** + * Class UpdateController + */ +class UpdateController extends Controller +{ + private AvailableBudgetRepositoryInterface $abRepository; + + /** + * AvailableBudgetController constructor. + * + * @codeCoverageIgnore + */ + public function __construct() + { + parent::__construct(); + $this->middleware( + function ($request, $next) { + /** @var User $user */ + $user = auth()->user(); + $this->abRepository = app(AvailableBudgetRepositoryInterface::class); + $this->abRepository->setUser($user); + + return $next($request); + } + ); + } + + /** + * Update the specified resource in storage. + * + * @param Request $request + * @param AvailableBudget $availableBudget + * + * @return JsonResponse + */ + public function update(Request $request, AvailableBudget $availableBudget): JsonResponse + { + $data = $request->getAll(); + + /** @var TransactionCurrencyFactory $factory */ + $factory = app(TransactionCurrencyFactory::class); + /** @var TransactionCurrency $currency */ + $currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null); + + if (null === $currency) { + // use default currency: + $currency = app('amount')->getDefaultCurrency(); + } + $currency->enabled = true; + $currency->save(); + unset($data['currency_code']); + $data['currency_id'] = $currency->id; + + + $this->abRepository->updateAvailableBudget($availableBudget, $data); + $manager = $this->getManager(); + + /** @var AvailableBudgetTransformer $transformer */ + $transformer = app(AvailableBudgetTransformer::class); + $transformer->setParameters($this->parameters); + + $resource = new Item($availableBudget, $transformer, 'available_budgets'); + + return response()->json($manager->createData($resource)->toArray())->header('Content-Type', self::CONTENT_TYPE); + + } +} \ No newline at end of file diff --git a/app/Api/V1/Controllers/Destruction/DestroyController.php b/app/Api/V1/Controllers/todo-Destruction/DestroyController.php similarity index 100% rename from app/Api/V1/Controllers/Destruction/DestroyController.php rename to app/Api/V1/Controllers/todo-Destruction/DestroyController.php diff --git a/app/Api/V1/Controllers/Preferences/IndexController.php b/app/Api/V1/Controllers/todo-Preferences/IndexController.php similarity index 100% rename from app/Api/V1/Controllers/Preferences/IndexController.php rename to app/Api/V1/Controllers/todo-Preferences/IndexController.php diff --git a/app/Api/V1/Controllers/Search/AccountController.php b/app/Api/V1/Controllers/todo-Search/AccountController.php similarity index 100% rename from app/Api/V1/Controllers/Search/AccountController.php rename to app/Api/V1/Controllers/todo-Search/AccountController.php diff --git a/app/Api/V1/Controllers/Search/TransactionController.php b/app/Api/V1/Controllers/todo-Search/TransactionController.php similarity index 100% rename from app/Api/V1/Controllers/Search/TransactionController.php rename to app/Api/V1/Controllers/todo-Search/TransactionController.php diff --git a/app/Api/V1/Controllers/System/AboutController.php b/app/Api/V1/Controllers/todo-System/AboutController.php similarity index 100% rename from app/Api/V1/Controllers/System/AboutController.php rename to app/Api/V1/Controllers/todo-System/AboutController.php diff --git a/app/Api/V1/Controllers/System/DynamicConfigController.php b/app/Api/V1/Controllers/todo-System/DynamicConfigController.php similarity index 100% rename from app/Api/V1/Controllers/System/DynamicConfigController.php rename to app/Api/V1/Controllers/todo-System/DynamicConfigController.php diff --git a/app/Api/V1/Controllers/System/StaticConfigController.php b/app/Api/V1/Controllers/todo-System/StaticConfigController.php similarity index 100% rename from app/Api/V1/Controllers/System/StaticConfigController.php rename to app/Api/V1/Controllers/todo-System/StaticConfigController.php diff --git a/app/Api/V1/Controllers/Webhook/CreateController.php b/app/Api/V1/Controllers/todo-Webhook/CreateController.php similarity index 100% rename from app/Api/V1/Controllers/Webhook/CreateController.php rename to app/Api/V1/Controllers/todo-Webhook/CreateController.php diff --git a/app/Api/V1/Controllers/Webhook/DeleteController.php b/app/Api/V1/Controllers/todo-Webhook/DeleteController.php similarity index 100% rename from app/Api/V1/Controllers/Webhook/DeleteController.php rename to app/Api/V1/Controllers/todo-Webhook/DeleteController.php diff --git a/app/Api/V1/Controllers/Webhook/EditController.php b/app/Api/V1/Controllers/todo-Webhook/EditController.php similarity index 100% rename from app/Api/V1/Controllers/Webhook/EditController.php rename to app/Api/V1/Controllers/todo-Webhook/EditController.php diff --git a/app/Api/V1/Controllers/Webhook/IndexController.php b/app/Api/V1/Controllers/todo-Webhook/IndexController.php similarity index 100% rename from app/Api/V1/Controllers/Webhook/IndexController.php rename to app/Api/V1/Controllers/todo-Webhook/IndexController.php diff --git a/app/Api/V1/Controllers/BillController.php b/app/Api/V1/Controllers/todo/BillController.php similarity index 100% rename from app/Api/V1/Controllers/BillController.php rename to app/Api/V1/Controllers/todo/BillController.php diff --git a/app/Api/V1/Controllers/BudgetLimitController.php b/app/Api/V1/Controllers/todo/BudgetLimitController.php similarity index 100% rename from app/Api/V1/Controllers/BudgetLimitController.php rename to app/Api/V1/Controllers/todo/BudgetLimitController.php diff --git a/app/Api/V1/Controllers/CategoryController.php b/app/Api/V1/Controllers/todo/CategoryController.php similarity index 100% rename from app/Api/V1/Controllers/CategoryController.php rename to app/Api/V1/Controllers/todo/CategoryController.php diff --git a/app/Api/V1/Controllers/CurrencyController.php b/app/Api/V1/Controllers/todo/CurrencyController.php similarity index 100% rename from app/Api/V1/Controllers/CurrencyController.php rename to app/Api/V1/Controllers/todo/CurrencyController.php diff --git a/app/Api/V1/Controllers/LinkTypeController.php b/app/Api/V1/Controllers/todo/LinkTypeController.php similarity index 100% rename from app/Api/V1/Controllers/LinkTypeController.php rename to app/Api/V1/Controllers/todo/LinkTypeController.php diff --git a/app/Api/V1/Controllers/ObjectGroupController.php b/app/Api/V1/Controllers/todo/ObjectGroupController.php similarity index 100% rename from app/Api/V1/Controllers/ObjectGroupController.php rename to app/Api/V1/Controllers/todo/ObjectGroupController.php diff --git a/app/Api/V1/Controllers/PreferenceController.php b/app/Api/V1/Controllers/todo/PreferenceController.php similarity index 100% rename from app/Api/V1/Controllers/PreferenceController.php rename to app/Api/V1/Controllers/todo/PreferenceController.php diff --git a/app/Api/V1/Controllers/RecurrenceController.php b/app/Api/V1/Controllers/todo/RecurrenceController.php similarity index 100% rename from app/Api/V1/Controllers/RecurrenceController.php rename to app/Api/V1/Controllers/todo/RecurrenceController.php diff --git a/app/Api/V1/Controllers/RuleController.php b/app/Api/V1/Controllers/todo/RuleController.php similarity index 100% rename from app/Api/V1/Controllers/RuleController.php rename to app/Api/V1/Controllers/todo/RuleController.php diff --git a/app/Api/V1/Controllers/RuleGroupController.php b/app/Api/V1/Controllers/todo/RuleGroupController.php similarity index 100% rename from app/Api/V1/Controllers/RuleGroupController.php rename to app/Api/V1/Controllers/todo/RuleGroupController.php diff --git a/app/Api/V1/Controllers/TagController.php b/app/Api/V1/Controllers/todo/TagController.php similarity index 100% rename from app/Api/V1/Controllers/TagController.php rename to app/Api/V1/Controllers/todo/TagController.php diff --git a/app/Api/V1/Controllers/TransactionLinkController.php b/app/Api/V1/Controllers/todo/TransactionLinkController.php similarity index 100% rename from app/Api/V1/Controllers/TransactionLinkController.php rename to app/Api/V1/Controllers/todo/TransactionLinkController.php diff --git a/app/Api/V1/Controllers/UserController.php b/app/Api/V1/Controllers/todo/UserController.php similarity index 100% rename from app/Api/V1/Controllers/UserController.php rename to app/Api/V1/Controllers/todo/UserController.php diff --git a/app/Api/V1/Requests/AccountStoreRequest.php b/app/Api/V1/Requests/Models/Account/StoreRequest.php similarity index 97% rename from app/Api/V1/Requests/AccountStoreRequest.php rename to app/Api/V1/Requests/Models/Account/StoreRequest.php index 29274f6e57..eb571e3d16 100644 --- a/app/Api/V1/Requests/AccountStoreRequest.php +++ b/app/Api/V1/Requests/Models/Account/StoreRequest.php @@ -1,8 +1,8 @@ $currency['id'], + 'currency_id' => (string) $currency['id'], 'currency_code' => $code, 'currency_name' => $currency['name'], 'currency_symbol' => $currency['symbol'], diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php index 150bcca996..1c4399ab96 100644 --- a/app/Repositories/Budget/OperationsRepository.php +++ b/app/Repositories/Budget/OperationsRepository.php @@ -264,7 +264,7 @@ class OperationsRepository implements OperationsRepositoryInterface /** @var TransactionCurrency $currency */ $currency = $currencies[$code]; $return[] = [ - 'currency_id' => $currency['id'], + 'currency_id' => (string)$currency['id'], 'currency_code' => $code, 'currency_name' => $currency['name'], 'currency_symbol' => $currency['symbol'], diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 231a31a9b6..b56a78c179 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -63,7 +63,7 @@ class AccountTransformer extends AbstractTransformer $fullType = $account->accountType->type; $accountType = (string) config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); $liabilityType = (string) config(sprintf('firefly.shortLiabilityNameByFullName.%s', $fullType)); - $liabilityType = '' === $liabilityType ? null : $liabilityType; + $liabilityType = '' === $liabilityType ? null : strtolower($liabilityType); // get account role (will only work if the type is asset. $accountRole = $this->getAccountRole($account, $accountType); diff --git a/app/Transformers/AttachmentTransformer.php b/app/Transformers/AttachmentTransformer.php index 5dbe9193b0..a546445eae 100644 --- a/app/Transformers/AttachmentTransformer.php +++ b/app/Transformers/AttachmentTransformer.php @@ -60,10 +60,10 @@ class AttachmentTransformer extends AbstractTransformer $this->repository->setUser($attachment->user); return [ - 'id' => (int)$attachment->id, + 'id' => (string)$attachment->id, 'created_at' => $attachment->created_at->toAtomString(), 'updated_at' => $attachment->updated_at->toAtomString(), - 'attachable_id' => (int) $attachment->attachable_id, + 'attachable_id' => (string)$attachment->attachable_id, 'attachable_type' => str_replace('FireflyIII\\Models\\', '', $attachment->attachable_type), 'md5' => $attachment->md5, 'filename' => $attachment->filename, diff --git a/app/Transformers/AvailableBudgetTransformer.php b/app/Transformers/AvailableBudgetTransformer.php index 46bf5289f5..538a18547f 100644 --- a/app/Transformers/AvailableBudgetTransformer.php +++ b/app/Transformers/AvailableBudgetTransformer.php @@ -36,12 +36,9 @@ use Log; */ class AvailableBudgetTransformer extends AbstractTransformer { - /** @var NoBudgetRepositoryInterface */ - private $noBudgetRepository; - /** @var OperationsRepositoryInterface */ - private $opsRepository; - /** @var BudgetRepositoryInterface */ - private $repository; + private NoBudgetRepositoryInterface $noBudgetRepository; + private OperationsRepositoryInterface $opsRepository; + private BudgetRepositoryInterface $repository; /** * CurrencyTransformer constructor. @@ -53,9 +50,6 @@ class AvailableBudgetTransformer extends AbstractTransformer $this->repository = app(BudgetRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class); $this->noBudgetRepository = app(NoBudgetRepositoryInterface::class); - if ('testing' === config('app.env')) { - Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); - } } /** @@ -71,10 +65,10 @@ class AvailableBudgetTransformer extends AbstractTransformer $currency = $availableBudget->transactionCurrency; $data = [ - 'id' => (int)$availableBudget->id, + 'id' => (string)$availableBudget->id, 'created_at' => $availableBudget->created_at->toAtomString(), 'updated_at' => $availableBudget->updated_at->toAtomString(), - 'currency_id' => (int) $currency->id, + 'currency_id' => (string) $currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, 'currency_decimal_places' => (int) $currency->decimal_places, diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php index 37ec5a9539..213d0c00db 100644 --- a/app/Transformers/BillTransformer.php +++ b/app/Transformers/BillTransformer.php @@ -97,7 +97,7 @@ class BillTransformer extends AbstractTransformer 'next_expected_match' => $paidData['next_expected_match'], 'pay_dates' => $payDates, 'paid_dates' => $paidData['paid_dates'], - 'object_group_id' => $objectGroupId, + 'object_group_id' => (string) $objectGroupId, 'object_group_order' => $objectGroupOrder, 'object_group_title' => $objectGroupTitle, 'links' => [ diff --git a/app/Transformers/PiggyBankTransformer.php b/app/Transformers/PiggyBankTransformer.php index c1f6cdc5cf..46d39a806e 100644 --- a/app/Transformers/PiggyBankTransformer.php +++ b/app/Transformers/PiggyBankTransformer.php @@ -125,7 +125,7 @@ class PiggyBankTransformer extends AbstractTransformer 'order' => (int) $piggyBank->order, 'active' => true, 'notes' => $notes, - 'object_group_id' => $objectGroupId, + 'object_group_id' => (string) $objectGroupId, 'object_group_order' => $objectGroupOrder, 'object_group_title' => $objectGroupTitle, 'links' => [ diff --git a/routes/api.php b/routes/api.php index c5228dd835..253c2137a8 100644 --- a/routes/api.php +++ b/routes/api.php @@ -145,6 +145,8 @@ Route::group( // Insight in transfers +// TODO + /** @@ -158,6 +160,81 @@ Route::group( Route::get('basic', ['uses' => 'BasicController@basic', 'as' => 'basic']); } ); + +/** + * MODELS + */ +// Accounts API routes: +Route::group( + ['namespace' => 'FireflyIII\Api\V1\Controllers\Models\Account', 'prefix' => 'accounts', + 'as' => 'api.v1.accounts.',], + static function () { + + Route::get('', ['uses' => 'ShowController@index', 'as' => 'index']); + Route::post('', ['uses' => 'StoreController@store', 'as' => 'store']); + Route::get('{account}', ['uses' => 'ShowController@show', 'as' => 'show']); + Route::put('{account}', ['uses' => 'UpdateController@update', 'as' => 'update']); + Route::delete('{account}', ['uses' => 'DestroyController@destroy', 'as' => 'delete']); + + Route::get('{account}/piggy_banks', ['uses' => 'ListController@piggyBanks', 'as' => 'piggy_banks']); + Route::get('{account}/transactions', ['uses' => 'ListController@transactions', 'as' => 'transactions']); + Route::get('{account}/attachments', ['uses' => 'ListController@attachments', 'as' => 'attachments']); + } +); + +// Attachment API routes: +Route::group( + ['namespace' => 'FireflyIII\Api\V1\Controllers\Models\Attachment', 'prefix' => 'attachments', + 'as' => 'api.v1.attachments.',], + static function () { + + Route::get('', ['uses' => 'ShowController@index', 'as' => 'index']); + Route::post('', ['uses' => 'StoreController@store', 'as' => 'store']); + Route::get('{attachment}', ['uses' => 'ShowController@show', 'as' => 'show']); + Route::get('{attachment}/download', ['uses' => 'ShowController@download', 'as' => 'download']); + Route::post('{attachment}/upload', ['uses' => 'StoreController@upload', 'as' => 'upload']); + Route::put('{attachment}', ['uses' => 'UpdateController@update', 'as' => 'update']); + Route::delete('{attachment}', ['uses' => 'DestroyController@destroy', 'as' => 'delete']); + } +); +// Available Budget API routes: +Route::group( + ['namespace' => 'FireflyIII\Api\V1\Controllers\Models\AvailableBudget', 'prefix' => 'available_budgets', + 'as' => 'api.v1.available_budgets.',], + static function () { + + Route::get('', ['uses' => 'ShowController@index', 'as' => 'index']); + Route::post('', ['uses' => 'StoreController@store', 'as' => 'store']); + Route::get('{availableBudget}', ['uses' => 'ShowController@show', 'as' => 'show']); + Route::put('{availableBudget}', ['uses' => 'UpdateController@update', 'as' => 'update']); + Route::delete('{availableBudget}', ['uses' => 'DestroyController@destroy', 'as' => 'delete']); + } +); + + + + + + + + + + + + + + + + + + + + + + + + + /** * DATA CONTROLLERS @@ -227,24 +304,7 @@ Route::group( ); -// TODO VERIFY API DOCS -Route::group( - ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'accounts', - 'as' => 'api.v1.accounts.',], - static function () { - // Accounts API routes: - Route::get('', ['uses' => 'Models\Account\ShowController@index', 'as' => 'index']); - Route::post('', ['uses' => 'Models\Account\StoreController@store', 'as' => 'store']); - Route::get('{account}', ['uses' => 'Models\Account\ShowController@show', 'as' => 'show']); - Route::put('{account}', ['uses' => 'Models\Account\UpdateController@update', 'as' => 'update']); - Route::delete('{account}', ['uses' => 'Models\Account\DestroyController@destroy', 'as' => 'delete']); - - Route::get('{account}/piggy_banks', ['uses' => 'Models\Account\ListController@piggyBanks', 'as' => 'piggy_banks']); - Route::get('{account}/transactions', ['uses' => 'Models\Account\ListController@transactions', 'as' => 'transactions']); - Route::get('{account}/attachments', ['uses' => 'Models\Account\ListController@attachments', 'as' => 'attachments']); - } -); // TODO VERIFY API DOCS @@ -263,37 +323,9 @@ Route::group( } ); -// TODO VERIFY API DOCS -Route::group( - ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'attachments', - 'as' => 'api.v1.attachments.',], - static function () { - // Attachment API routes: - Route::get('', ['uses' => 'AttachmentController@index', 'as' => 'index']); - Route::post('', ['uses' => 'AttachmentController@store', 'as' => 'store']); - Route::get('{attachment}', ['uses' => 'AttachmentController@show', 'as' => 'show']); - Route::get('{attachment}/download', ['uses' => 'AttachmentController@download', 'as' => 'download']); - Route::post('{attachment}/upload', ['uses' => 'AttachmentController@upload', 'as' => 'upload']); - Route::put('{attachment}', ['uses' => 'AttachmentController@update', 'as' => 'update']); - Route::delete('{attachment}', ['uses' => 'AttachmentController@delete', 'as' => 'delete']); - } -); -// TODO VERIFY API DOCS -Route::group( - ['namespace' => 'FireflyIII\Api\V1\Controllers', 'prefix' => 'available_budgets', - 'as' => 'api.v1.available_budgets.',], - static function () { - // Available Budget API routes: - Route::get('', ['uses' => 'AvailableBudgetController@index', 'as' => 'index']); - Route::post('', ['uses' => 'AvailableBudgetController@store', 'as' => 'store']); - Route::get('{availableBudget}', ['uses' => 'AvailableBudgetController@show', 'as' => 'show']); - Route::put('{availableBudget}', ['uses' => 'AvailableBudgetController@update', 'as' => 'update']); - Route::delete('{availableBudget}', ['uses' => 'AvailableBudgetController@delete', 'as' => 'delete']); - } -); // TODO VERIFY API DOCS Route::group(