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:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user