1616 **/
1717
1818use App \Rules \Boolean ;
19+ use App \Security \CompanyScopes ;
20+ use App \Security \SummitScopes ;
1921use App \Services \Model \ICompanyService ;
2022use Illuminate \Http \Request as LaravelRequest ;
2123use Illuminate \Http \Response ;
2628use ModelSerializers \SerializerRegistry ;
2729use OpenApi \Attributes as OA ;
2830
31+
32+ #[OA \SecurityScheme(
33+ type: 'oauth2 ' ,
34+ securityScheme: 'OAuth2CompaniesApiControllerAuthSchema ' ,
35+ flows: [
36+ new OA \Flow (
37+ authorizationUrl: L5_SWAGGER_CONST_AUTH_URL ,
38+ tokenUrl: L5_SWAGGER_CONST_TOKEN_URL ,
39+ flow: 'authorizationCode ' ,
40+ scopes: [
41+ CompanyScopes::Read => 'Read Data ' ,
42+ CompanyScopes::Write => 'Write Data ' ,
43+ SummitScopes::ReadSummitData => 'Read Summit Data ' ,
44+ SummitScopes::ReadAllSummitData => 'Read All Summit Data ' ,
45+ SummitScopes::WriteSummitData => 'Write Summit Data ' ,
46+ ],
47+ ),
48+ ],
49+ )
50+ ]
51+ class OAuth2CompaniesApiControllerAuthSchema
52+ {
53+ }
54+
55+
2956/**
3057 * Class OAuth2CompaniesApiController
3158 * @package App\Http\Controllers
3461 path: "/api/v1/companies/{id} " ,
3562 summary: "Get a specific company " ,
3663 description: "Returns detailed information about a specific company " ,
64+ security: [
65+ [
66+ "OAuth2CompaniesApiControllerAuthSchema " => [
67+ CompanyScopes::Read,
68+ ]
69+ ]
70+ ],
71+ tags: ["Companies " ],
72+ parameters: [
73+ new OA \Parameter (
74+ name: "id " ,
75+ in: "path " ,
76+ required: true ,
77+ description: "Company ID " ,
78+ schema: new OA \Schema (type: "integer " )
79+ ),
80+ new OA \Parameter (
81+ name: "expand " ,
82+ in: "query " ,
83+ required: false ,
84+ description: "Expand related entities. Available expansions: sponsorships, project_sponsorships " ,
85+ schema: new OA \Schema (type: "string " )
86+ ),
87+ new OA \Parameter (
88+ name: "relations " ,
89+ in: "query " ,
90+ required: false ,
91+ description: "Load relations. Available: sponsorships, project_sponsorships " ,
92+ schema: new OA \Schema (type: "string " )
93+ ),
94+ ],
95+ responses: [
96+ new OA \Response (
97+ response: Response::HTTP_OK ,
98+ description: "Success " ,
99+ content: new OA \JsonContent (ref: "#/components/schemas/Company " )
100+ ),
101+ new OA \Response (response: Response::HTTP_NOT_FOUND , description: "Company not found " ),
102+ ]
103+ )]
104+ /**
105+ * Class OAuth2CompaniesApiController
106+ * @package App\Http\Controllers
107+ */
108+ #[OA \Get(
109+ path: "/api/public/v1/companies/{id} " ,
110+ summary: "Get a specific company (Public) " ,
111+ description: "Returns detailed information about a specific company " ,
37112 tags: ["Companies " ],
38113 parameters: [
39114 new OA \Parameter (
71146 path: "/api/v1/companies " ,
72147 summary: "Create a new company " ,
73148 description: "Creates a new company " ,
74- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
149+ security: [
150+ [
151+ "OAuth2CompaniesApiControllerAuthSchema " => [
152+ CompanyScopes::Write,
153+ ]
154+ ]
155+ ],
75156 tags: ["Companies " ],
76157 requestBody: new OA \RequestBody (
77158 required: true ,
93174 path: "/api/v1/companies/{id} " ,
94175 summary: "Update a company " ,
95176 description: "Updates an existing company " ,
96- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
177+ security: [
178+ [
179+ "OAuth2CompaniesApiControllerAuthSchema " => [
180+ CompanyScopes::Write,
181+ ]
182+ ]
183+ ],
97184 tags: ["Companies " ],
98185 parameters: [
99186 new OA \Parameter (
125212 path: "/api/v1/companies/{id} " ,
126213 summary: "Delete a company " ,
127214 description: "Deletes a company " ,
128- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
215+ security: [
216+ [
217+ "OAuth2CompaniesApiControllerAuthSchema " => [
218+ CompanyScopes::Write,
219+ ]
220+ ]
221+ ],
129222 tags: ["Companies " ],
130223 parameters: [
131224 new OA \Parameter (
@@ -169,11 +262,10 @@ final class OAuth2CompaniesApiController extends OAuth2ProtectedController
169262 */
170263 public function __construct
171264 (
172- ICompanyRepository $ company_repository ,
265+ ICompanyRepository $ company_repository ,
173266 IResourceServerContext $ resource_server_context ,
174- ICompanyService $ service
175- )
176- {
267+ ICompanyService $ service
268+ ) {
177269 parent ::__construct ($ resource_server_context );
178270 $ this ->repository = $ company_repository ;
179271 $ this ->service = $ service ;
@@ -183,7 +275,75 @@ public function __construct
183275 path: "/api/v1/companies " ,
184276 summary: "Get all companies " ,
185277 description: "Returns a paginated list of companies. Allows ordering, filtering and pagination. " ,
186- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
278+ security: [
279+ [
280+ "OAuth2CompaniesApiControllerAuthSchema " => [
281+ CompanyScopes::Read,
282+ SummitScopes::ReadSummitData,
283+ SummitScopes::ReadAllSummitData,
284+ ]
285+ ]
286+ ],
287+ tags: ["Companies " ],
288+ parameters: [
289+ new OA \Parameter (
290+ name: 'page ' ,
291+ in: 'query ' ,
292+ required: false ,
293+ schema: new OA \Schema (type: 'integer ' ),
294+ description: 'The page number '
295+ ),
296+ new OA \Parameter (
297+ name: 'per_page ' ,
298+ in: 'query ' ,
299+ required: false ,
300+ schema: new OA \Schema (type: 'integer ' ),
301+ description: 'The number of pages in each page ' ,
302+ ),
303+ new OA \Parameter (
304+ name: "filter[] " ,
305+ in: "query " ,
306+ required: false ,
307+ description: "Filter companies. Available filters: name (=@, ==, @@), member_level (=@, ==, @@), display_on_site (==) " ,
308+ schema: new OA \Schema (type: "array " , items: new OA \Items (type: "string " )),
309+ explode: true
310+ ),
311+ new OA \Parameter (
312+ name: "order " ,
313+ in: "query " ,
314+ required: false ,
315+ description: "Order by field. Valid fields: id, name, member_level " ,
316+ schema: new OA \Schema (type: "string " )
317+ ),
318+ new OA \Parameter (
319+ name: "expand " ,
320+ in: "query " ,
321+ required: false ,
322+ description: "Expand related entities. Available expansions: sponsorships, project_sponsorships " ,
323+ schema: new OA \Schema (type: "string " )
324+ ),
325+ new OA \Parameter (
326+ name: "relations " ,
327+ in: "query " ,
328+ required: false ,
329+ description: "Load relations. Available: sponsorships, project_sponsorships " ,
330+ schema: new OA \Schema (type: "string " )
331+ ),
332+ ],
333+ responses: [
334+ new OA \Response (
335+ response: Response::HTTP_OK ,
336+ description: "Success " ,
337+ content: new OA \JsonContent (ref: "#/components/schemas/PaginatedCompaniesResponse " )
338+ ),
339+ new OA \Response (response: Response::HTTP_BAD_REQUEST , description: "Bad Request " ),
340+ ]
341+ )]
342+
343+ #[OA \Get(
344+ path: "/api/public/v1/companies " ,
345+ summary: "Get all companies (Public) " ,
346+ description: "Returns a paginated list of companies. Allows ordering, filtering and pagination. " ,
187347 tags: ["Companies " ],
188348 parameters: [
189349 new OA \Parameter (
@@ -247,14 +407,14 @@ function () {
247407 return [
248408 'name ' => ['=@ ' , '== ' , '@@ ' ],
249409 'member_level ' => ['=@ ' , '== ' , '@@ ' ],
250- 'display_on_site ' => [ '== ' ],
410+ 'display_on_site ' => ['== ' ],
251411 ];
252412 },
253413 function () {
254414 return [
255415 'name ' => 'sometimes|string ' ,
256416 'member_level ' => 'sometimes|string ' ,
257- 'display_on_site ' => ['sometimes ' , new Boolean ],
417+ 'display_on_site ' => ['sometimes ' , new Boolean ],
258418 ];
259419 },
260420 function () {
@@ -268,7 +428,7 @@ function ($filter) {
268428 return $ filter ;
269429 },
270430 function () {
271- return $ this ->getEntitySerializerType ();
431+ return $ this ->getEntitySerializerType ();
272432 }
273433 );
274434 }
@@ -292,7 +452,8 @@ protected function addEntity(array $payload): IEntity
292452 return $ this ->service ->addCompany ($ payload );
293453 }
294454
295- protected function addEntitySerializerType (){
455+ protected function addEntitySerializerType ()
456+ {
296457 return $ this ->getEntitySerializerType ();
297458 }
298459
@@ -320,7 +481,8 @@ protected function getEntitySerializerType()
320481 SerializerRegistry::SerializerType_Public;
321482 }
322483
323- protected function updateEntitySerializerType (){
484+ protected function updateEntitySerializerType ()
485+ {
324486 return $ this ->getEntitySerializerType ();
325487 }
326488 /**
@@ -347,7 +509,13 @@ protected function updateEntity($id, array $payload): IEntity
347509 path: "/api/v1/companies/{id}/logo " ,
348510 summary: "Add company logo " ,
349511 description: "Uploads a logo image for the company " ,
350- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
512+ security: [
513+ [
514+ "OAuth2CompaniesApiControllerAuthSchema " => [
515+ CompanyScopes::Write,
516+ ]
517+ ]
518+ ],
351519 tags: ["Companies " ],
352520 parameters: [
353521 new OA \Parameter (
@@ -407,7 +575,13 @@ public function addCompanyLogo(LaravelRequest $request, $company_id)
407575 path: "/api/v1/companies/{id}/logo " ,
408576 summary: "Delete company logo " ,
409577 description: "Removes the logo image from the company " ,
410- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
578+ security: [
579+ [
580+ "OAuth2CompaniesApiControllerAuthSchema " => [
581+ CompanyScopes::Write,
582+ ]
583+ ]
584+ ],
411585 tags: ["Companies " ],
412586 parameters: [
413587 new OA \Parameter (
@@ -440,7 +614,13 @@ public function deleteCompanyLogo($company_id)
440614 path: "/api/v1/companies/{id}/logo/big " ,
441615 summary: "Add company big logo " ,
442616 description: "Uploads a big logo image for the company " ,
443- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
617+ security: [
618+ [
619+ "OAuth2CompaniesApiControllerAuthSchema " => [
620+ CompanyScopes::Write,
621+ ]
622+ ]
623+ ],
444624 tags: ["Companies " ],
445625 parameters: [
446626 new OA \Parameter (
@@ -499,7 +679,13 @@ public function addCompanyBigLogo(LaravelRequest $request, $company_id)
499679 path: "/api/v1/companies/{id}/logo/big " ,
500680 summary: "Delete company big logo " ,
501681 description: "Removes the big logo image from the company " ,
502- security: [["oauth2_security_scope " => ["openid " , "profile " , "email " ]]],
682+ security: [
683+ [
684+ "OAuth2CompaniesApiControllerAuthSchema " => [
685+ CompanyScopes::Write,
686+ ]
687+ ]
688+ ],
503689 tags: ["Companies " ],
504690 parameters: [
505691 new OA \Parameter (
0 commit comments