Skip to content

Commit 94f5358

Browse files
committed
Profile
1 parent 06cce5a commit 94f5358

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Http\Controllers;
6+
7+
use Acme\Application\ShowUserProfile\ShowUserProfileUseCase;
8+
use Acme\Application\ShowUserProfile\ShowUserProfileUseCaseInput;
9+
use App\Models\User;
10+
use Illuminate\Contracts\View\View;
11+
use Illuminate\Support\Facades\Auth;
12+
13+
final class ProfileController extends Controller
14+
{
15+
public function __invoke(ShowUserProfileUseCase $useCase): View
16+
{
17+
/** @var User $user */
18+
$user = Auth::user();
19+
$input = new ShowUserProfileUseCaseInput($user->username);
20+
$output = $useCase->show($input);
21+
22+
return view('profile', [
23+
'username' => $output->username,
24+
'email' => $output->email,
25+
]);
26+
}
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Acme\Application\ShowUserProfile;
6+
7+
use Acme\Domain\User\Username;
8+
use Acme\Domain\User\UserRepository;
9+
10+
final class ShowUserProfileUseCase
11+
{
12+
public function __construct(private UserRepository $userRepository)
13+
{
14+
}
15+
16+
public function show(ShowUserProfileUseCaseInput $input): ShowUserProfileUseCaseOutput
17+
{
18+
$username = new Username($input->username);
19+
$authUser = $this->userRepository->findByUsername($username);
20+
21+
return new ShowUserProfileUseCaseOutput($authUser->username(), $authUser->email());
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Acme\Application\ShowUserProfile;
6+
7+
final readonly class ShowUserProfileUseCaseInput
8+
{
9+
public function __construct(public string $username)
10+
{
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Acme\Application\ShowUserProfile;
6+
7+
final readonly class ShowUserProfileUseCaseOutput
8+
{
9+
public function __construct(
10+
public string $username,
11+
public string $email,
12+
) {
13+
}
14+
}

src/resources/views/profile.blade.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@extends('layouts.app')
2+
3+
@section('title', 'プロフィール')
4+
5+
@section('content')
6+
<h1>プロフィール</h1>
7+
8+
<ul>
9+
<li>ユーザー名: {{ $username }}</li>
10+
<li>メールアドレス: {{ $email }}</li>
11+
</ul>
12+
13+
<p><a href="{{ route('dashboard') }}">ダッシュボードへ戻る</a></p>
14+
@endsection

src/routes/web.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Http\Controllers\LoginController;
66
use App\Http\Controllers\LogoutController;
7+
use App\Http\Controllers\ProfileController;
78
use App\Http\Controllers\RegisterController;
89
use Illuminate\Support\Facades\Route;
910

@@ -28,5 +29,6 @@
2829

2930
Route::group(['middleware' => 'auth'], static function () {
3031
Route::view('/dashboard', 'dashboard')->name('dashboard');
32+
Route::get('/profile', ProfileController::class)->name('profile');
3133
Route::post('/logout', LogoutController::class)->name('logout');
3234
});

0 commit comments

Comments
 (0)