v7.0.0-beta.2 release

This commit is contained in:
HeuJung committed 2026-04-20 20:37:49 +09:00
1 parent 6595fd0eb5
commit fa8eba7a0d
1165 files changed
+107118 -762127

No files matched your search

+13 -4
View File
@@ -2,9 +2,7 @@
namespace App\Http\Resources;
use App\Http\Resources\Traits\HasRowNumber;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
/**
@@ -12,9 +10,17 @@ use Illuminate\Pagination\LengthAwarePaginator;
*
* 활동 로그 목록을 페이지네이션과 함께 반환합니다.
*/
class ActivityLogCollection extends ResourceCollection
class ActivityLogCollection extends BaseApiCollection
{
use HasRowNumber;
/**
* {@inheritDoc}
*/
protected function abilityMap(): array
{
return [
'can_delete' => 'core.activities.delete',
];
}
/**
* 활동 로그 컬렉션을 배열로 변환합니다.
@@ -24,6 +30,8 @@ class ActivityLogCollection extends ResourceCollection
*/
public function toArray(Request $request): array
{
$abilities = $this->resolveCollectionAbilities($request);
return [
'data' => $this->mapWithRowNumber(function ($activityLog) {
return (new ActivityLogResource($activityLog))->toArray(request());
@@ -37,6 +45,7 @@ class ActivityLogCollection extends ResourceCollection
'to' => $this->resource->lastItem(),
'has_more_pages' => $this->resource->hasMorePages(),
] : null,
...($abilities ? ['abilities' => $abilities] : []),
];
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace App\Http\Resources;
use App\Helpers\PermissionHelper;
use App\Http\Resources\Traits\HasRowNumber;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
/**
* API 컬렉션 리소스 기본 클래스
*
* 모든 API Collection은 이 클래스를 상속해야 합니다.
* - HasRowNumber: 순번 부여
* - abilityMap(): 컬렉션 레벨 abilities (페이지 버튼 제어)
*/
abstract class BaseApiCollection extends ResourceCollection
{
use HasRowNumber;
/**
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
*
* 페이지 레벨 버튼 제어용 (생성, 일괄삭제 등).
* abilities가 불필요한 컬렉션은 오버라이드하지 않습니다.
*
* @return array<string, string> ['can_delete' => 'permission.identifier', ...]
*/
protected function abilityMap(): array
{
return [];
}
/**
* 컬렉션 레벨 abilities를 해석합니다.
*
* @param Request $request HTTP 요청 객체
* @return array<string, bool>
*/
public function resolveCollectionAbilities(Request $request): array
{
$map = $this->abilityMap();
if (empty($map)) {
return [];
}
$user = $request->user();
$abilities = [];
foreach ($map as $key => $permission) {
$abilities[$key] = PermissionHelper::check($permission, $user);
}
return $abilities;
}
}
@@ -1,42 +0,0 @@
<?php
namespace App\Http\Resources;
use App\Http\Resources\Traits\HasRowNumber;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
/**
* 메일 발송 이력 컬렉션 리소스
*
* 발송 이력 목록을 페이지네이션과 함께 반환합니다.
*/
class MailSendLogCollection extends ResourceCollection
{
use HasRowNumber;
/**
* 메일 발송 이력 컬렉션을 배열로 변환합니다.
*
* @param Request $request HTTP 요청 객체
* @return array<int|string, mixed> 변환된 컬렉션 배열
*/
public function toArray(Request $request): array
{
return [
'data' => $this->mapWithRowNumber(function ($mailSendLog) {
return (new MailSendLogResource($mailSendLog))->toArray(request());
}),
'pagination' => $this->resource instanceof LengthAwarePaginator ? [
'current_page' => $this->resource->currentPage(),
'last_page' => $this->resource->lastPage(),
'per_page' => $this->resource->perPage(),
'total' => $this->resource->total(),
'from' => $this->resource->firstItem(),
'to' => $this->resource->lastItem(),
'has_more_pages' => $this->resource->hasMorePages(),
] : null,
];
}
}
@@ -1,51 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
/**
* 메일 발송 이력 API 리소스
*/
class MailSendLogResource extends BaseApiResource
{
/**
* 권한 매핑을 반환합니다.
*
* @return array<string, string> 능력명 => 권한 식별자 매핑
*/
protected function abilityMap(): array
{
return [
'can_delete' => 'core.mail-send-logs.delete',
];
}
/**
* 리소스를 배열로 변환합니다.
*
* @param Request $request HTTP 요청 객체
* @return array<string, mixed> 변환된 배열 데이터
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'sender_email' => $this->sender_email,
'sender_name' => $this->sender_name,
'recipient_email' => $this->recipient_email,
'recipient_name' => $this->recipient_name,
'subject' => $this->subject,
'body' => $this->body,
'template_type' => $this->template_type,
'extension_type' => $this->extension_type?->value,
'extension_identifier' => $this->extension_identifier,
'source' => $this->source,
'status' => $this->status,
'error_message' => $this->error_message,
'sent_at' => $this->formatDateTimeStringForUser($this->sent_at),
...$this->formatTimestamps(),
...$this->resourceMeta($request),
];
}
}
@@ -1,42 +0,0 @@
<?php
namespace App\Http\Resources;
use App\Http\Resources\Traits\HasRowNumber;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
/**
* 메일 템플릿 컬렉션 리소스
*
* 템플릿 목록을 페이지네이션과 함께 반환합니다.
*/
class MailTemplateCollection extends ResourceCollection
{
use HasRowNumber;
/**
* 메일 템플릿 컬렉션을 배열로 변환합니다.
*
* @param Request $request HTTP 요청 객체
* @return array<int|string, mixed> 변환된 컬렉션 배열
*/
public function toArray(Request $request): array
{
return [
'data' => $this->mapWithRowNumber(function ($mailTemplate) {
return (new MailTemplateResource($mailTemplate))->toArray(request());
}),
'pagination' => $this->resource instanceof LengthAwarePaginator ? [
'current_page' => $this->resource->currentPage(),
'last_page' => $this->resource->lastPage(),
'per_page' => $this->resource->perPage(),
'total' => $this->resource->total(),
'from' => $this->resource->firstItem(),
'to' => $this->resource->lastItem(),
'has_more_pages' => $this->resource->hasMorePages(),
] : null,
];
}
}
@@ -1,30 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class MailTemplateResource extends BaseApiResource
{
/**
* 리소스를 배열로 변환합니다.
*
* @param Request $request HTTP 요청
* @return array<string, mixed> 리소스 배열
*/
public function toArray(Request $request): array
{
return [
'id' => $this->getValue('id'),
'type' => $this->getValue('type'),
'subject' => $this->getValue('subject'),
'body' => $this->getValue('body'),
'variables' => $this->getValue('variables'),
'is_active' => (bool) $this->getValue('is_active'),
'is_default' => (bool) $this->getValue('is_default'),
'updated_by' => $this->updater?->uuid,
...$this->formatTimestamps(),
...$this->resourceMeta($request),
];
}
}
+1 -2
View File
@@ -4,9 +4,8 @@ namespace App\Http\Resources;
use App\Http\Resources\Traits\HasAbilityCheck;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class MenuCollection extends ResourceCollection
class MenuCollection extends BaseApiCollection
{
use HasAbilityCheck;
+13 -2
View File
@@ -3,10 +3,21 @@
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ModuleCollection extends ResourceCollection
class ModuleCollection extends BaseApiCollection
{
/**
* {@inheritDoc}
*/
protected function abilityMap(): array
{
return [
'can_install' => 'core.modules.install',
'can_activate' => 'core.modules.activate',
'can_uninstall' => 'core.modules.uninstall',
];
}
/**
* 모듈 컬렉션을 배열로 변환합니다.
*
+1
View File
@@ -67,6 +67,7 @@ class ModuleResource extends BaseApiResource
'version' => $this->getValue('version'),
'description' => $this->getLocalizedField('description'),
'github_url' => $this->getValue('github_url'),
'requires_core' => $this->getValue('requires_core'),
'dependencies' => $this->getValue('dependencies', []),
'status' => $this->getValue('status'),
'is_installed' => $this->getValue('is_installed', false),
@@ -0,0 +1,46 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class NotificationDefinitionCollection extends BaseApiCollection
{
/**
* {@inheritDoc}
*/
protected function abilityMap(): array
{
return [
'can_update' => 'core.settings.update',
];
}
/**
* 컬렉션을 배열로 변환합니다.
*
* @param Request $request
* @return array
*/
public function toArray(Request $request): array
{
$sortOrder = $request->input('sort_order', 'asc');
$abilities = $this->resolveCollectionAbilities($request);
return [
'data' => $this->mapWithRowNumber(function ($definition) use ($request) {
return (new NotificationDefinitionResource($definition))->toArray($request);
}, $sortOrder),
'pagination' => [
'current_page' => $this->currentPage(),
'last_page' => $this->lastPage(),
'per_page' => $this->perPage(),
'total' => $this->total(),
'from' => $this->firstItem(),
'to' => $this->lastItem(),
'has_more_pages' => $this->hasMorePages(),
],
...($abilities ? ['abilities' => $abilities] : []),
];
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class NotificationDefinitionResource extends BaseApiResource
{
/**
* {@inheritDoc}
*/
protected function abilityMap(): array
{
return [
'can_update' => 'core.settings.update',
'can_delete' => 'core.settings.update',
];
}
/**
* 리소스를 배열로 변환합니다.
*
* @param Request $request
* @return array
*/
public function toArray(Request $request): array
{
return [
'id' => $this->getValue('id'),
'type' => $this->getValue('type'),
'hook_prefix' => $this->getValue('hook_prefix'),
'extension_type' => $this->getValue('extension_type'),
'extension_identifier' => $this->getValue('extension_identifier'),
'name' => $this->getValue('name'),
'description' => $this->getValue('description'),
'variables' => $this->getValue('variables'),
'channels' => $this->getValue('channels'),
'hooks' => $this->getValue('hooks'),
'is_active' => (bool) $this->getValue('is_active'),
'is_default' => (bool) $this->getValue('is_default'),
'templates' => $this->relationLoaded('templates')
? NotificationTemplateResource::collection($this->templates)
: null,
...$this->formatTimestamps(),
...$this->resourceMeta($request),
];
}
}
@@ -0,0 +1,46 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class NotificationLogCollection extends BaseApiCollection
{
/**
* {@inheritDoc}
*/
protected function abilityMap(): array
{
return [
'can_delete' => 'core.notification-logs.delete',
];
}
/**
* 컬렉션을 배열로 변환합니다.
*
* @param Request $request
* @return array
*/
public function toArray(Request $request): array
{
$sortOrder = $request->input('sort_order', 'desc');
$abilities = $this->resolveCollectionAbilities($request);
return [
'data' => $this->mapWithRowNumber(function ($log) use ($request) {
return (new NotificationLogResource($log))->toArray($request);
}, $sortOrder),
'pagination' => [
'current_page' => $this->resource->currentPage(),
'last_page' => $this->resource->lastPage(),
'per_page' => $this->resource->perPage(),
'total' => $this->resource->total(),
'from' => $this->resource->firstItem(),
'to' => $this->resource->lastItem(),
'has_more_pages' => $this->resource->hasMorePages(),
],
...($abilities ? ['abilities' => $abilities] : []),
];
}
}
@@ -0,0 +1,64 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class NotificationLogResource extends BaseApiResource
{
/**
* 리소스를 배열로 변환합니다.
*/
public function toArray(Request $request): array
{
return [
'id' => $this->getValue('id'),
'channel' => $this->getValue('channel'),
'notification_type' => $this->getValue('notification_type'),
'extension_type' => $this->getValue('extension_type'),
'extension_identifier' => $this->getValue('extension_identifier'),
'recipient_user_id' => $this->getValue('recipient_user_id'),
'recipient_identifier' => $this->getValue('recipient_identifier'),
'recipient_name' => $this->getValue('recipient_name'),
'sender_user_id' => $this->getValue('sender_user_id'),
'sender' => $this->whenLoaded('senderUser', function () {
$user = $this->resource->senderUser;
return $user ? [
'uuid' => $user->uuid,
'name' => $user->name,
'email' => $user->email,
] : null;
}),
'recipient' => $this->whenLoaded('recipientUser', function () {
$user = $this->resource->recipientUser;
return $user ? [
'uuid' => $user->uuid,
'name' => $user->name,
'email' => $user->email,
] : null;
}),
'subject' => $this->getValue('subject'),
'body' => $this->getValue('body'),
'status' => $this->getValue('status')?->value ?? $this->getValue('status'),
'error_message' => $this->getValue('error_message'),
'source' => $this->getValue('source'),
'sent_at' => $this->formatDateTimeStringForUser($this->resource->sent_at),
...$this->formatTimestamps(),
...$this->resourceMeta($request),
];
}
/**
* 리소스별 능력 매핑을 반환합니다.
*
* @return array<string, string>
*/
protected function abilityMap(): array
{
return [
'can_delete' => 'core.notification-logs.delete',
];
}
}
@@ -0,0 +1,73 @@
<?php
namespace App\Http\Resources;
use App\Models\Role;
use App\Models\User;
use Illuminate\Http\Request;
class NotificationTemplateResource extends BaseApiResource
{
/**
* {@inheritDoc}
*/
protected function abilityMap(): array
{
return [
'can_update' => 'core.settings.update',
'can_delete' => 'core.settings.update',
];
}
/**
* 리소스를 배열로 변환합니다.
*
* @param Request $request
* @return array
*/
public function toArray(Request $request): array
{
return [
'id' => $this->getValue('id'),
'definition_id' => $this->getValue('definition_id'),
'channel' => $this->getValue('channel'),
'subject' => $this->getValue('subject'),
'body' => $this->getValue('body'),
'click_url' => $this->getValue('click_url'),
'recipients' => $this->enrichRecipients($this->getValue('recipients') ?? []),
'is_active' => (bool) $this->getValue('is_active'),
'is_default' => (bool) $this->getValue('is_default'),
'user_overrides' => $this->getValue('user_overrides'),
'updated_by' => $this->resource->updater?->uuid ?? null,
...$this->formatTimestamps(),
...$this->resourceMeta($request),
];
}
/**
* 수신자 규칙에 표시용 이름을 추가합니다.
*
* @param array $recipients 수신자 규칙 배열
* @return array
*/
private function enrichRecipients(array $recipients): array
{
$locale = app()->getLocale();
return array_map(function (array $rule) use ($locale) {
if ($rule['type'] === 'role' && ! empty($rule['value'])) {
$role = Role::where('identifier', $rule['value'])->first();
$rule['display_name'] = $role
? ($role->name[$locale] ?? $role->name['ko'] ?? $rule['value'])
: $rule['value'];
}
if ($rule['type'] === 'specific_users' && ! empty($rule['value'])) {
$users = User::whereIn('uuid', $rule['value'])->pluck('name', 'uuid');
$rule['display_names'] = $users->values()->all();
}
return $rule;
}, $recipients);
}
}
+1 -2
View File
@@ -3,14 +3,13 @@
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
/**
* 플러그인 컬렉션 리소스
*
* 플러그인 목록을 다양한 형태로 변환하여 반환합니다.
*/
class PluginCollection extends ResourceCollection
class PluginCollection extends BaseApiCollection
{
/**
* 플러그인 컬렉션을 배열로 변환합니다.
+1
View File
@@ -94,6 +94,7 @@ class PluginResource extends BaseApiResource
'version' => $this->getValue('version', '1.0.0'),
'description' => $this->getLocalizedField('description'),
'github_url' => $this->getValue('github_url'),
'requires_core' => $this->getValue('requires_core'),
'dependencies' => $this->getValue('dependencies', []),
'status' => $this->getValue('status', 'uninstalled'),
'is_installed' => $this->getValue('is_installed', false),
+1 -2
View File
@@ -4,9 +4,8 @@ namespace App\Http\Resources;
use App\Http\Resources\Traits\HasAbilityCheck;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class RoleCollection extends ResourceCollection
class RoleCollection extends BaseApiCollection
{
use HasAbilityCheck;
+1 -2
View File
@@ -3,10 +3,9 @@
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
class ScheduleCollection extends ResourceCollection
class ScheduleCollection extends BaseApiCollection
{
/**
* 스케줄 컬렉션을 배열로 변환합니다.
@@ -3,10 +3,9 @@
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\LengthAwarePaginator;
class ScheduleHistoryCollection extends ResourceCollection
class ScheduleHistoryCollection extends BaseApiCollection
{
/**
* 스케줄 실행 이력 컬렉션을 배열로 변환합니다.
+1 -2
View File
@@ -3,14 +3,13 @@
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
/**
* 템플릿 컬렉션 리소스
*
* 템플릿 목록을 다양한 형태로 변환하여 반환합니다.
*/
class TemplateCollection extends ResourceCollection
class TemplateCollection extends BaseApiCollection
{
/**
* 템플릿 컬렉션을 배열로 변환합니다.
+1
View File
@@ -83,6 +83,7 @@ class TemplateResource extends BaseApiResource
'description' => $this->getLocalizedField('description'),
'github_url' => $this->getValue('github_url'),
'github_changelog_url' => $this->getValue('github_changelog_url'),
'requires_core' => $this->getValue('requires_core'),
// pending/bundled 상태
'is_pending' => $this->getValue('is_pending', false),
'is_bundled' => $this->getValue('is_bundled', false),
+1 -4
View File
@@ -3,14 +3,11 @@
namespace App\Http\Resources;
use App\Http\Resources\Traits\HasAbilityCheck;
use App\Http\Resources\Traits\HasRowNumber;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
class UserCollection extends ResourceCollection
class UserCollection extends BaseApiCollection
{
use HasAbilityCheck;
use HasRowNumber;
/**
* 컬렉션 레벨 능력(can_*) 매핑을 반환합니다.
@@ -0,0 +1,43 @@
<?php
namespace App\Http\Resources;
use App\Contracts\Repositories\NotificationDefinitionRepositoryInterface;
use Illuminate\Http\Request;
class UserNotificationCollection extends BaseApiCollection
{
/**
* 컬렉션을 배열로 변환합니다.
*
* @param Request $request
* @return array
*/
public function toArray(Request $request): array
{
$sortOrder = $request->input('sort_order', 'desc');
// 알림 type 식별자 → 다국어 라벨 맵을 컬렉션 단위로 한 번만 로드 (N+1 회피)
$user = $request->user();
$typeLabelMap = app(NotificationDefinitionRepositoryInterface::class)
->getLabelMap($user?->locale);
return [
'data' => $this->mapWithRowNumber(function ($notification) use ($request, $typeLabelMap) {
return (new UserNotificationResource($notification))
->withTypeLabelMap($typeLabelMap)
->toArray($request);
}, $sortOrder),
'pagination' => [
'current_page' => $this->resource->currentPage(),
'last_page' => $this->resource->lastPage(),
'per_page' => $this->resource->perPage(),
'total' => $this->resource->total(),
'from' => $this->resource->firstItem(),
'to' => $this->resource->lastItem(),
'has_more_pages' => $this->resource->hasMorePages(),
],
];
}
}
@@ -0,0 +1,92 @@
<?php
namespace App\Http\Resources;
use App\Contracts\Repositories\NotificationDefinitionRepositoryInterface;
use Illuminate\Http\Request;
class UserNotificationResource extends BaseApiResource
{
/**
* type 식별자 → 다국어 라벨 맵 (Collection에서 사전 주입).
*
* Collection에서 일괄 응답 시 N+1을 회피하기 위해 한 번만 로드한 맵을 주입받습니다.
* 단일 Resource로 사용될 경우 null이며, toArray() 내부에서 즉시 조회합니다.
*
* @var array<string, string>|null
*/
protected ?array $typeLabelMap = null;
/**
* 사전 주입된 type 라벨 맵을 설정합니다.
*
* @param array<string, string> $map
* @return $this
*/
public function withTypeLabelMap(array $map): static
{
$this->typeLabelMap = $map;
return $this;
}
/**
* 리소스를 배열로 변환합니다.
*
* @param Request $request
* @return array
*/
public function toArray(Request $request): array
{
$data = $this->getValue('data') ?? [];
$user = $request->user();
$timezone = $user?->getTimezone() ?? config('app.default_user_timezone', 'Asia/Seoul');
$type = $data['type'] ?? $this->getValue('type');
$typeLabel = $this->resolveTypeLabel($type, $user?->locale);
// 알림 클릭 시 이동 URL — click_url(템플릿 패턴 기반) 우선, 없으면 action_url(메일 CTA) fallback
$innerData = $data['data'] ?? [];
$url = $data['click_url'] ?? $innerData['action_url'] ?? null;
return [
'id' => $this->getValue('id'),
'type' => $type,
'type_label' => $typeLabel,
'subject' => $data['subject'] ?? null,
'body' => $data['body'] ?? null,
'url' => $url,
'data' => $data,
'read_at' => $this->resource->read_at?->setTimezone($timezone)->format('Y-m-d H:i:s'),
'created_at' => $this->resource->created_at?->setTimezone($timezone)->format('Y-m-d H:i:s'),
];
}
/**
* type 식별자에 해당하는 다국어 라벨을 해석합니다.
*
* 우선순위:
* 1. Collection에서 사전 주입한 typeLabelMap
* 2. Repository에서 즉시 조회 (단일 Resource 사용 시)
* 3. 정의 미존재 시 type 식별자 그대로 반환 (UI에 raw 키 노출 방지 fallback)
*
* @param string|null $type
* @param string|null $locale
* @return string
*/
protected function resolveTypeLabel(?string $type, ?string $locale): string
{
if (! $type) {
return '';
}
if ($this->typeLabelMap !== null) {
return $this->typeLabelMap[$type] ?? '';
}
$repository = app(NotificationDefinitionRepositoryInterface::class);
$definition = $repository->getActiveByType($type);
return $definition?->getLocalizedName($locale) ?: '';
}
}