global progress
This commit is contained in:
parent
8de72cf6bb
commit
1591b11308
|
@ -9,6 +9,7 @@
|
|||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
|
@ -28,11 +29,19 @@ public function store(Request $request): RedirectResponse
|
|||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => strtolower($request->email),
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
$user = DB::transaction(function () use ($request) {
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => strtolower($request->email),
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
$user->wallet()->create([
|
||||
'balance' => 0,
|
||||
]);
|
||||
|
||||
return $user;
|
||||
});
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
|
|
|
@ -10,6 +10,14 @@ class DashboardController
|
|||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$wallet = $request->user()->wallet;
|
||||
|
||||
// bouger cette partie dans un service ou un listener quand on aura le temps, ainsi que le même code dans l'inscription
|
||||
if (! $wallet) {
|
||||
$request->user()->wallet()->create(['balance' => 0]);
|
||||
$request->user()->load('wallet');
|
||||
}
|
||||
|
||||
$transactions = $request->user()->wallet->transactions()->with('transfer')->orderByDesc('id')->get();
|
||||
$balance = $request->user()->wallet->balance;
|
||||
|
||||
|
|
10
app/Models/RecuringTransfer.php
Executable file
10
app/Models/RecuringTransfer.php
Executable file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RecuringTransfer extends Model
|
||||
{
|
||||
//
|
||||
}
|
55
app/Notifications/WalletBalanceLowNotification.php
Executable file
55
app/Notifications/WalletBalanceLowNotification.php
Executable file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class WalletBalanceLowNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->line('Your balance of your wallet is low.')
|
||||
->action('see your dashboard', route('dashboard'))
|
||||
->line('Thank you for using our application!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
20
app/Observers/WalletObserver.php
Executable file
20
app/Observers/WalletObserver.php
Executable file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Wallet;
|
||||
use App\Notifications\WalletBalanceLowNotification;
|
||||
|
||||
class WalletObserver
|
||||
{
|
||||
public function updated(Wallet $wallet)
|
||||
{
|
||||
// todo mettre le montant dans un fichier de config / une constante ou autre
|
||||
// /!\ balance is in cents
|
||||
if ($wallet->getOriginal('balance') > $wallet->balance && $wallet->balance < 1000) {
|
||||
$wallet->user->notify(new WalletBalanceLowNotification($wallet));
|
||||
}
|
||||
}
|
||||
}
|
542
composer.lock
generated
542
composer.lock
generated
File diff suppressed because it is too large
Load Diff
27
database/migrations/2024_12_12_144934_create_recuring_transfers_table.php
Executable file
27
database/migrations/2024_12_12_144934_create_recuring_transfers_table.php
Executable file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('recuring_transfers', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('recuring_transfers');
|
||||
}
|
||||
};
|
2
package-lock.json
generated
Normal file → Executable file
2
package-lock.json
generated
Normal file → Executable file
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "test-tech-laravel-wallet",
|
||||
"name": "test-laravel-wallet",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
|
|
|
@ -23,6 +23,18 @@
|
|||
]);
|
||||
});
|
||||
|
||||
test('dashboard is accessible as new registered user', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = actingAs($user)->get('/');
|
||||
|
||||
$response->assertOk()->assertSeeTextInOrder([
|
||||
__('Balance'),
|
||||
Number::currencyCents(0),
|
||||
'Transactions history',
|
||||
]);
|
||||
});
|
||||
|
||||
test('send money to a friend', function () {
|
||||
$user = User::factory()->has(Wallet::factory()->richChillGuy())->create();
|
||||
$recipient = User::factory()->has(Wallet::factory())->create();
|
||||
|
|
Loading…
Reference in New Issue
Block a user