Add EmailLogController and routes for email logs management
This commit is contained in:
@@ -47,6 +47,7 @@ jobs:
|
||||
|
||||
php artisan migrate --force
|
||||
|
||||
php artisan config:clear
|
||||
php artisan optimize
|
||||
|
||||
php artisan queue:restart || true
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\EmailLog;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Mail;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
final class EmailLogController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$limit = min((int) $request->get('limit', $request->get('per_page', 20)), 200);
|
||||
|
||||
$query = Mail::query()->orderByDesc('created_at');
|
||||
|
||||
// sort=field_asc|field_desc
|
||||
if ($sort = $request->get('sort')) {
|
||||
$parts = explode('_', $sort);
|
||||
$dir = array_pop($parts);
|
||||
$col = implode('_', $parts);
|
||||
|
||||
$allowed = ['created_at', 'subject', 'status', 'to'];
|
||||
if (in_array($col, $allowed, true) && in_array($dir, ['asc', 'desc'], true)) {
|
||||
$query->reorder($col, $dir);
|
||||
}
|
||||
}
|
||||
|
||||
if ($status = $request->get('status')) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
if ($customerId = $request->get('customer_id')) {
|
||||
$query->where('customer_id', (int) $customerId);
|
||||
}
|
||||
if ($search = trim((string) $request->get('search', ''))) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('to', 'like', "%{$search}%")
|
||||
->orWhere('subject', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$paginator = $query->paginate($limit);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => $paginator->items(),
|
||||
'total' => $paginator->total(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$log = Mail::find($id);
|
||||
|
||||
if (!$log) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy email log'], 404);
|
||||
}
|
||||
|
||||
return response()->json(['error' => false, 'data' => $log]);
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ use App\Http\Controllers\Api\Admin\EmailTemplate\EmailTemplateController;
|
||||
use App\Http\Controllers\Api\Admin\EmailNotificationTemplateController;
|
||||
use App\Http\Controllers\Api\Admin\ActivityLog\ActivityLogController;
|
||||
use App\Http\Controllers\Api\Admin\Rebuild\AdminReinstallLogController;
|
||||
use App\Http\Controllers\Api\Admin\EmailLog\EmailLogController;
|
||||
use App\Http\Controllers\Api\Admin\Transaction\AdminTransactionController;
|
||||
use App\Http\Controllers\Api\Admin\Ticket\TicketController as AdminTicketController;
|
||||
use App\Http\Controllers\Api\Admin\Docs\PostCategoryController as AdminPostCategoryController;
|
||||
@@ -607,6 +608,14 @@ Route::prefix('v1')
|
||||
Route::get('{id}', 'show');
|
||||
});
|
||||
|
||||
// Email Logs
|
||||
Route::prefix('email-logs')
|
||||
->controller(EmailLogController::class)
|
||||
->group(function () {
|
||||
Route::get('/', 'index');
|
||||
Route::get('{id}', 'show')->whereNumber('id');
|
||||
});
|
||||
|
||||
// VM Rebuild Logs — who rebuilt, which OS, post-rebuild password
|
||||
Route::prefix('rebuild-logs')
|
||||
->controller(AdminReinstallLogController::class)
|
||||
|
||||
Reference in New Issue
Block a user