refactor: single EventPresenter and ManualEvents shared by /api, /me, inbox, webhook; editable flag

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
nikita.hohlov
2026-09-05 06:01:55 -03:00
parent 2ec71ab710
commit 9163ff97f9
10 changed files with 297 additions and 75 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Enums\EventState;
use Carbon\CarbonImmutable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -20,6 +21,20 @@ class User extends Model
return $this->hasMany(Event::class);
}
/** Событие пользователя по id; чужой id — «не найдено», а не 403. */
public function ownEvent(int $id): Event
{
return $this->events()->with('source')->whereKey($id)->firstOrFail();
}
/** Закрытые события для архива: done и expired, свежие первыми, не больше 100. */
public function archive(): HasMany
{
return $this->events()->with('source')
->whereIn('state', [EventState::Done->value, EventState::Expired->value])
->orderByDesc('updated_at')->limit(100);
}
/** «Сейчас» в поясе пользователя. */
public function now(): CarbonImmutable
{