Skip to content

feat: implement Login API across all layers / ユーザーログインAPIの全層実装#535

Merged
zigzagdev merged 32 commits into
feat/userfrom
feat/user-login
Jul 14, 2026
Merged

feat: implement Login API across all layers / ユーザーログインAPIの全層実装#535
zigzagdev merged 32 commits into
feat/userfrom
feat/user-login

Conversation

@zigzagdev

Copy link
Copy Markdown
Owner

Motivation / 目的

Implement POST /api/v1/user/login API using Laravel Sanctum for token-based authentication.
Each layer was developed on its own branch and merged in sequence.

ユーザーログイン機能(POST /api/v1/user/login)を実装しました。
Laravel Sanctum を用いたトークン認証を採用し、DDD の各層を個別ブランチで実装して順次マージしています。


What I have done / 実施内容

Domain Layer

  • Added Email Value Object (App\Packages\Domains\User\ValueObject\Email)
  • Added findByEmail to UserRepositroyInterface
  • Refactored UserEntity and UserEntityFactory to use Email VO
  • Added TokenServiceInterface (createToken, revokeAllTokens)

Infra Layer

  • Installed laravel/sanctum and published config (expiration: 1440 min = 1 day)
  • Added personal_access_tokens migration
  • Added HasApiTokens trait to User model
  • Implemented SanctumTokenService (resolves User Eloquent model from UserEntity and delegates to Sanctum)
  • Bound TokenServiceInterfaceSanctumTokenService in AppServiceProvider

Application Layer

  • Added AuthTokenDto (token: string, tokenType: string = 'Bearer')
  • Implemented LoginUseCase::handle(string $email, string $password): AuthTokenDto
    • findByEmail → entity null check → password_verifycreateToken
    • Password errors return InvalidArgumentException (→ 401)

Presentation Layer

  • Added AuthController::login with 200 / 401 / 500 response handling
  • Registered POST /v1/user/login route
  • Refactored routes/api.php using Route::controller()->prefix()->group() grouping
  • Added integration tests for all 3 HTTP paths (200, 401, 500)

Static Analysis (mago)

  • Added mago.toml with lint-based static analysis config (scoped to app/Packages)
  • Added .github/workflows/static_analysis.yml CI workflow (mago lint on PR)

Test Results / テスト結果

Integration Tests

  • LoginTest::test_login_returns_200_with_token_on_valid_credentials
  • LoginTest::test_login_returns_401_when_user_not_found
  • LoginTest::test_login_returns_401_on_wrong_password
  • LoginTest::test_login_returns_500_on_unexpected_error
  • SanctumTokenServiceTest::test_createToken_returns_plain_text_token
  • SanctumTokenServiceTest::test_createToken_throws_when_user_not_found
  • SanctumTokenServiceTest::test_revokeAllTokens_deletes_tokens_for_user
  • SanctumTokenServiceTest::test_revokeAllTokens_throws_when_user_not_found
  • UserRepositoryTest::test_findByEmail_returns_entity_when_email_matches
  • UserRepositoryTest::test_findByEmail_returns_null_when_email_not_found

Unit Tests

  • LoginUseCaseTest::test_handle_returns_auth_token_dto_on_valid_credentials
  • LoginUseCaseTest::test_handle_throws_when_user_not_found
  • LoginUseCaseTest::test_handle_throws_when_password_does_not_match

Closes #405

zigzagdev added 30 commits July 13, 2026 08:53
…ind-mail

feat: implement Email ValueObject and findByEmail in Infra layer / Email ValueObjectとfindByEmailのInfra層実装
…ken-service

feat: implement SanctumTokenService for token issuance and revocation / Sanctumトークン発行・失効のInfra層実装
feat: implement Application layer for User Login / ユーザーログインのApplication層実装
- Narrow source path to app/Packages only
- Disable false-positive rules: no-literal-password, no-empty, no-nested-ternary, prefer-first-class-callable, block-statement, class-name
- Raise cyclomatic-complexity threshold to 60, excessive-parameter-list to 25, too-many-methods to 30
…ayer

feat: implement Presentation layer for User Login and introduce mago lint / ユーザーログインのPresentation層実装とmago lint導入
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.75%. Comparing base (0ca7fd4) to head (e24f4c2).
⚠️ Report is 33 commits behind head on feat/user.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff               @@
##             feat/user     #535      +/-   ##
===============================================
+ Coverage        60.30%   61.75%   +1.45%     
- Complexity        1534     1585      +51     
===============================================
  Files              123      132       +9     
  Lines             7854     8153     +299     
===============================================
+ Hits              4736     5035     +299     
  Misses            3118     3118              
Files with missing lines Coverage Δ
src/app/Models/User.php 100.00% <ø> (ø)
...ackages/Domains/User/Factory/UserEntityFactory.php 100.00% <100.00%> (ø)
...kages/Domains/User/Service/SanctumTokenService.php 100.00% <100.00%> (ø)
...mains/User/Tests/Factory/UserEntityFactoryTest.php 100.00% <100.00%> (ø)
...ins/User/Tests/Service/SanctumTokenServiceTest.php 100.00% <100.00%> (ø)
...app/Packages/Domains/User/Tests/UserEntityTest.php 100.00% <100.00%> (ø)
...Packages/Domains/User/Tests/UserRepositoryTest.php 100.00% <100.00%> (ø)
...kages/Domains/User/Tests/ValueObject/EmailTest.php 100.00% <100.00%> (ø)
src/app/Packages/Domains/User/UserEntity.php 100.00% <100.00%> (ø)
src/app/Packages/Domains/User/UserRepository.php 98.11% <100.00%> (+0.67%) ⬆️
... and 7 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zigzagdev zigzagdev left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zigzagdev
zigzagdev merged commit 7ce1092 into feat/user Jul 14, 2026
27 checks passed
@zigzagdev
zigzagdev deleted the feat/user-login branch July 14, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User LogIn

1 participant