feat: MCP profile tools; ProfileUpdater/ProfilePresenter shared with /me; docs and Caddy snippet for /mcp
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
42
core/app/Users/ProfileUpdater.php
Normal file
42
core/app/Users/ProfileUpdater.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Users;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/** Правка профиля — пояс и тихие часы; правила одни для инбокса и агента. */
|
||||
final class ProfileUpdater
|
||||
{
|
||||
/**
|
||||
* @param array<string,mixed> $input любое подмножество tz, quiet_start, quiet_end (HH:MM)
|
||||
*
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function update(User $user, array $input): User
|
||||
{
|
||||
$data = Validator::validate($input, [
|
||||
'tz' => ['sometimes', 'string', Rule::in(\DateTimeZone::listIdentifiers())],
|
||||
'quiet_start' => ['sometimes', 'date_format:H:i'],
|
||||
'quiet_end' => ['sometimes', 'date_format:H:i'],
|
||||
]);
|
||||
|
||||
$start = $data['quiet_start'] ?? substr($user->quiet_start, 0, 5);
|
||||
$end = $data['quiet_end'] ?? substr($user->quiet_end, 0, 5);
|
||||
if ($end >= $start) {
|
||||
throw ValidationException::withMessages([
|
||||
'quiet_end' => 'Тихие часы должны переходить через полночь: quiet_end раньше quiet_start',
|
||||
]);
|
||||
}
|
||||
|
||||
$user->fill([
|
||||
'tz' => $data['tz'] ?? $user->tz,
|
||||
'quiet_start' => $start.':00',
|
||||
'quiet_end' => $end.':00',
|
||||
])->save();
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user