134 lines
3.2 KiB
PHP
134 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Turno;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class TurnoController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(): JsonResponse
|
|
{
|
|
$items = Turno::all();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $items,
|
|
'message' => 'Registros obtenidos correctamente',
|
|
], 200);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$payload = $request->only((new Turno())->getFillable());
|
|
$turno = Turno::create($payload);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Registro creado correctamente',
|
|
], 201);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Turno $turno): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Registro obtenido correctamente',
|
|
], 200);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Turno $turno): JsonResponse
|
|
{
|
|
$payload = $request->only((new Turno())->getFillable());
|
|
$turno->update($payload);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Registro actualizado correctamente',
|
|
], 200);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Turno $turno): JsonResponse
|
|
{
|
|
$turno->delete();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Registro eliminado correctamente',
|
|
], 200);
|
|
}
|
|
|
|
public function confirmar(Turno $turno): JsonResponse
|
|
{
|
|
$turno->confirmar();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Turno confirmado correctamente',
|
|
], 200);
|
|
}
|
|
|
|
public function cancelar(Turno $turno): JsonResponse
|
|
{
|
|
$turno->cancelar();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Turno cancelado correctamente',
|
|
], 200);
|
|
}
|
|
|
|
public function reprogramar(Turno $turno): JsonResponse
|
|
{
|
|
$turno->reprogramar();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Turno reprogramado correctamente',
|
|
], 200);
|
|
}
|
|
|
|
public function clienteAusente(Turno $turno): JsonResponse
|
|
{
|
|
$turno->clienteAusente();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Turno marcado como cliente ausente',
|
|
], 200);
|
|
}
|
|
|
|
public function clientePresente(Turno $turno): JsonResponse
|
|
{
|
|
$turno->clientePresente();
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'data' => $turno,
|
|
'message' => 'Turno marcado como cliente presente',
|
|
], 200);
|
|
}
|
|
} |