feat: action links, telegram webhook and channels API
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
39
core/app/Http/Controllers/ActionController.php
Normal file
39
core/app/Http/Controllers/ActionController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Delivery\EventActions;
|
||||
use App\Models\Delivery;
|
||||
use App\Models\Event;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/** Кнопки из каналов: подписанные ссылки по action_token доставки. Без SSO и CSRF. */
|
||||
class ActionController extends Controller
|
||||
{
|
||||
public function __construct(private readonly EventActions $actions) {}
|
||||
|
||||
public function ack(string $token): JsonResponse
|
||||
{
|
||||
$event = $this->eventFor($token);
|
||||
$this->actions->ack($event);
|
||||
|
||||
return response()->json(['state' => $event->fresh()->state->value]);
|
||||
}
|
||||
|
||||
public function done(string $token): JsonResponse
|
||||
{
|
||||
$event = $this->eventFor($token);
|
||||
$this->actions->done($event);
|
||||
|
||||
return response()->json(['state' => $event->fresh()->state->value]);
|
||||
}
|
||||
|
||||
private function eventFor(string $token): Event
|
||||
{
|
||||
$delivery = Delivery::where('action_token', $token)->with('event.user')->first();
|
||||
abort_if($delivery === null, 404, 'Неизвестный токен');
|
||||
abort_if($delivery->event->isTerminal(), 410, 'Событие уже закрыто');
|
||||
|
||||
return $delivery->event;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user