From c490555fe6c9ae9823c9de602891c42c5237f1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Mon, 18 Dec 2023 09:41:25 +0100 Subject: [PATCH] UI: list of api endpoints --- app/Api/Product/ListProductController.php | 16 +++++++++++----- app/Api/Product/ListProductResponse.php | 6 +++--- app/UI/Home/Templates/default.latte | 5 ++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/Api/Product/ListProductController.php b/app/Api/Product/ListProductController.php index b59ba1a..6356cd1 100644 --- a/app/Api/Product/ListProductController.php +++ b/app/Api/Product/ListProductController.php @@ -25,16 +25,22 @@ public static function describe(): Describer public function __invoke(ApiRequest $request): ResponseInterface { try { - $product = [ - 'id' => 1, - 'name' => 'Test', + $products = [ + [ + 'id' => 1, + 'name' => 'Test1', + ], + [ + 'id' => 2, + 'name' => 'Test2', + ], ]; - return GetProductResponse::of($product); + return ListProductResponse::of($products); } catch (Throwable $e) { return ErrorResponse::create() ->withStatusCode(400) - ->withMessage('Cannot load detail'); + ->withMessage('Cannot load list of products'); } } diff --git a/app/Api/Product/ListProductResponse.php b/app/Api/Product/ListProductResponse.php index 90e5453..9f304c7 100644 --- a/app/Api/Product/ListProductResponse.php +++ b/app/Api/Product/ListProductResponse.php @@ -8,12 +8,12 @@ class ListProductResponse extends EntityResponse { /** - * @param array $detail + * @param array $products */ - public static function of(array $detail): self + public static function of(array $products): self { $self = self::create(); - $self->payload = $detail; + $self->payload = $products; return $self; } diff --git a/app/UI/Home/Templates/default.latte b/app/UI/Home/Templates/default.latte index 85a8c0d..7c95871 100644 --- a/app/UI/Home/Templates/default.latte +++ b/app/UI/Home/Templates/default.latte @@ -1,5 +1,8 @@ {block #content}