C. srv / srvAmigoBusca.php

1<?php
2
3require_once __DIR__ . "/../lib/php/ejecutaServicio.php";
4require_once __DIR__ . "/../lib/php/ProblemDetails.php";
5require_once __DIR__ . "/../lib/php/pdFaltaId.php";
6require_once __DIR__ . "/../lib/php/leeEntero.php";
7require_once __DIR__ . "/bd/amigoBusca.php";
8
9ejecutaServicio(function () {
10 $id = leeEntero("id");
11 if ($id === null) throw pdFaltaId();
12 $modelo = amigoBusca($id);
13 if ($modelo === false) {
14 $htmlId = htmlentities($id);
15 throw new ProblemDetails(
16 status: ProblemDetails::NotFound,
17 type: "/error/amigonoencontrado.html",
18 title: "Amigo no encontrado.",
19 detail: "No se encontró ningún amigo con el id $htmlId.",
20 );
21 } else {
22 $pasatiempo = $modelo->pasatiempo;
23 return [
24 "id" => ["value" => $modelo->id],
25 "nombre" => ["value" => $modelo->nombre],
26 "pasId" => ["value" => $pasatiempo === null ? "" : $pasatiempo->id]
27 ];
28 }
29});
30
skip_previous skip_next