Cotizaciones/app/Http/Controllers/Api/InstitucioneController.php
2026-04-24 12:16:47 -07:00

90 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers\Api;
use App\Models\Institucione;
use Illuminate\Http\Request;
use App\Http\Requests\InstitucioneRequest;
use Illuminate\Http\Response;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use App\Http\Resources\InstitucioneResource;
use OpenApi\Attributes as OA;
#[OA\Tag(
name: "Institucioness",
description: "Gestión de instituciones"
)]
class InstitucioneController extends Controller
{
/**
* Display a listing of the resource.
*/
#[OA\Get(
path: "/api/instituciones",
summary: "Lista de instituciones del usuario autenticado",
tags: ["Instituciones"],
security: [["bearerAuth" => []]],
responses: [
new OA\Response(
response: 200,
description: "OK",
content: new OA\JsonContent()
),
new OA\Response(
response: 401,
description: "No autorizado",
content: new OA\JsonContent(
example: ["message" => "Unauthenticated."]
)
)
]
)]
public function index(Request $request)
{
$instituciones = Institucione::paginate();
return InstitucioneResource::collection($instituciones);
}
/**
* Store a newly created resource in storage.
*/
public function store(InstitucioneRequest $request): JsonResponse
{
$institucione = Institucione::create($request->validated());
return response()->json(new InstitucioneResource($institucione));
}
/**
* Display the specified resource.
*/
public function show(Institucione $institucione): JsonResponse
{
return response()->json(new InstitucioneResource($institucione));
}
/**
* Update the specified resource in storage.
*/
public function update(InstitucioneRequest $request, Institucione $institucione): JsonResponse
{
$institucione->update($request->validated());
return response()->json(new InstitucioneResource($institucione));
}
/**
* Delete the specified resource.
*/
public function destroy(Institucione $institucione): Response
{
$institucione->delete();
return response()->noContent();
}
}