From e4aa3ae968d883f54d8ebada72c708f56aad35db Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Tue, 24 Aug 2021 05:31:48 +0100 Subject: [PATCH] [NOTE] Add route and controller --- src/Controller/Note.php | 57 +++++++++++++++++++++++++++++++++++++++++ src/Routes/Note.php | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/Controller/Note.php create mode 100644 src/Routes/Note.php diff --git a/src/Controller/Note.php b/src/Controller/Note.php new file mode 100644 index 0000000000..6e3709fd2e --- /dev/null +++ b/src/Controller/Note.php @@ -0,0 +1,57 @@ +. + +// }}} + +namespace App\Controller; + +use App\Core\Controller; +use App\Core\DB\DB; +use function App\Core\I18n\_m; +use App\Util\Exception\ClientException; +use Symfony\Component\HttpFoundation\Request; + +class Note extends Controller +{ + /** + * Generic function that handles getting a representation for a note + */ + private function note(int $id, callable $handle) + { + $note = DB::findOneBy('note', ['id' => $id]); + if (empty($note)) { + throw new ClientException(_m('No such note'), 404); + } else { + return $handle($note); + } + } + + /** + * The page where the note and it's info is shown + */ + public function note_show(Request $request, int $id) + { + return $this->note($id, function ($note) use ($id) { + return [ + '_template' => 'note/view.html.twig', + 'note' => $note, + ]; + }); + } +} diff --git a/src/Routes/Note.php b/src/Routes/Note.php new file mode 100644 index 0000000000..d84ef58c91 --- /dev/null +++ b/src/Routes/Note.php @@ -0,0 +1,45 @@ +. + +// }}} + +/** + * Define social's attachment routes + * + * @package GNUsocial + * @category Router + * + * @author Diogo Cordeiro + * @author Hugo Sales + * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Routes; + +use App\Controller as C; +use App\Core\Router\RouteLoader; + +abstract class Note +{ + public static function load(RouteLoader $r): void + { + $r->connect('note_view', '/note/{id<\d+>}', [C\Note::class, 'note_show']); + } +}