feat: implement Presentation layer for GET /api/v1/user/me / ログイン中ユーザー取得APIのPresentation層実装#543
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat-user-me-api #543 +/- ##
======================================================
+ Coverage 62.21% 62.51% +0.30%
- Complexity 1604 1615 +11
======================================================
Files 135 136 +1
Lines 8252 8329 +77
======================================================
+ Hits 5134 5207 +73
- Misses 3118 3122 +4
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / 目的
AuthController::loginのレスポンスはトークンのみでユーザーのidを返さないため、フロントエンドはログイン後に「自分自身」の情報を取得する手段を持っていなかった(#542)。これがマイページ表示ができない一因だった。The login response only returns a token, never the user's id, so the frontend had no way to fetch "its own" user data after logging in (#542). This was one of the causes preventing mypage from displaying.
Domain層・Infra層は既存の
findByIdをそのまま利用でき、Application層も既存のGetUserByIdUseCaseをそのまま流用できるため、変更が必要だったのはPresentation層のみ。Domain and Infra layers already have
findByIdimplemented, and the Application layer can reuse the existingGetUserByIdUseCaseas-is, so only the Presentation layer required changes.Closes #542
What I have done / 実施内容
routes/api.phpにGET /v1/user/meをauth:sanctumミドルウェア付きで追加AuthController::meを追加し、$request->user()->id(Sanctumが認証セッション/トークンから解決した現在のユーザーのid)を既存のGetUserByIdUseCaseに渡して結果を返すUserViewModelFactory/UserViewModelをそのまま再利用してレスポンスを整形Test Results / テスト結果
test_me_returns_200_with_authenticated_user_when_authenticatedtest_me_returns_401_when_unauthenticatedtest_me_returns_500_on_unexpected_errorLoginTest/LogoutTestも回帰なしを確認済み