Skip to content

Commit a4aecc7

Browse files
.
Signed-off-by: matiasperrone-exo <matias.perrone@exomindset.co>
1 parent 399f1ec commit a4aecc7

File tree

4 files changed

+234
-2
lines changed

4 files changed

+234
-2
lines changed

app/Http/Controllers/Api/OAuth2/OAuth2GroupApiController.php

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use App\libs\Auth\Repositories\IGroupRepository;
1717
use App\ModelSerializers\SerializerRegistry;
1818
use OAuth2\IResourceServerContext;
19+
use OpenApi\Attributes as OA;
20+
use Symfony\Component\HttpFoundation\Response;
1921
use Utils\Services\ILogService;
2022

2123
/**
@@ -24,7 +26,9 @@
2426
*/
2527
final class OAuth2GroupApiController extends OAuth2ProtectedController
2628
{
27-
use GetAllTrait;
29+
use GetAllTrait {
30+
GetAllTrait::getAll as traitGetAll;
31+
}
2832

2933
/**
3034
* OAuth2UserApiController constructor.
@@ -76,4 +80,94 @@ public function getOrderRules(): array
7680
'slug'
7781
];
7882
}
79-
}
83+
84+
#[OA\Get(
85+
path: '/api/v1/groups',
86+
summary: 'Get all groups',
87+
description: 'Retrieves a paginated list of groups with optional filtering and ordering.',
88+
tags: ['Groups'],
89+
parameters: [
90+
new OA\Parameter(
91+
name: 'page',
92+
in: 'query',
93+
description: 'Page number for pagination',
94+
required: false,
95+
schema: new OA\Schema(type: 'integer', minimum: 1, default: 1, example: 1)
96+
),
97+
new OA\Parameter(
98+
name: 'per_page',
99+
in: 'query',
100+
description: 'Number of items per page',
101+
required: false,
102+
schema: new OA\Schema(type: 'integer', minimum: 5, maximum: 100, default: 5, example: 10)
103+
),
104+
new OA\Parameter(
105+
name: 'filter',
106+
in: 'query',
107+
description: 'Filter criteria. Supported filters: slug== (exact match). Example: filter=slug==administrators',
108+
required: false,
109+
schema: new OA\Schema(type: 'string', example: 'slug==administrators')
110+
),
111+
new OA\Parameter(
112+
name: 'order',
113+
in: 'query',
114+
description: 'Ordering criteria. Supported fields: id, name, slug. Use + for ascending, - for descending. Example: +name or -id',
115+
required: false,
116+
schema: new OA\Schema(type: 'string', example: '+name')
117+
),
118+
new OA\Parameter(
119+
name: 'expand',
120+
in: 'query',
121+
description: 'Expand related resources in the response',
122+
required: false,
123+
schema: new OA\Schema(type: 'string')
124+
)
125+
],
126+
responses: [
127+
new OA\Response(
128+
response: Response::HTTP_OK,
129+
description: 'Successful response with paginated groups',
130+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedGroupResponseSchema')
131+
),
132+
new OA\Response(
133+
response: Response::HTTP_NOT_FOUND,
134+
description: 'Entity not found',
135+
content: new OA\JsonContent(
136+
type: 'object',
137+
properties: [
138+
new OA\Property(property: 'message', type: 'string', example: 'Entity Not Found')
139+
]
140+
)
141+
),
142+
new OA\Response(
143+
response: Response::HTTP_PRECONDITION_FAILED,
144+
description: 'Validation failed',
145+
content: new OA\JsonContent(
146+
type: 'object',
147+
properties: [
148+
new OA\Property(property: 'message', type: 'string', example: 'Validation Failed'),
149+
new OA\Property(
150+
property: 'errors',
151+
type: 'array',
152+
items: new OA\Items(type: 'string')
153+
)
154+
]
155+
)
156+
),
157+
new OA\Response(
158+
response: Response::HTTP_INTERNAL_SERVER_ERROR,
159+
description: 'Server error',
160+
content: new OA\JsonContent(
161+
type: 'object',
162+
properties: [
163+
new OA\Property(property: 'error', type: 'string', example: 'server error')
164+
]
165+
)
166+
)
167+
]
168+
)]
169+
public function getAll()
170+
{
171+
return $this->traitGetAll();
172+
}
173+
}

app/Swagger/Model/GroupSchema.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace App\Swagger\Model;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: 'GroupModel',
9+
type: 'object',
10+
description: 'Group database model - represents the original entity structure',
11+
properties: [
12+
new OA\Property(
13+
property: 'id',
14+
type: 'integer',
15+
description: 'Unique identifier',
16+
example: 1
17+
),
18+
new OA\Property(
19+
property: 'name',
20+
type: 'string',
21+
description: 'Group name',
22+
example: 'Administrators'
23+
),
24+
new OA\Property(
25+
property: 'slug',
26+
type: 'string',
27+
description: 'Group slug for URL-friendly identification',
28+
example: 'administrators'
29+
),
30+
new OA\Property(
31+
property: 'active',
32+
type: 'boolean',
33+
description: 'Whether the group is active',
34+
example: true
35+
),
36+
new OA\Property(
37+
property: 'is_default',
38+
type: 'boolean',
39+
description: 'Whether this is a default group',
40+
example: false
41+
),
42+
new OA\Property(
43+
property: 'created_at',
44+
type: 'string',
45+
format: 'date-time',
46+
description: 'Creation timestamp'
47+
),
48+
new OA\Property(
49+
property: 'updated_at',
50+
type: 'string',
51+
format: 'date-time',
52+
description: 'Last update timestamp'
53+
),
54+
]
55+
)]
56+
class GroupSchema {}

app/Swagger/Models/GroupSchema.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace App\Swagger\Models;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: 'Group',
9+
type: 'object',
10+
description: 'Group API response - serialized representation of a group',
11+
properties: [
12+
new OA\Property(
13+
property: 'id',
14+
type: 'integer',
15+
description: 'Unique identifier',
16+
example: 1
17+
),
18+
new OA\Property(
19+
property: 'name',
20+
type: 'string',
21+
description: 'Group name',
22+
example: 'Administrators'
23+
),
24+
new OA\Property(
25+
property: 'slug',
26+
type: 'string',
27+
description: 'Group slug for URL-friendly identification',
28+
example: 'administrators'
29+
),
30+
new OA\Property(
31+
property: 'active',
32+
type: 'boolean',
33+
description: 'Whether the group is active',
34+
example: true
35+
),
36+
new OA\Property(
37+
property: 'default',
38+
type: 'boolean',
39+
description: 'Whether this is a default group',
40+
example: false
41+
),
42+
new OA\Property(
43+
property: 'created_at',
44+
type: 'integer',
45+
description: 'Creation timestamp (Unix epoch)',
46+
example: 1704067200
47+
),
48+
new OA\Property(
49+
property: 'updated_at',
50+
type: 'integer',
51+
description: 'Last update timestamp (Unix epoch)',
52+
example: 1704153600
53+
),
54+
]
55+
)]
56+
class GroupSchema {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Swagger;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: 'PaginatedGroupResponseSchema',
9+
type: 'object',
10+
description: 'Paginated list of groups',
11+
allOf: [
12+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
13+
new OA\Schema(
14+
type: 'object',
15+
properties: [
16+
new OA\Property(
17+
property: 'data',
18+
type: 'array',
19+
description: 'Array of group objects',
20+
items: new OA\Items(ref: '#/components/schemas/Group')
21+
)
22+
]
23+
)
24+
]
25+
)]
26+
class PaginatedGroupResponseSchemaSchema {}

0 commit comments

Comments
 (0)