mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-02 12:15:55 +00:00
New endpoints for transactions.
This commit is contained in:
@@ -26,8 +26,6 @@ namespace FireflyIII\Transformers;
|
||||
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use League\Fractal\Resource\Collection as FractalCollection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -36,19 +34,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
*/
|
||||
class AttachmentTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* List of resources possible to include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['user'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = ['user'];
|
||||
|
||||
/** @var ParameterBag */
|
||||
protected $parameters;
|
||||
|
||||
@@ -68,20 +53,6 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
$this->repository = app(AttachmentRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach the user.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function includeUser(Attachment $attachment): Item
|
||||
{
|
||||
return $this->item($attachment->user, new UserTransformer($this->parameters), 'users');
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform attachment.
|
||||
*
|
||||
@@ -97,7 +68,8 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
'id' => (int)$attachment->id,
|
||||
'updated_at' => $attachment->updated_at->toAtomString(),
|
||||
'created_at' => $attachment->created_at->toAtomString(),
|
||||
'attachable_type' => $attachment->attachable_type,
|
||||
'attachable_id' => $attachment->attachable_id,
|
||||
'attachable_type' => str_replace('FireflyIII\\Models\\','',$attachment->attachable_type),
|
||||
'md5' => $attachment->md5,
|
||||
'filename' => $attachment->filename,
|
||||
'download_uri' => route('api.v1.attachments.download', [$attachment->id]),
|
||||
|
||||
@@ -24,12 +24,9 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\Resource\Item;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
|
||||
@@ -38,19 +35,6 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
*/
|
||||
class PiggyBankEventTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* List of resources possible to include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['piggy_bank', 'transaction'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = [];
|
||||
|
||||
/** @var ParameterBag */
|
||||
protected $parameters;
|
||||
|
||||
@@ -66,50 +50,6 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include piggy bank into end result.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param PiggyBankEvent $event
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function includePiggyBank(PiggyBankEvent $event): Item
|
||||
{
|
||||
return $this->item($event->piggyBank, new PiggyBankTransformer($this->parameters), 'piggy_banks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Include transaction into end result.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param PiggyBankEvent $event
|
||||
*
|
||||
* @return Item
|
||||
*/
|
||||
public function includeTransaction(PiggyBankEvent $event): Item
|
||||
{
|
||||
$journal = $event->transactionJournal;
|
||||
$pageSize = (int)app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data;
|
||||
|
||||
// journals always use collector and limited using URL parameters.
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($journal->user);
|
||||
$collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation();
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->setJournals(new Collection([$journal]));
|
||||
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
|
||||
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
|
||||
}
|
||||
$collector->setLimit($pageSize)->setPage($this->parameters->get('page'));
|
||||
$transactions = $collector->getTransactions();
|
||||
|
||||
return $this->item($transactions->first(), new TransactionTransformer($this->parameters), 'transactions');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert piggy bank event.
|
||||
*
|
||||
@@ -125,6 +65,8 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
$accountRepos->setUser($account->user);
|
||||
|
||||
$currencyId = (int)$accountRepos->getMetaValue($account, 'currency_id');
|
||||
$journal = $event->transactionJournal;
|
||||
$transactionId = null;
|
||||
$decimalPlaces = 2;
|
||||
if ($currencyId > 0) {
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
@@ -134,13 +76,24 @@ class PiggyBankEventTransformer extends TransformerAbstract
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
$decimalPlaces = $currency->decimal_places;
|
||||
}
|
||||
if (0 === $currencyId) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($account->user);
|
||||
}
|
||||
if (null !== $journal) {
|
||||
$transactionId = $journal->transactions()->first()->id;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'id' => (int)$event->id,
|
||||
'updated_at' => $event->updated_at->toAtomString(),
|
||||
'created_at' => $event->created_at->toAtomString(),
|
||||
'amount' => round($event->amount, $decimalPlaces),
|
||||
'links' => [
|
||||
'id' => (int)$event->id,
|
||||
'updated_at' => $event->updated_at->toAtomString(),
|
||||
'created_at' => $event->created_at->toAtomString(),
|
||||
'amount' => round($event->amount, $decimalPlaces),
|
||||
'currency_id' => $currency->id,
|
||||
'currency_code' => $currency->code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_dp' => $currency->decimal_places,
|
||||
'transaction_id' => $transactionId,
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
'uri' => '/piggy_bank_events/' . $event->id,
|
||||
|
||||
Reference in New Issue
Block a user