Skip to content

Conversation

@kevalyq
Copy link
Contributor

@kevalyq kevalyq commented Nov 16, 2025

Summary

Implements user language preference functionality to allow users to set their preferred UI language (English or German) in their profile.

Changes

Database

  • ✅ Add preferred_locale column to users table (VARCHAR(5), nullable)
  • ✅ Migration: 2025_11_16_192506_add_preferred_locale_to_users_table

API

  • ✅ New endpoint: PATCH /v1/me/language
  • ✅ Request validation via UpdateUserLanguageRequest
  • ✅ Supported locales: en (English), de (German), null (reset to default)
  • ✅ Controller method: AuthController@updateLanguage

Models

  • ✅ Update User model with preferred_locale in fillable
  • ✅ Update UserFactory to include preferred_locale
  • ✅ PHPDoc annotations updated

Tests

  • ✅ 8 comprehensive feature tests (TDD approach)
  • ✅ All 403 tests passing
  • ✅ PHPStan level max: 0 errors
  • ✅ Laravel Pint: Clean
  • ✅ REUSE 3.3: Compliant

Testing

# Run tests
ddev exec php artisan test --filter=UserLanguagePreferenceTest

# All tests
ddev exec php artisan test

# Static analysis
ddev exec vendor/bin/phpstan analyse --memory-limit=512M

# Code style
ddev exec vendor/bin/pint

Acceptance Criteria (from #86)

  • Database column preferred_locale added to users table
  • API endpoint PATCH /v1/me/language created
  • Validation: Only en, de, or null accepted
  • Empty string treated as null (reset preference)
  • Endpoint only updates authenticated user's preference
  • Unauthenticated requests return 401
  • Comprehensive test coverage (8 tests)

Documentation

  • ✅ CHANGELOG.md updated with new feature

Follow-up

Frontend implementation (#141) can now use this endpoint to persist user language preferences.

Closes #86

- Add preferred_locale column to users table (VARCHAR(5), nullable)
- Add PATCH /v1/me/language endpoint with validation
- Support for en (English) and de (German) locales
- Allow null to reset preference to default
- Update User model, factory, and AuthController
- Add UpdateUserLanguageRequest with validation rules
- Add 8 comprehensive feature tests (TDD approach)
- Update CHANGELOG.md

Fixes #86
Copilot AI review requested due to automatic review settings November 16, 2025 19:34
@github-actions
Copy link

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

Copilot finished reviewing on behalf of kevalyq November 16, 2025 19:35
@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements user language preference functionality allowing users to set and persist their preferred UI language (English or German) via a new API endpoint. The implementation follows TDD principles with comprehensive test coverage.

Key Changes

  • Database schema extended with preferred_locale column in the users table
  • New PATCH endpoint /v1/me/language for updating language preferences
  • Comprehensive validation ensuring only supported locales (en, de, or null) are accepted

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Feature/Controllers/Api/V1/UserLanguagePreferenceTest.php Adds 8 comprehensive feature tests covering happy paths, validation, and authentication
routes/api.php Registers new language preference endpoint in v1 API routes
database/migrations/2025_11_16_192506_add_preferred_locale_to_users_table.php Adds nullable preferred_locale column to users table
database/factories/UserFactory.php Updates factory to include preferred_locale with default null value
app/Models/User.php Adds preferred_locale to fillable array and PHPDoc annotations
app/Http/Requests/UpdateUserLanguageRequest.php Validates locale input using present, nullable, and Rule::in()
app/Http/Controllers/AuthController.php Implements updateLanguage() method to handle language preference updates
CHANGELOG.md Documents the new user language preference feature

- Add messages() method to UpdateUserLanguageRequest with custom error message
- Add @return JsonResponse annotation to AuthController::updateLanguage()
- Follow patterns from sibling Form Requests (TokenRequest, GrantShareRequest)

Addresses Copilot review comments in PR #186
- Remove @return JsonResponse annotation (already in method signature)
- Comply with no_superfluous_phpdoc_tags Pint rule
- Match pattern used in sibling methods (logout, logoutAll, me)

The return type is already declared in the method signature,
making the PHPDoc @return tag redundant per PSR-12 standards.
@kevalyq kevalyq merged commit ebccf1e into main Nov 16, 2025
17 checks passed
@kevalyq kevalyq deleted the feat/issue-86-user-language-preference branch November 16, 2025 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User Language Preference in Profile (Override Accept-Language Header)

2 participants