mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update transaction journal repository / provider
This commit is contained in:
parent
b4f1bbf793
commit
5ce4104644
@ -84,7 +84,6 @@ class FireflyServiceProvider extends ServiceProvider
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->app->bind('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface', 'FireflyIII\Repositories\Category\SingleCategoryRepository');
|
$this->app->bind('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface', 'FireflyIII\Repositories\Category\SingleCategoryRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Journal\JournalRepositoryInterface', 'FireflyIII\Repositories\Journal\JournalRepository');
|
|
||||||
$this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepository');
|
$this->app->bind('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface', 'FireflyIII\Repositories\PiggyBank\PiggyBankRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
$this->app->bind('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface', 'FireflyIII\Repositories\Currency\CurrencyRepository');
|
||||||
$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository');
|
$this->app->bind('FireflyIII\Repositories\Tag\TagRepositoryInterface', 'FireflyIII\Repositories\Tag\TagRepository');
|
||||||
|
49
app/Providers/JournalServiceProvider.php
Normal file
49
app/Providers/JournalServiceProvider.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FireflyIII\Providers;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class JournalServiceProvider
|
||||||
|
*
|
||||||
|
* @package FireflyIII\Providers
|
||||||
|
*/
|
||||||
|
class JournalServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap the application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
$this->app->bind(
|
||||||
|
'FireflyIII\Repositories\Journal\JournalRepositoryInterface',
|
||||||
|
function (Application $app, array $arguments) {
|
||||||
|
if (!isset($arguments[0]) && Auth::check()) {
|
||||||
|
return app('FireflyIII\Repositories\Journal\JournalRepository', [Auth::user()]);
|
||||||
|
} else {
|
||||||
|
if (!isset($arguments[0]) && !Auth::check()) {
|
||||||
|
throw new FireflyException('There is no user present.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return app('FireflyIII\Repositories\Journal\JournalRepository', $arguments);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@ declare(strict_types = 1);
|
|||||||
|
|
||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use Auth;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
@ -15,6 +14,7 @@ use FireflyIII\Models\Tag;
|
|||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\User;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@ -26,6 +26,19 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class JournalRepository implements JournalRepositoryInterface
|
class JournalRepository implements JournalRepositoryInterface
|
||||||
{
|
{
|
||||||
|
/** @var User */
|
||||||
|
private $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BillRepository constructor.
|
||||||
|
*
|
||||||
|
* @param User $user
|
||||||
|
*/
|
||||||
|
public function __construct(User $user)
|
||||||
|
{
|
||||||
|
Log::debug('Constructed transaction journal repository for user #' . $user->id . ' (' . $user->email . ')');
|
||||||
|
$this->user = $user;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TransactionJournal $journal
|
* @param TransactionJournal $journal
|
||||||
@ -46,7 +59,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function first()
|
public function first()
|
||||||
{
|
{
|
||||||
$entry = Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
$entry = $this->user->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
||||||
|
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
@ -85,7 +98,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getCollectionOfTypes(array $types, int $offset, int $count)
|
public function getCollectionOfTypes(array $types, int $offset, int $count)
|
||||||
{
|
{
|
||||||
$set = Auth::user()->transactionJournals()->transactionTypes($types)
|
$set = $this->user->transactionJournals()->transactionTypes($types)
|
||||||
->take($count)->offset($offset)
|
->take($count)->offset($offset)
|
||||||
->orderBy('date', 'DESC')
|
->orderBy('date', 'DESC')
|
||||||
->orderBy('order', 'ASC')
|
->orderBy('order', 'ASC')
|
||||||
@ -104,7 +117,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getJournalsOfType(TransactionType $dbType)
|
public function getJournalsOfType(TransactionType $dbType)
|
||||||
{
|
{
|
||||||
return Auth::user()->transactionjournals()->where('transaction_type_id', $dbType->id)->orderBy('id', 'DESC')->take(50)->get();
|
return $this->user->transactionjournals()->where('transaction_type_id', $dbType->id)->orderBy('id', 'DESC')->take(50)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -118,7 +131,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getJournalsOfTypes(array $types, int $offset, int $page, int $pagesize = 50)
|
public function getJournalsOfTypes(array $types, int $offset, int $page, int $pagesize = 50)
|
||||||
{
|
{
|
||||||
$set = Auth::user()
|
$set = $this->user
|
||||||
->transactionJournals()
|
->transactionJournals()
|
||||||
->expanded()
|
->expanded()
|
||||||
->transactionTypes($types)
|
->transactionTypes($types)
|
||||||
@ -129,7 +142,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
->orderBy('id', 'DESC')
|
->orderBy('id', 'DESC')
|
||||||
->get(TransactionJournal::QUERYFIELDS);
|
->get(TransactionJournal::QUERYFIELDS);
|
||||||
|
|
||||||
$count = Auth::user()->transactionJournals()->transactionTypes($types)->count();
|
$count = $this->user->transactionJournals()->transactionTypes($types)->count();
|
||||||
$journals = new LengthAwarePaginator($set, $count, $pagesize, $page);
|
$journals = new LengthAwarePaginator($set, $count, $pagesize, $page);
|
||||||
|
|
||||||
return $journals;
|
return $journals;
|
||||||
@ -153,7 +166,7 @@ class JournalRepository implements JournalRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getWithDate(int $journalId, Carbon $date)
|
public function getWithDate(int $journalId, Carbon $date)
|
||||||
{
|
{
|
||||||
return Auth::user()->transactionjournals()->where('id', $journalId)->where('date', $date->format('Y-m-d 00:00:00'))->first();
|
return $this->user->transactionjournals()->where('id', $journalId)->where('date', $date->format('Y-m-d 00:00:00'))->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user