Skip to content

Commit

Permalink
Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ucan-lab committed Jun 30, 2023
1 parent 06cce5a commit 94f5358
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Acme\Application\ShowUserProfile\ShowUserProfileUseCase;
use Acme\Application\ShowUserProfile\ShowUserProfileUseCaseInput;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;

final class ProfileController extends Controller
{
public function __invoke(ShowUserProfileUseCase $useCase): View
{
/** @var User $user */
$user = Auth::user();
$input = new ShowUserProfileUseCaseInput($user->username);
$output = $useCase->show($input);

return view('profile', [
'username' => $output->username,
'email' => $output->email,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Acme\Application\ShowUserProfile;

use Acme\Domain\User\Username;
use Acme\Domain\User\UserRepository;

final class ShowUserProfileUseCase
{
public function __construct(private UserRepository $userRepository)
{
}

public function show(ShowUserProfileUseCaseInput $input): ShowUserProfileUseCaseOutput
{
$username = new Username($input->username);
$authUser = $this->userRepository->findByUsername($username);

return new ShowUserProfileUseCaseOutput($authUser->username(), $authUser->email());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Acme\Application\ShowUserProfile;

final readonly class ShowUserProfileUseCaseInput
{
public function __construct(public string $username)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Acme\Application\ShowUserProfile;

final readonly class ShowUserProfileUseCaseOutput
{
public function __construct(
public string $username,
public string $email,
) {
}
}
14 changes: 14 additions & 0 deletions src/resources/views/profile.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@extends('layouts.app')

@section('title', 'プロフィール')

@section('content')
<h1>プロフィール</h1>

<ul>
<li>ユーザー名: {{ $username }}</li>
<li>メールアドレス: {{ $email }}</li>
</ul>

<p><a href="{{ route('dashboard') }}">ダッシュボードへ戻る</a></p>
@endsection
2 changes: 2 additions & 0 deletions src/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Http\Controllers\LoginController;
use App\Http\Controllers\LogoutController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RegisterController;
use Illuminate\Support\Facades\Route;

Expand All @@ -28,5 +29,6 @@

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

0 comments on commit 94f5358

Please sign in to comment.