Skip to content

Commit 8807068

Browse files
teste
1 parent 9b450d3 commit 8807068

File tree

21 files changed

+609
-169
lines changed

21 files changed

+609
-169
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
6+
use App\Services\AccountService;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\Auth;
9+
use App\Models\User;
10+
11+
12+
class AccountController extends Controller
13+
{
14+
protected AccountService $accountService;
15+
16+
public function __construct(AccountService $accountService)
17+
{
18+
$this->accountService = $accountService;
19+
}
20+
21+
22+
public function dashboard(Request $request)
23+
{
24+
$apiKey = $request->api_key;
25+
26+
$saldo = $this->accountService->pegarSaldo([
27+
'apiKey' => $apiKey,
28+
]);
29+
30+
return view ('dashboard', [
31+
'saldo' => $saldo,
32+
'nome' => Auth::user()->name
33+
]);
34+
}
35+
36+
37+
}
38+
39+
//mudar nomes
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Auth;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Services\UserService;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Validation\Rules;
9+
use Illuminate\Support\Facades\Validator;
10+
11+
class RegisterController extends Controller
12+
{
13+
public function __construct(protected UserService $userService) {}
14+
15+
public function store(Request $request)
16+
{
17+
$validated = Validator::make($request->all(), [
18+
'name' => ['required', 'string', 'max:255'],
19+
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:users'],
20+
'cpfCnpj' => ['required', 'string', 'unique:users'],
21+
'birthDate' => ['required', 'date'],
22+
'mobilePhone' => ['required', 'string'],
23+
'incomeValue' => ['required', 'numeric'],
24+
'address' => ['required', 'string'],
25+
'addressNumber' => ['required', 'string'],
26+
'complement' => ['nullable', 'string'],
27+
'province' => ['required', 'string'],
28+
'postalCode' => ['required', 'string'],
29+
'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
30+
])->validate();
31+
32+
$this->userService->register($validated);
33+
34+
return redirect()->route('dashboard');
35+
}
36+
37+
}

app/Http/Controllers/BankController.php

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use App\Services\AccountService;
7+
8+
class PixController extends Controller
9+
{
10+
public function __construct(protected AccountService $accountService) {}
11+
12+
public function index(Request $request)
13+
{
14+
$apiKey = $request->api_key;
15+
16+
$rawSaldo = $this->accountService->pegarSaldo([
17+
'apiKey' => $apiKey,
18+
]);
19+
20+
$saldoFormatado = number_format($rawSaldo['balance'], 2, ',', '.');
21+
22+
return view('pix', [
23+
'saldo' => $saldoFormatado,
24+
]);
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
use Illuminate\Support\Facades\Auth;
9+
10+
11+
class CheckApiKey
12+
{
13+
/**
14+
* Handle an incoming request.
15+
*
16+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
17+
*/
18+
public function handle(Request $request, Closure $next): Response
19+
{
20+
$user = Auth::user();
21+
22+
if (!$user || !$user->apiKey) {
23+
return response()->json(['message' => 'Usuario não autenticado'], 403);
24+
}
25+
26+
$request->merge(['api_key' => $user->apiKey]);
27+
28+
return $next($request);
29+
}
30+
}

app/Models/User.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Notifications\Notifiable;
88
use Illuminate\Support\Str;
99

10+
1011
class User extends Authenticatable
1112
{
1213
use HasFactory, Notifiable;

app/Providers/AppServiceProvider.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
namespace App\Providers;
44

55
use Illuminate\Support\ServiceProvider;
6+
use App\Http\Middleware\CheckApiKey;
7+
use Illuminate\Support\Facades\Route;
8+
use App\Repositories\Contracts\UserRepositoryInterface;
9+
use App\Repositories\Eloquent\UserRepository;
610

711
class AppServiceProvider extends ServiceProvider
812
{
@@ -11,14 +15,18 @@ class AppServiceProvider extends ServiceProvider
1115
*/
1216
public function register(): void
1317
{
14-
//
18+
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
1519
}
1620

21+
22+
1723
/**
1824
* Bootstrap any application services.
1925
*/
2026
public function boot(): void
2127
{
22-
//
28+
Route::aliasMiddleware('check.apikey', CheckApiKey::class);
2329
}
30+
31+
2432
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Repositories\Contracts;
4+
5+
use App\Models\User;
6+
7+
interface UserRepositoryInterface
8+
{
9+
public function create(array $data): User;
10+
11+
public function findByEmail(string $email): ?User;
12+
13+
public function update(User $user, array $data): bool;
14+
15+
public function delete(User $user): bool;
16+
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Repositories\Eloquent;
4+
5+
use App\Models\User;
6+
use App\Repositories\Contracts\UserRepositoryInterface;
7+
8+
class UserRepository implements UserRepositoryInterface
9+
{
10+
public function create(array $data): User
11+
{
12+
return User::create($data);
13+
}
14+
15+
public function findByEmail(string $email): ?User
16+
{
17+
return User::where('email', $email)->first();
18+
}
19+
20+
public function update(User $user, array $data): bool
21+
{
22+
return $user->update($data);
23+
}
24+
25+
public function delete(User $user): bool
26+
{
27+
return $user->delete();
28+
}
29+
}

app/Services/AccountService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public function criarConta(array $dados)
2323
return $this->apiService->enviarRequisicao('accounts', $dados, 'POST');
2424
}
2525

26-
// public function pegarSaldo (array $dados)
27-
// {
28-
// return $this->apiService->enviarRequisicao('finance/balance', $dados, 'GET');
29-
// }
26+
public function pegarSaldo (array $dados)
27+
{
28+
return $this->apiService->enviarRequisicao('finance/balance', $dados, 'GET');
29+
}
3030

3131
//extrato
3232

0 commit comments

Comments
 (0)