Skip to content

Commit

Permalink
Refactor personal accounts related code & add list view
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmytych committed Dec 27, 2023
1 parent cf1100d commit b05d9cb
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions TODOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Check what is happening after changing user settings currency.
* Styles improvements for mobile.
* Totally reorganize reports.
* After first synchronization with bank, new personal account should be created.
* Currently, saldo on home page is showing value of first account of user. It should show saldo of user selected 'default' account.
* Check if API calls & websockets are properly authorized.
* Add synchronizing bank accounts saldo.
Expand Down
13 changes: 13 additions & 0 deletions app/Http/Controllers/Web/Transaction/PersonalAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use App\Models\Transaction\PersonalAccount;

class PersonalAccountController extends Controller
{
public function index(Request $request): View
{
$personalAccounts = PersonalAccount::whereUser($request->user())
->latest()
->withCount('transactions')
->get();

return view('personal_account.index', [
'personalAccounts' => $personalAccounts
]);
}

public function edit(Request $request): View
{
// @todo - handle editing multiplte personal account saldos
Expand Down
10 changes: 9 additions & 1 deletion app/Models/Transaction/PersonalAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@

namespace App\Models\Transaction;

use App\Models\Traits\BelongsToUser;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property mixed $value
* @method static whereUser(mixed $user)
*/
class PersonalAccount extends Model
{
use HasFactory;
use HasFactory, BelongsToUser;

protected $fillable = [
'user_id',
'value',
'name'
];

public function transactions(): HasMany
{
return $this->hasMany(Transaction::class);
}
}
1 change: 1 addition & 0 deletions app/Models/Transaction/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Transaction extends Model
'receiver_account_number',
'sender_account_number',
'receiver_persona_id',
'personal_account_id',
'calculation_volume',
'sender_persona_id',
'transaction_date',
Expand Down
3 changes: 3 additions & 0 deletions resources/views/icons/sm/accounts.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg data-slot="icon" fill="none" width="20" height="20" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 6.878V6a2.25 2.25 0 0 1 2.25-2.25h7.5A2.25 2.25 0 0 1 18 6v.878m-12 0c.235-.083.487-.128.75-.128h10.5c.263 0 .515.045.75.128m-12 0A2.25 2.25 0 0 0 4.5 9v.878m13.5-3A2.25 2.25 0 0 1 19.5 9v.878m0 0a2.246 2.246 0 0 0-.75-.128H5.25c-.263 0-.515.045-.75.128m15 0A2.25 2.25 0 0 1 21 12v6a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 18v-6c0-.98.626-1.813 1.5-2.122"></path>
</svg>
6 changes: 6 additions & 0 deletions resources/views/layouts/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class="inline-flex items-center px-3 py-2 border border-transparent text-sm lead
</div>
{{ __('All transactions') }}
</x-dropdown-link>
<x-dropdown-link class="navLink" :href="route('personal-account.index')">
<div class="mr-2">
@include('icons.sm.accounts')
</div>
{{ __('Personal accounts') }}
</x-dropdown-link>
@if(config('personas.enabled'))
<x-dropdown-link class="navLink" :href="route('persona.index')">
<span class="flex items-center justify-between">
Expand Down
9 changes: 9 additions & 0 deletions resources/views/personal_account/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<x-app-layout>
<div class="py-12">
<div class="w-full mx-auto sm:px-6 lg:px-8">

@include('personal_account.partials.personal-accounts-list', ['personalAccounts' => $personalAccounts])

</div>
</div>
</x-app-layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@if(count($personalAccounts) > 0)
<div class="p-4">
<h2 class="text-3xl font-bold mb-4">{{ __('Personal accounts') }}</h2>
<table class="min-w-full divide-y divide-gray-200">
<thead>
<tr class="bg-gray-200">
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{{ __('Name') }}
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{{ __('Transactions count') }}
</th>
<th class="px-6 py-3 bg-gray-50 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{{ __('Created at') }}
</th>
</tr>
</thead>
<tbody>
@foreach ($personalAccounts as $personalAccount)
<tr class="divide-y divide-gray-200">
<td class="px-4 py-2">
{{ $personalAccount->name }}
</td>
<td class="px-4 py-2">
{{ $personalAccount->transactions_count }}
</td>
<td class="px-4 py-2">{{ $personalAccount->created_at->format('d.m.Y H:i') }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<h2 class="font-semibold text-2xl">{{ __('No personal accounts') }}</h2>
@endif
1 change: 1 addition & 0 deletions routes/web/personal_accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Illuminate\Support\Facades\Route;

Route::prefix('personal-accounts')->as('personal-account.')->group(function () {
Route::get('/', [PersonalAccountController::class, 'index'])->name('index');
Route::get('/edit', [PersonalAccountController::class, 'edit'])->name('edit');
Route::put('/update', [PersonalAccountController::class, 'update'])->name('update');
});

0 comments on commit b05d9cb

Please sign in to comment.