36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\DeskServiceEditor;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
final class DeskServiceEditorController extends Controller
|
|
{
|
|
public function index(Request $request, DeskServiceEditor $editor): Response|JsonResponse
|
|
{
|
|
$data = ['services' => $editor->listing()];
|
|
|
|
return $request->expectsJson() ? response()->json($data) : Inertia::render('desk/service-editor', $data);
|
|
}
|
|
|
|
public function publish(Request $request, DeskServiceEditor $editor, string $code): JsonResponse|RedirectResponse
|
|
{
|
|
$row = $editor->publish($request->user(), $code, $request->all());
|
|
|
|
return $request->expectsJson() ? response()->json(['id' => $row->id, 'version' => $row->version], 201)
|
|
: back()->with('success', 'Nova versão publicada para pedidos futuros. Os pedidos existentes conservam a sua versão.');
|
|
}
|
|
|
|
public function history(Request $request, DeskServiceEditor $editor, string $code): JsonResponse
|
|
{
|
|
$data = $request->validate(['page' => ['nullable', 'integer', 'min:1']]);
|
|
|
|
return response()->json($editor->history($code, (int) ($data['page'] ?? 1)));
|
|
}
|
|
}
|