Skip to content

Commit 583f112

Browse files
feat: Add OpenAPI documentation to "getAll" method
- Add controller's response to OpenAPI schema
1 parent 9ed27c0 commit 583f112

2 files changed

Lines changed: 112 additions & 2 deletions

File tree

app/Http/Controllers/Apis/Protected/Main/OAuth2AuditLogController.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
**/
1414

1515
use App\Models\Foundation\Main\Repositories\IAuditLogRepository;
16+
use App\Security\SummitScopes;
17+
use Illuminate\Http\Response;
1618
use models\main\SummitAttendeeBadgeAuditLog;
1719
use models\main\SummitAuditLog;
1820
use models\main\SummitEventAuditLog;
1921
use models\oauth2\IResourceServerContext;
2022
use models\summit\SummitAttendeeBadge;
2123
use ModelSerializers\SerializerRegistry;
24+
use OpenApi\Attributes as OA;
2225

2326
/**
2427
* Class OAuth2AuditLogController
@@ -46,6 +49,77 @@ public function __construct
4649
/**
4750
* @return mixed
4851
*/
52+
#[OA\Get(
53+
path: "/api/v1/audit-logs",
54+
description: "Get all audit logs with filtering capabilities. Requires OAuth2 authentication with appropriate scope.",
55+
summary: 'Get all audit logs',
56+
operationId: 'getAllAuditLogs',
57+
tags: ['Audit Logs'],
58+
security: [['summit_rsvp_oauth2' => [
59+
SummitScopes::ReadAllSummitData,
60+
]]],
61+
parameters: [
62+
new OA\Parameter(
63+
name: 'access_token',
64+
in: 'query',
65+
required: false,
66+
description: 'OAuth2 access token (alternative to Authorization: Bearer)',
67+
schema: new OA\Schema(type: 'string', example: 'eyJhbGciOi...')
68+
),
69+
new OA\Parameter(
70+
name: 'page',
71+
in: 'query',
72+
required: false,
73+
description: 'Page number for pagination',
74+
schema: new OA\Schema(type: 'integer', example: 1)
75+
),
76+
new OA\Parameter(
77+
name: 'per_page',
78+
in: 'query',
79+
required: false,
80+
description: 'Items per page',
81+
schema: new OA\Schema(type: 'integer', example: 10, maximum: 100)
82+
),
83+
new OA\Parameter(
84+
name: 'filter[]',
85+
in: 'query',
86+
required: false,
87+
description: 'Filter expressions. Format: field<op>value. Available fields: class_name (required, ==), user_id (==), summit_id (==), event_id (==), entity_id (==), user_email (==, =@, @@), user_full_name (==, =@, @@), action (=@, @@), metadata (==, =@, @@), created (==, >, <, >=, <=, []). class_name must be one of: SummitAuditLog, SummitEventAuditLog, SummitAttendeeBadgeAuditLog',
88+
style: 'form',
89+
explode: true,
90+
schema: new OA\Schema(
91+
type: 'array',
92+
items: new OA\Items(type: 'string', example: 'class_name==SummitAuditLog')
93+
)
94+
),
95+
new OA\Parameter(
96+
name: 'order',
97+
in: 'query',
98+
required: false,
99+
description: 'Order by field(s). Available fields: id, user_id, event_id, entity_id, created, user_email, user_full_name, metadata. Use "-" prefix for descending order.',
100+
schema: new OA\Schema(type: 'string', example: '-created')
101+
),
102+
new OA\Parameter(
103+
name: 'expand',
104+
in: 'query',
105+
required: false,
106+
description: 'Comma-separated list of related resources to include. Available relations: user, summit',
107+
schema: new OA\Schema(type: 'string', example: 'user,summit')
108+
),
109+
],
110+
responses: [
111+
new OA\Response(
112+
response: 200,
113+
description: 'Success - Returns paginated list of audit logs',
114+
content: new OA\JsonContent(ref: '#/components/schemas/PaginatedAuditLogsResponse')
115+
),
116+
new OA\Response(response: Response::HTTP_BAD_REQUEST, description: "Bad Request - Invalid parameters"),
117+
new OA\Response(response: Response::HTTP_UNAUTHORIZED, description: "Unauthorized - Invalid or missing access token"),
118+
new OA\Response(response: Response::HTTP_FORBIDDEN, description: "Forbidden - Insufficient permissions"),
119+
new OA\Response(response: Response::HTTP_PRECONDITION_FAILED, description: "Validation Error - Missing required filters"),
120+
new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: "Server Error")
121+
]
122+
)]
49123
public function getAll(){
50124

51125
return $this->_getAll(
@@ -97,4 +171,4 @@ function () {
97171
}
98172
);
99173
}
100-
}
174+
}

app/Swagger/schemas.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,40 @@ class RSVPUpdateRequestSchema_{
348348

349349
]
350350
)]
351-
class RSVPAdminAddRequestSchema {}
351+
class RSVPAdminAddRequestSchema {}
352+
353+
#[OA\Schema(
354+
schema: 'AuditLog',
355+
type: 'object',
356+
properties: [
357+
new OA\Property(property: 'id', type: 'integer', example: 1, description: 'Unique identifier'),
358+
new OA\Property(property: 'created', type: 'integer', example: 1630500518, description: 'Creation timestamp (Unix epoch)'),
359+
new OA\Property(property: 'last_edited', type: 'integer', example: 1630500518, description: 'Last modification timestamp (Unix epoch)'),
360+
new OA\Property(property: 'class_name', type: 'string', example: 'SummitAuditLog', description: 'Audit log type: SummitAuditLog, SummitEventAuditLog, or SummitAttendeeBadgeAuditLog'),
361+
new OA\Property(property: 'action', type: 'string', example: 'UPDATED', description: 'Action performed (e.g., CREATED, UPDATED, DELETED)'),
362+
new OA\Property(property: 'metadata', type: 'string', example: 'Additional audit information', description: 'Metadata about the audit action', nullable: true),
363+
new OA\Property(property: 'user_id', type: 'integer', example: 123, description: 'ID of the user who performed the action'),
364+
new OA\Property(property: 'summit_id', type: 'integer', example: 45, description: 'Summit ID (for SummitAuditLog, SummitEventAuditLog, SummitAttendeeBadgeAuditLog)', nullable: true),
365+
new OA\Property(property: 'event_id', type: 'integer', example: 789, description: 'Event ID (for SummitEventAuditLog)', nullable: true),
366+
new OA\Property(property: 'attendee_badge_id', type: 'integer', example: 456, description: 'Attendee Badge ID (for SummitAttendeeBadgeAuditLog)', nullable: true),
367+
]
368+
)]
369+
class AuditLogSchema {}
370+
371+
#[OA\Schema(
372+
schema: 'PaginatedAuditLogsResponse',
373+
allOf: [
374+
new OA\Schema(ref: '#/components/schemas/PaginateDataSchemaResponse'),
375+
new OA\Schema(
376+
type: 'object',
377+
properties: [
378+
new OA\Property(
379+
property: 'data',
380+
type: 'array',
381+
items: new OA\Items(ref: '#/components/schemas/AuditLog')
382+
)
383+
]
384+
)
385+
]
386+
)]
387+
class PaginatedAuditLogsResponseSchema {}

0 commit comments

Comments
 (0)