37 lines
1.6 KiB
PHP
37 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\DeskServiceAvailability;
|
|
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(), 'schedulingAvailable' => app(DeskServiceAvailability::class)->scheduled(), 'today' => now()->toDateString(), 'calendarTimezone' => config('app.timezone')];
|
|
|
|
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, 'effective_from' => $row->effective_from ?? null], 201)
|
|
: back()->with('success', 'Versão publicada'.(($row->effective_from ?? null) ? ' com entrada em vigor em '.$row->effective_from : '').'. 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)));
|
|
}
|
|
}
|