Initial Version
This commit is contained in:
58
core/lib/Controllers/UserSettingsController.php
Normal file
58
core/lib/Controllers/UserSettingsController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?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 UserSettingsController extends ControllerAbstract
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SessionTenant $tenantIdentity,
|
||||
private readonly SessionIdentity $userIdentity,
|
||||
private readonly UserService $userService
|
||||
) {}
|
||||
|
||||
|
||||
/**
|
||||
* retrieve user settings
|
||||
*
|
||||
* @param array $settings list of settings to retrieve
|
||||
*
|
||||
* @example request body:
|
||||
* {
|
||||
* "settings": ["key1", "key2"]
|
||||
* }
|
||||
*/
|
||||
#[AuthenticatedRoute('/user/settings/read', name: 'user.settings.read', methods: ['PUT', 'PATCH'])]
|
||||
public function read(array $settings = []): JsonResponse
|
||||
{
|
||||
// authorize request
|
||||
$tenantId = $this->tenantIdentity->identifier();
|
||||
$userId = $this->userIdentity->identifier();
|
||||
|
||||
return $this->userService->fetchSettings($tenantId, $userId, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* store user settings
|
||||
*
|
||||
* @param array $settings key-value pairs of settings to store
|
||||
*
|
||||
* @example request body:
|
||||
* {
|
||||
* "key1": "value1",
|
||||
* "key2": "value2"
|
||||
* }
|
||||
*/
|
||||
#[AuthenticatedRoute('/user/settings/write', name: 'user.settings.write', methods: ['PUT', 'PATCH'])]
|
||||
public function write(array $settings): JsonResponse
|
||||
{
|
||||
return new JsonResponse(['status' => 'not_implemented'], JsonResponse::HTTP_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user