60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Sms;
|
|
|
|
use App\Repositories\Admin\Sms\AdminSmsTemplateRepository;
|
|
|
|
final class AdminSmsTemplateService
|
|
{
|
|
public function __construct(
|
|
private readonly AdminSmsTemplateRepository $repo
|
|
) {}
|
|
|
|
public function list(array $filters, int $perPage = 30)
|
|
{
|
|
return $this->repo->paginate($filters, $perPage);
|
|
}
|
|
|
|
public function get(int $id): ?object
|
|
{
|
|
return $this->repo->find($id);
|
|
}
|
|
|
|
public function create(int $adminId, array $data): array
|
|
{
|
|
$code = strtolower(trim((string)($data['code'] ?? '')));
|
|
if ($code === '' || !preg_match('/^[a-z0-9\-_]{3,60}$/', $code)) {
|
|
return ['ok'=>false, 'message'=>'code는 영문/숫자/대시/언더바 3~60자로 입력하세요.'];
|
|
}
|
|
|
|
$id = $this->repo->insert([
|
|
'code' => $code,
|
|
'title' => trim((string)($data['title'] ?? '')),
|
|
'body' => (string)($data['body'] ?? ''),
|
|
'description' => trim((string)($data['description'] ?? '')) ?: null,
|
|
'is_active' => (int)($data['is_active'] ?? 1),
|
|
'created_by' => $adminId,
|
|
]);
|
|
|
|
return ['ok'=>true, 'id'=>$id];
|
|
}
|
|
|
|
public function update(int $id, array $data): array
|
|
{
|
|
$affected = $this->repo->update($id, [
|
|
'title' => trim((string)($data['title'] ?? '')),
|
|
'body' => (string)($data['body'] ?? ''),
|
|
'description' => trim((string)($data['description'] ?? '')) ?: null,
|
|
'is_active' => (int)($data['is_active'] ?? 1),
|
|
]);
|
|
|
|
return ['ok'=>($affected >= 0)];
|
|
}
|
|
|
|
public function activeForSend(int $limit = 200): array
|
|
{
|
|
return $this->repo->listActive($limit);
|
|
}
|
|
|
|
}
|