Skip to content

Commit 8e1d2d2

Browse files
committed
feat: add Endpoint for list a workspace for actually authorized user
1 parent 0f2a6cf commit 8e1d2d2

3 files changed

Lines changed: 63 additions & 9 deletions

File tree

public/api/docs/swagger.json

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@
290290
],
291291
"summary": "Returns a collection of all workspaces owned by or associated with the currently authenticated user.",
292292
"description": "List all workspaces for the authenticated account",
293-
"operationId": "findWorkspaces",
293+
"operationId": "findOwnWorkspaces",
294294
"parameters": [
295295
{
296296
"name": "page",
@@ -322,7 +322,18 @@
322322
"content": {
323323
"application/json": {
324324
"schema": {
325-
"$ref": "#/components/schemas/WorkspaceList"
325+
"properties": {
326+
"workspaces": {
327+
"type": "array",
328+
"items": {
329+
"$ref": "#/components/schemas/WorkspaceResponse"
330+
}
331+
},
332+
"meta": {
333+
"$ref": "#/components/schemas/PaginationMeta"
334+
}
335+
},
336+
"type": "object"
326337
}
327338
}
328339
}
@@ -595,6 +606,25 @@
595606
},
596607
"type": "object"
597608
},
609+
"PaginationMeta": {
610+
"title": "Pagination Meta",
611+
"description": "Info about the number of pages and limits",
612+
"properties": {
613+
"currentPage": {
614+
"type": "integer",
615+
"example": 1
616+
},
617+
"totalPages": {
618+
"type": "integer",
619+
"example": 10
620+
},
621+
"totalItems": {
622+
"type": "integer",
623+
"example": 100
624+
}
625+
},
626+
"type": "object"
627+
},
598628
"WorkspaceList": {
599629
"properties": {
600630
"workspaces": {

src/App/Workspace/src/DTO/PaginationMeta.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22

33
namespace ownHackathon\Workspace\DTO;
44

5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
title: 'Pagination Meta',
9+
description: 'Info about the number of pages and limits'
10+
)]
511
readonly class PaginationMeta
612
{
713
public function __construct(
8-
public int $totalItems,
9-
public int $totalPages,
14+
#[OA\Property(example: 1)]
1015
public int $currentPage,
16+
#[OA\Property(example: 10)]
17+
public int $totalPages,
18+
#[OA\Property(example: 100)]
19+
public int $totalItems,
1120
) {
1221
}
1322

1423
public static function fromValues(int $totalCount, int $totalPages, int $currentPage): self
1524
{
16-
return new self($totalCount, $totalPages, $currentPage);
25+
return new self($currentPage, $totalPages, $totalCount);
1726
}
1827
}

src/App/Workspace/src/Handler/ListOwnWorkspacesHandler.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
use Exdrals\Identity\DTO\Response\HttpResponseMessage;
66
use Exdrals\Shared\Domain\Account\AccountInterface;
7+
use Exdrals\Shared\Domain\Enum\DataType;
78
use Fig\Http\Message\StatusCodeInterface as HTTP;
89
use Laminas\Diactoros\Response\JsonResponse;
910
use OpenApi\Attributes as OA;
1011
use ownHackathon\Shared\Domain\ValueObject\Pagination;
11-
use ownHackathon\Workspace\DTO\WorkspaceList;
12+
use ownHackathon\Workspace\DTO\PaginationMeta;
1213
use ownHackathon\Workspace\DTO\WorkspaceResponse;
1314
use ownHackathon\Workspace\Infrastructure\Persistence\Repository\WorkspaceRepository;
1415
use ownHackathon\Workspace\Infrastructure\Service\PaginationService;
@@ -26,7 +27,7 @@ public function __construct(
2627

2728
#[OA\Get(
2829
path: '/me/workspaces',
29-
operationId: 'findWorkspaces',
30+
operationId: 'findOwnWorkspaces',
3031
description: 'List all workspaces for the authenticated account',
3132
summary: 'Returns a collection of all workspaces owned by or associated with the currently authenticated user.',
3233
security: [['accessToken' => []]],
@@ -58,7 +59,21 @@ public function __construct(
5859
#[OA\Response(
5960
response: HTTP::STATUS_OK,
6061
description: 'A list of workspaces belonging to the user.',
61-
content: new OA\JsonContent(ref: WorkspaceList::class)
62+
content: new OA\JsonContent(
63+
properties: [
64+
new OA\Property(
65+
property: 'workspaces',
66+
type: 'array',
67+
items: new OA\Items(ref: WorkspaceResponse::class)
68+
),
69+
new OA\Property(
70+
property: 'meta',
71+
ref: PaginationMeta::class,
72+
type: DataType::OBJECT->value
73+
),
74+
],
75+
type: DataType::OBJECT->value
76+
)
6277
)]
6378
#[OA\Response(
6479
response: HTTP::STATUS_UNAUTHORIZED,
@@ -86,7 +101,7 @@ public function handle(ServerRequestInterface $request): ResponseInterface
86101
'workspaces' => $response,
87102
'meta' => [
88103
'currentPage' => $metaData->currentPage,
89-
'maxPages' => $metaData->totalPages,
104+
'totalPages' => $metaData->totalPages,
90105
'totalItems' => $metaData->totalItems,
91106
],
92107
], HTTP::STATUS_OK);

0 commit comments

Comments
 (0)