Skip to content

Commit

Permalink
UI: list of api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 18, 2023
1 parent 8305be2 commit 6fc0ea4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
16 changes: 11 additions & 5 deletions app/Api/Product/ListProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 39 in app/Api/Product/ListProductController.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Parameter #1 $products of static method App\Api\Product\ListProductResponse::of() expects array<string, array>, array<int, array<string, int|string>> given.
} catch (Throwable $e) {
return ErrorResponse::create()
->withStatusCode(400)
->withMessage('Cannot load detail');
->withMessage('Cannot load list of products');
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/Api/Product/ListProductResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class ListProductResponse extends EntityResponse
{

/**
* @param array<string, scalar> $detail
* @param array<string, mixed[]> $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;
}
Expand Down
7 changes: 5 additions & 2 deletions app/UI/Home/Templates/default.latte
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{block #content}

<div class="space-x-4">
<a href="/api/v1/product" class="hover:underline text-blue-600">/api/v1/product</a>
<div class="flex flex-col">
<a href="api/_/ping" class="hover:underline text-blue-600">/api/_/ping</a>
<a href="api/_/apidoc" class="hover:underline text-blue-600">/api/_/apidoc</a>
<a href="api/v1/product?_apikey=foobar" class="hover:underline text-blue-600">/api/v1/product</a>
<a href="api/v1/product/1234567?_apikey=foobar" class="hover:underline text-blue-600">/api/v1/product/1234567</a>
</div>

0 comments on commit 6fc0ea4

Please sign in to comment.