user auth, settings, profile
This commit is contained in:
63
core/lib/Controllers/UserProfileController.php
Normal file
63
core/lib/Controllers/UserProfileController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace KTXC\Controllers;
|
||||
|
||||
use KTXC\Http\Response\JsonResponse;
|
||||
use KTXC\Service\UserService;
|
||||
use KTXC\SessionIdentity;
|
||||
use KTXC\SessionTenant;
|
||||
use KTXF\Controller\ControllerAbstract;
|
||||
use KTXF\Routing\Attributes\AuthenticatedRoute;
|
||||
|
||||
class UserProfileController extends ControllerAbstract
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SessionTenant $tenantIdentity,
|
||||
private readonly SessionIdentity $userIdentity,
|
||||
private readonly UserService $userService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Retrieve user profile
|
||||
*
|
||||
* @return JsonResponse Profile data with editability metadata
|
||||
*/
|
||||
#[AuthenticatedRoute('/user/profile', name: 'user.profile.read', methods: ['GET'])]
|
||||
public function read(): JsonResponse
|
||||
{
|
||||
$userId = $this->userIdentity->identifier();
|
||||
|
||||
$profile = $this->userService->fetchProfile($userId);
|
||||
|
||||
return new JsonResponse($profile, JsonResponse::HTTP_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user profile fields
|
||||
* Only editable fields can be updated. Provider-managed fields are automatically filtered out.
|
||||
*
|
||||
* @param array $profile Key-value pairs of profile fields to update
|
||||
*
|
||||
* @example request body:
|
||||
* {
|
||||
* "name_given": "John",
|
||||
* "name_family": "Doe",
|
||||
* "phone": "+1234567890"
|
||||
* }
|
||||
*
|
||||
* @return JsonResponse Updated profile data
|
||||
*/
|
||||
#[AuthenticatedRoute('/user/profile', name: 'user.profile.update', methods: ['PUT', 'PATCH'])]
|
||||
public function update(array $profile = []): JsonResponse
|
||||
{
|
||||
$userId = $this->userIdentity->identifier();
|
||||
|
||||
// storeProfile automatically filters out provider-managed fields
|
||||
$this->userService->storeProfile($userId, $profile);
|
||||
|
||||
// Return updated profile
|
||||
$updatedProfile = $this->userService->fetchProfile($userId);
|
||||
|
||||
return new JsonResponse($updatedProfile, JsonResponse::HTTP_OK);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user