v7.0.0-beta.2 release
This commit is contained in:
1 parent
6595fd0eb5
commit
fa8eba7a0d
1165 files changed
+107118
-762127
No files matched your search
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\MailSendLogRepositoryInterface;
|
||||
use App\Enums\MailSendStatus;
|
||||
use App\Models\MailSendLog;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* 메일 발송 이력 리포지토리 구현체
|
||||
*/
|
||||
class MailSendLogRepository implements MailSendLogRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* 발송 이력을 생성합니다.
|
||||
*
|
||||
* @param array $data 생성 데이터
|
||||
* @return MailSendLog 생성된 발송 이력 모델
|
||||
*/
|
||||
public function create(array $data): MailSendLog
|
||||
{
|
||||
return MailSendLog::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 발송 이력 목록을 페이지네이션하여 조회합니다.
|
||||
*
|
||||
* @param array $filters 필터 조건
|
||||
* @param int $perPage 페이지 당 항목 수
|
||||
* @return LengthAwarePaginator 페이지네이션 결과
|
||||
*/
|
||||
public function getPaginated(array $filters = [], int $perPage = 20): LengthAwarePaginator
|
||||
{
|
||||
$sortBy = $filters['sort_by'] ?? 'sent_at';
|
||||
$sortOrder = $filters['sort_order'] ?? 'desc';
|
||||
$query = MailSendLog::query()->orderBy($sortBy, $sortOrder);
|
||||
|
||||
if (! empty($filters['extension_type'])) {
|
||||
$types = is_array($filters['extension_type']) ? $filters['extension_type'] : [$filters['extension_type']];
|
||||
$query->whereIn('extension_type', $types);
|
||||
}
|
||||
|
||||
if (! empty($filters['extension_identifier'])) {
|
||||
$identifiers = is_array($filters['extension_identifier']) ? $filters['extension_identifier'] : [$filters['extension_identifier']];
|
||||
$query->whereIn('extension_identifier', $identifiers);
|
||||
}
|
||||
|
||||
if (! empty($filters['template_type'])) {
|
||||
$query->where('template_type', $filters['template_type']);
|
||||
}
|
||||
|
||||
if (! empty($filters['status'])) {
|
||||
$statuses = is_array($filters['status']) ? $filters['status'] : [$filters['status']];
|
||||
$query->whereIn('status', $statuses);
|
||||
}
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$searchType = $filters['search_type'] ?? 'all';
|
||||
$query->where(function ($q) use ($search, $searchType) {
|
||||
if ($searchType === 'recipient_email') {
|
||||
$q->where('recipient_email', 'like', "%{$search}%");
|
||||
} elseif ($searchType === 'recipient_name') {
|
||||
$q->where('recipient_name', 'like', "%{$search}%");
|
||||
} elseif ($searchType === 'subject') {
|
||||
$q->where('subject', 'like', "%{$search}%");
|
||||
} else {
|
||||
$q->where('recipient_email', 'like', "%{$search}%")
|
||||
->orWhere('recipient_name', 'like', "%{$search}%")
|
||||
->orWhere('subject', 'like', "%{$search}%");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (! empty($filters['date_from'])) {
|
||||
$query->where('sent_at', '>=', Carbon::parse($filters['date_from'])->startOfDay());
|
||||
}
|
||||
|
||||
if (! empty($filters['date_to'])) {
|
||||
$query->where('sent_at', '<=', Carbon::parse($filters['date_to'])->endOfDay());
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 발송 통계를 조회합니다.
|
||||
*
|
||||
* @return array{total: int, sent: int, failed: int, today: int} 통계 정보
|
||||
*/
|
||||
public function getStatistics(): array
|
||||
{
|
||||
return [
|
||||
'total' => MailSendLog::count(),
|
||||
'sent' => MailSendLog::where('status', MailSendStatus::Sent->value)->count(),
|
||||
'failed' => MailSendLog::where('status', MailSendStatus::Failed->value)->count(),
|
||||
'today' => MailSendLog::whereDate('sent_at', Carbon::today())->count(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 발송 이력을 삭제합니다.
|
||||
*
|
||||
* @param int $id 삭제할 발송 이력 ID
|
||||
* @return bool 삭제 성공 여부
|
||||
*/
|
||||
public function delete(int $id): bool
|
||||
{
|
||||
return MailSendLog::where('id', $id)->delete() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 여러 발송 이력을 일괄 삭제합니다.
|
||||
*
|
||||
* @param array<int> $ids 삭제할 발송 이력 ID 목록
|
||||
* @return int 삭제된 건수
|
||||
*/
|
||||
public function deleteMany(array $ids): int
|
||||
{
|
||||
return MailSendLog::whereIn('id', $ids)->delete();
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\MailTemplateRepositoryInterface;
|
||||
use App\Models\MailTemplate;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
/**
|
||||
* 메일 템플릿 리포지토리 구현체
|
||||
*
|
||||
* 메일 템플릿의 조회, 수정 등 데이터 접근 로직을 처리합니다.
|
||||
*/
|
||||
class MailTemplateRepository implements MailTemplateRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* ID로 메일 템플릿을 찾습니다.
|
||||
*
|
||||
* @param int $id 메일 템플릿 ID
|
||||
* @return MailTemplate|null 찾은 모델 또는 null
|
||||
*/
|
||||
public function findById(int $id): ?MailTemplate
|
||||
{
|
||||
return MailTemplate::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 유형으로 메일 템플릿을 찾습니다.
|
||||
*
|
||||
* @param string $type 템플릿 유형
|
||||
* @return MailTemplate|null 찾은 모델 또는 null
|
||||
*/
|
||||
public function findByType(string $type): ?MailTemplate
|
||||
{
|
||||
return MailTemplate::where('type', $type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 상태인 특정 유형 템플릿을 찾습니다.
|
||||
*
|
||||
* @param string $type 템플릿 유형
|
||||
* @return MailTemplate|null 활성 템플릿 또는 null
|
||||
*/
|
||||
public function getActiveByType(string $type): ?MailTemplate
|
||||
{
|
||||
return MailTemplate::active()->byType($type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 메일 템플릿 목록을 반환합니다.
|
||||
*
|
||||
* @return Collection 메일 템플릿 컬렉션
|
||||
*/
|
||||
public function getAllTemplates(): Collection
|
||||
{
|
||||
return MailTemplate::orderBy('id')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿을 수정합니다.
|
||||
*
|
||||
* @param MailTemplate $template 수정 대상
|
||||
* @param array $data 수정 데이터
|
||||
* @return bool 수정 성공 여부
|
||||
*/
|
||||
public function update(MailTemplate $template, array $data): bool
|
||||
{
|
||||
return $template->update($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 메일 템플릿 목록을 페이지네이션하여 조회합니다.
|
||||
*
|
||||
* @param array $filters 필터 조건
|
||||
* @param int $perPage 페이지 당 항목 수
|
||||
* @return LengthAwarePaginator 페이지네이션 결과
|
||||
*/
|
||||
public function getPaginated(array $filters = [], int $perPage = 20): LengthAwarePaginator
|
||||
{
|
||||
$sortBy = $filters['sort_by'] ?? 'id';
|
||||
$sortOrder = $filters['sort_order'] ?? 'asc';
|
||||
$query = MailTemplate::query()->orderBy($sortBy, $sortOrder);
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$searchType = $filters['search_type'] ?? 'all';
|
||||
$query->where(function ($q) use ($search, $searchType) {
|
||||
$locales = config('app.supported_locales', ['ko', 'en']);
|
||||
|
||||
if ($searchType === 'subject' || $searchType === 'all') {
|
||||
foreach ($locales as $locale) {
|
||||
$q->orWhere("subject->{$locale}", 'like', "%{$search}%");
|
||||
}
|
||||
}
|
||||
|
||||
if ($searchType === 'body' || $searchType === 'all') {
|
||||
foreach ($locales as $locale) {
|
||||
$q->orWhere("body->{$locale}", 'like', "%{$search}%");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\NotificationDefinitionRepositoryInterface;
|
||||
use App\Models\NotificationDefinition;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class NotificationDefinitionRepository implements NotificationDefinitionRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* ID로 알림 정의 조회.
|
||||
*
|
||||
* @param int $id
|
||||
* @return NotificationDefinition|null
|
||||
*/
|
||||
public function findById(int $id): ?NotificationDefinition
|
||||
{
|
||||
return NotificationDefinition::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 타입으로 알림 정의 조회.
|
||||
*
|
||||
* @param string $type
|
||||
* @return NotificationDefinition|null
|
||||
*/
|
||||
public function findByType(string $type): ?NotificationDefinition
|
||||
{
|
||||
return NotificationDefinition::byType($type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 상태인 특정 타입 알림 정의 조회.
|
||||
*
|
||||
* @param string $type
|
||||
* @return NotificationDefinition|null
|
||||
*/
|
||||
public function getActiveByType(string $type): ?NotificationDefinition
|
||||
{
|
||||
return NotificationDefinition::active()->byType($type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 모든 활성 알림 정의 조회.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAllActive(): Collection
|
||||
{
|
||||
return NotificationDefinition::active()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 활성 알림 정의의 로케일별 라벨 맵을 반환합니다.
|
||||
*
|
||||
* 알림 목록 응답에서 N+1 회피 목적으로 한 번 호출하여 [type => label] 맵을 생성합니다.
|
||||
* 라벨 fallback 우선순위: 사용자 로케일 → ko → en → type 식별자
|
||||
*
|
||||
* @param string|null $locale 사용자 로케일 (null이면 app()->getLocale())
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getLabelMap(?string $locale = null): array
|
||||
{
|
||||
$locale = $locale ?? app()->getLocale();
|
||||
|
||||
return NotificationDefinition::active()
|
||||
->get(['type', 'name'])
|
||||
->mapWithKeys(fn (NotificationDefinition $def) => [
|
||||
$def->type => $def->getLocalizedName($locale),
|
||||
])
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 전체 알림 정의 목록 조회.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return NotificationDefinition::all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 확장의 알림 정의 목록 조회.
|
||||
*
|
||||
* @param string $extensionType
|
||||
* @param string $extensionIdentifier
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByExtension(string $extensionType, string $extensionIdentifier): Collection
|
||||
{
|
||||
return NotificationDefinition::byExtension($extensionType, $extensionIdentifier)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 정의 수정.
|
||||
*
|
||||
* @param NotificationDefinition $definition
|
||||
* @param array $data
|
||||
* @return NotificationDefinition
|
||||
*/
|
||||
public function update(NotificationDefinition $definition, array $data): NotificationDefinition
|
||||
{
|
||||
$definition->update($data);
|
||||
|
||||
return $definition->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 페이지네이션 목록 조회.
|
||||
*
|
||||
* @param array $filters
|
||||
* @param int $perPage
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getPaginated(array $filters = [], int $perPage = 20): LengthAwarePaginator
|
||||
{
|
||||
$query = NotificationDefinition::with('templates');
|
||||
|
||||
if (! empty($filters['extension_type'])) {
|
||||
$query->where('extension_type', $filters['extension_type']);
|
||||
}
|
||||
|
||||
if (! empty($filters['extension_identifier'])) {
|
||||
$query->where('extension_identifier', $filters['extension_identifier']);
|
||||
}
|
||||
|
||||
if (isset($filters['is_active'])) {
|
||||
$query->where('is_active', $filters['is_active']);
|
||||
}
|
||||
|
||||
if (! empty($filters['channel'])) {
|
||||
$query->whereJsonContains('channels', $filters['channel']);
|
||||
}
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$locales = config('app.supported_locales', ['ko', 'en']);
|
||||
|
||||
$query->where(function ($q) use ($search, $locales) {
|
||||
$q->where('type', 'like', "%{$search}%");
|
||||
foreach ($locales as $locale) {
|
||||
$q->orWhere("name->{$locale}", 'like', "%{$search}%");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$sortBy = $filters['sort_by'] ?? 'id';
|
||||
$sortOrder = $filters['sort_order'] ?? 'asc';
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\NotificationLogRepositoryInterface;
|
||||
use App\Enums\NotificationLogStatus;
|
||||
use App\Models\NotificationLog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class NotificationLogRepository implements NotificationLogRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* ID로 알림 로그 조회.
|
||||
*/
|
||||
public function findById(int $id): ?NotificationLog
|
||||
{
|
||||
return NotificationLog::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 로그 생성.
|
||||
*/
|
||||
public function create(array $data): NotificationLog
|
||||
{
|
||||
return NotificationLog::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 로그 삭제.
|
||||
*/
|
||||
public function delete(NotificationLog $log): bool
|
||||
{
|
||||
return (bool) $log->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 다건 삭제.
|
||||
*/
|
||||
public function bulkDelete(array $ids): int
|
||||
{
|
||||
return NotificationLog::whereIn('id', $ids)->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 페이지네이션 목록 조회.
|
||||
*/
|
||||
public function getPaginated(array $filters = [], int $perPage = 20, ?User $scopeUser = null): LengthAwarePaginator
|
||||
{
|
||||
$query = NotificationLog::with(['senderUser', 'recipientUser']);
|
||||
|
||||
// notification-logs scope: 전달된 사용자의 권한 스코프 적용
|
||||
if ($scopeUser) {
|
||||
$this->applyNotificationLogScope($query, $scopeUser);
|
||||
}
|
||||
|
||||
if (! empty($filters['sender_user_id'])) {
|
||||
$query->where('sender_user_id', $filters['sender_user_id']);
|
||||
}
|
||||
|
||||
if (! empty($filters['recipient_user_id'])) {
|
||||
$query->where('recipient_user_id', $filters['recipient_user_id']);
|
||||
}
|
||||
|
||||
if (! empty($filters['channel'])) {
|
||||
$query->byChannel($filters['channel']);
|
||||
}
|
||||
|
||||
if (! empty($filters['notification_type'])) {
|
||||
$query->byNotificationType($filters['notification_type']);
|
||||
}
|
||||
|
||||
if (! empty($filters['status'])) {
|
||||
$status = NotificationLogStatus::tryFrom($filters['status']);
|
||||
if ($status) {
|
||||
$query->byStatus($status);
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($filters['extension_type'])) {
|
||||
$query->where('extension_type', $filters['extension_type']);
|
||||
}
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('recipient_name', 'like', "%{$search}%")
|
||||
->orWhere('recipient_identifier', 'like', "%{$search}%")
|
||||
->orWhere('subject', 'like', "%{$search}%")
|
||||
->orWhere('notification_type', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$sortBy = $filters['sort_by'] ?? 'sent_at';
|
||||
$sortOrder = $filters['sort_order'] ?? 'desc';
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* notification-logs 전용 스코프를 적용합니다.
|
||||
*
|
||||
* self 스코프: 본인이 발송했거나 수신한 알림 이력만 조회
|
||||
*/
|
||||
private function applyNotificationLogScope(Builder $query, User $user): void
|
||||
{
|
||||
$effectiveScope = $user->getEffectiveScopeForPermission('core.notification-logs.read');
|
||||
|
||||
if ($effectiveScope === null) {
|
||||
return; // 전체 접근
|
||||
}
|
||||
|
||||
if ($effectiveScope === 'self') {
|
||||
$query->where(function (Builder $q) use ($user) {
|
||||
$q->where('sender_user_id', $user->id)
|
||||
->orWhere('recipient_user_id', $user->id);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\NotificationRepositoryInterface;
|
||||
use App\Models\User;
|
||||
use Illuminate\Notifications\DatabaseNotification;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
|
||||
class NotificationRepository implements NotificationRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* 사용자의 알림 목록을 페이지네이션으로 조회합니다.
|
||||
*/
|
||||
public function getByUser(User $user, array $filters = [], int $perPage = 20): LengthAwarePaginator
|
||||
{
|
||||
$query = $user->notifications();
|
||||
|
||||
if (isset($filters['read']) && $filters['read'] === 'unread') {
|
||||
$query->whereNull('read_at');
|
||||
} elseif (isset($filters['read']) && $filters['read'] === 'read') {
|
||||
$query->whereNotNull('read_at');
|
||||
}
|
||||
|
||||
return $query->orderBy('created_at', 'desc')->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자의 미읽음 알림 수를 반환합니다.
|
||||
*/
|
||||
public function getUnreadCount(User $user): int
|
||||
{
|
||||
return $user->unreadNotifications()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 알림을 읽음 처리합니다.
|
||||
*/
|
||||
public function markAsRead(User $user, string $notificationId): ?DatabaseNotification
|
||||
{
|
||||
$notification = $user->notifications()->find($notificationId);
|
||||
|
||||
if (! $notification) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$notification->markAsRead();
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
/**
|
||||
* 지정된 알림들을 일괄 읽음 처리합니다.
|
||||
*/
|
||||
public function markBatchAsRead(User $user, array $ids): int
|
||||
{
|
||||
return $user->unreadNotifications()
|
||||
->whereIn('id', $ids)
|
||||
->update(['read_at' => now()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자의 모든 미읽음 알림을 읽음 처리합니다.
|
||||
*/
|
||||
public function markAllAsRead(User $user): int
|
||||
{
|
||||
$count = $user->unreadNotifications()->count();
|
||||
|
||||
$user->unreadNotifications->markAsRead();
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림을 삭제합니다.
|
||||
*/
|
||||
public function delete(User $user, string $notificationId): bool
|
||||
{
|
||||
$notification = $user->notifications()->find($notificationId);
|
||||
|
||||
if (! $notification) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $notification->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용자의 모든 알림을 삭제합니다.
|
||||
*
|
||||
* @param User $user
|
||||
* @return int 삭제된 알림 수
|
||||
*/
|
||||
public function deleteAll(User $user): int
|
||||
{
|
||||
return $user->notifications()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 오래된 알림을 정리합니다.
|
||||
*
|
||||
* @return array{deleted_read: int, deleted_unread: int}
|
||||
*/
|
||||
public function cleanup(int $readRetentionDays, int $unreadRetentionDays): array
|
||||
{
|
||||
$deletedRead = 0;
|
||||
$deletedUnread = 0;
|
||||
|
||||
if ($readRetentionDays > 0) {
|
||||
$deletedRead = DatabaseNotification::whereNotNull('read_at')
|
||||
->where('read_at', '<', now()->subDays($readRetentionDays))
|
||||
->delete();
|
||||
}
|
||||
|
||||
if ($unreadRetentionDays > 0) {
|
||||
$deletedUnread = DatabaseNotification::whereNull('read_at')
|
||||
->where('created_at', '<', now()->subDays($unreadRetentionDays))
|
||||
->delete();
|
||||
}
|
||||
|
||||
return [
|
||||
'deleted_read' => $deletedRead,
|
||||
'deleted_unread' => $deletedUnread,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Contracts\Repositories\NotificationTemplateRepositoryInterface;
|
||||
use App\Models\NotificationDefinition;
|
||||
use App\Models\NotificationTemplate;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class NotificationTemplateRepository implements NotificationTemplateRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* ID로 알림 템플릿 조회.
|
||||
*
|
||||
* @param int $id
|
||||
* @return NotificationTemplate|null
|
||||
*/
|
||||
public function findById(int $id): ?NotificationTemplate
|
||||
{
|
||||
return NotificationTemplate::find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 정의 ID + 채널로 템플릿 조회.
|
||||
*
|
||||
* @param int $definitionId
|
||||
* @param string $channel
|
||||
* @return NotificationTemplate|null
|
||||
*/
|
||||
public function findByDefinitionAndChannel(int $definitionId, string $channel): ?NotificationTemplate
|
||||
{
|
||||
return NotificationTemplate::where('definition_id', $definitionId)
|
||||
->byChannel($channel)
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 알림 타입 + 채널로 활성 템플릿 조회.
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $channel
|
||||
* @return NotificationTemplate|null
|
||||
*/
|
||||
public function getActiveByTypeAndChannel(string $type, string $channel): ?NotificationTemplate
|
||||
{
|
||||
return NotificationTemplate::active()
|
||||
->byChannel($channel)
|
||||
->whereHas('definition', function ($query) use ($type) {
|
||||
$query->byType($type)->active();
|
||||
})
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 특정 알림 정의의 모든 템플릿 조회.
|
||||
*
|
||||
* @param int $definitionId
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByDefinitionId(int $definitionId): Collection
|
||||
{
|
||||
return NotificationTemplate::where('definition_id', $definitionId)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 템플릿 수정.
|
||||
*
|
||||
* @param NotificationTemplate $template
|
||||
* @param array $data
|
||||
* @return NotificationTemplate
|
||||
*/
|
||||
public function update(NotificationTemplate $template, array $data): NotificationTemplate
|
||||
{
|
||||
$template->update($data);
|
||||
|
||||
return $template->fresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 템플릿 생성 또는 수정.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $values
|
||||
* @return NotificationTemplate
|
||||
*/
|
||||
public function updateOrCreate(array $attributes, array $values): NotificationTemplate
|
||||
{
|
||||
return NotificationTemplate::updateOrCreate($attributes, $values);
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,20 @@ class RoleRepository implements RoleRepositoryInterface
|
||||
->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* 확장이 소유한 모든 역할을 조회합니다.
|
||||
*
|
||||
* @param ExtensionOwnerType $extensionType 확장 타입
|
||||
* @param string $extensionIdentifier 확장 식별자
|
||||
* @return Collection 해당 확장 소유 역할 컬렉션
|
||||
*/
|
||||
public function getByExtension(ExtensionOwnerType $extensionType, string $extensionIdentifier): Collection
|
||||
{
|
||||
return Role::where('extension_type', $extensionType)
|
||||
->where('extension_identifier', $extensionIdentifier)
|
||||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 역할에 권한을 할당합니다.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user