Skip to content

Commit 00328fa

Browse files
andrestejerina97matiasperrone
authored andcommitted
feat: Extend Swagger Coverage for controller OAuth2SpeakersPromoCodesApiController
1 parent 29166a0 commit 00328fa

File tree

3 files changed

+399
-0
lines changed

3 files changed

+399
-0
lines changed
Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
<?php namespace App\Http\Controllers;
2+
/**
3+
* Copyright 2023 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
use Illuminate\Http\Request;
16+
use Illuminate\Http\Response;
17+
use OpenApi\Attributes as OA;
18+
use ModelSerializers\SerializerRegistry;
19+
20+
class OAuth2SpeakersPromoCodesApiController extends OAuth2ProtectedController
21+
{
22+
/**
23+
* @param int $promo_code_id
24+
* @param Request $request
25+
* @return mixed
26+
*/
27+
#[OA\Get(
28+
path: "/api/v1/summits/{id}/speakers-promo-codes/{promo_code_id}/speakers",
29+
operationId: "getSpeakersPromoCodeSpeakers",
30+
description: "Get speakers assigned to a speakers promo code",
31+
tags: ["Speakers Promo Codes"],
32+
parameters: [
33+
new OA\Parameter(
34+
name: "id",
35+
description: "Summit ID",
36+
in: "path",
37+
required: true,
38+
schema: new OA\Schema(type: "integer", format: "int64")
39+
),
40+
new OA\Parameter(
41+
name: "promo_code_id",
42+
description: "Promo Code ID",
43+
in: "path",
44+
required: true,
45+
schema: new OA\Schema(type: "integer", format: "int64")
46+
),
47+
new OA\Parameter(
48+
name: "expand",
49+
description: "Expandable relations",
50+
in: "query",
51+
required: false,
52+
schema: new OA\Schema(type: "string", default: "")
53+
),
54+
new OA\Parameter(
55+
name: "fields",
56+
description: "Fields to retrieve",
57+
in: "query",
58+
required: false,
59+
schema: new OA\Schema(type: "string", default: "")
60+
),
61+
new OA\Parameter(
62+
name: "relations",
63+
description: "Relations to include",
64+
in: "query",
65+
required: false,
66+
schema: new OA\Schema(type: "string", default: "")
67+
),
68+
new OA\Parameter(
69+
name: "page",
70+
description: "Page number",
71+
in: "query",
72+
required: false,
73+
schema: new OA\Schema(type: "integer", default: 1)
74+
),
75+
new OA\Parameter(
76+
name: "per_page",
77+
description: "Items per page",
78+
in: "query",
79+
required: false,
80+
schema: new OA\Schema(type: "integer", default: 10)
81+
),
82+
],
83+
responses: [
84+
new OA\Response(
85+
response: Response::HTTP_OK,
86+
description: "List of speakers assigned to promo code",
87+
content: new OA\JsonContent(ref: "#/components/schemas/PaginateDataSchemaResponse")
88+
),
89+
new OA\Response(
90+
response: Response::HTTP_UNAUTHORIZED,
91+
description: "Unauthorized"
92+
),
93+
new OA\Response(
94+
response: Response::HTTP_FORBIDDEN,
95+
description: "Forbidden"
96+
),
97+
new OA\Response(
98+
response: Response::HTTP_NOT_FOUND,
99+
description: "Not found"
100+
),
101+
new OA\Response(
102+
response: Response::HTTP_INTERNAL_SERVER_ERROR,
103+
description: "Server Error"
104+
),
105+
]
106+
)]
107+
public function getSpeakersPromoCodeSpeakers($id, $promo_code_id, Request $request)
108+
{
109+
try {
110+
return $this->_getAll(
111+
function () use ($id, $promo_code_id) {
112+
return \App\Models\Summit\SpeakersSummitRegistrationPromoCode::findOrFail($promo_code_id)
113+
->getOwners();
114+
},
115+
SerializerRegistry::SerializerType_Public,
116+
[],
117+
function ($query) {},
118+
$request,
119+
null
120+
);
121+
} catch (\Exception $ex) {
122+
\Log::warning($ex);
123+
return $this->error500();
124+
}
125+
}
126+
127+
/**
128+
* @param int $promo_code_id
129+
* @param int $speaker_id
130+
* @param Request $request
131+
* @return mixed
132+
*/
133+
#[OA\Post(
134+
path: "/api/v1/summits/{id}/speakers-promo-codes/{promo_code_id}/speakers",
135+
operationId: "addSpeakerToPromoCode",
136+
description: "Add a speaker to a speakers promo code",
137+
tags: ["Speakers Promo Codes"],
138+
parameters: [
139+
new OA\Parameter(
140+
name: "id",
141+
description: "Summit ID",
142+
in: "path",
143+
required: true,
144+
schema: new OA\Schema(type: "integer", format: "int64")
145+
),
146+
new OA\Parameter(
147+
name: "promo_code_id",
148+
description: "Promo Code ID",
149+
in: "path",
150+
required: true,
151+
schema: new OA\Schema(type: "integer", format: "int64")
152+
),
153+
],
154+
requestBody: new OA\RequestBody(
155+
description: "Speaker to add",
156+
required: true,
157+
content: new OA\JsonContent(
158+
required: ["speaker_id"],
159+
properties: [
160+
new OA\Property(
161+
property: "speaker_id",
162+
description: "Speaker ID to assign",
163+
type: "integer",
164+
format: "int64"
165+
),
166+
]
167+
)
168+
),
169+
responses: [
170+
new OA\Response(
171+
response: Response::HTTP_CREATED,
172+
description: "Speaker added to promo code successfully"
173+
),
174+
new OA\Response(
175+
response: Response::HTTP_BAD_REQUEST,
176+
description: "Bad Request"
177+
),
178+
new OA\Response(
179+
response: Response::HTTP_UNAUTHORIZED,
180+
description: "Unauthorized"
181+
),
182+
new OA\Response(
183+
response: Response::HTTP_FORBIDDEN,
184+
description: "Forbidden"
185+
),
186+
new OA\Response(
187+
response: Response::HTTP_NOT_FOUND,
188+
description: "Not found"
189+
),
190+
new OA\Response(
191+
response: Response::HTTP_PRECONDITION_FAILED,
192+
description: "Validation Error"
193+
),
194+
new OA\Response(
195+
response: Response::HTTP_INTERNAL_SERVER_ERROR,
196+
description: "Server Error"
197+
),
198+
]
199+
)]
200+
public function addSpeakerToPromoCode($id, $promo_code_id, Request $request)
201+
{
202+
try {
203+
$payload = $request->all();
204+
205+
if (!isset($payload['speaker_id'])) {
206+
return $this->error400();
207+
}
208+
209+
$promo_code = \App\Models\Summit\SpeakersSummitRegistrationPromoCode::findOrFail($promo_code_id);
210+
$speaker = \App\Models\Presentation\PresentationSpeaker::findOrFail($payload['speaker_id']);
211+
212+
$promo_code->addOwner($speaker);
213+
214+
return $this->created();
215+
} catch (\ModelNotFoundException $ex) {
216+
return $this->error404();
217+
} catch (\ValidationException $ex) {
218+
return $this->error412($ex->getMessages());
219+
} catch (\Exception $ex) {
220+
\Log::warning($ex);
221+
return $this->error500();
222+
}
223+
}
224+
225+
/**
226+
* @param int $promo_code_id
227+
* @param int $speaker_id
228+
* @param Request $request
229+
* @return mixed
230+
*/
231+
#[OA\Delete(
232+
path: "/api/v1/summits/{id}/speakers-promo-codes/{promo_code_id}/speakers/{speaker_id}",
233+
operationId: "removeSpeakerFromPromoCode",
234+
description: "Remove a speaker from a speakers promo code",
235+
tags: ["Speakers Promo Codes"],
236+
parameters: [
237+
new OA\Parameter(
238+
name: "id",
239+
description: "Summit ID",
240+
in: "path",
241+
required: true,
242+
schema: new OA\Schema(type: "integer", format: "int64")
243+
),
244+
new OA\Parameter(
245+
name: "promo_code_id",
246+
description: "Promo Code ID",
247+
in: "path",
248+
required: true,
249+
schema: new OA\Schema(type: "integer", format: "int64")
250+
),
251+
new OA\Parameter(
252+
name: "speaker_id",
253+
description: "Speaker ID to remove",
254+
in: "path",
255+
required: true,
256+
schema: new OA\Schema(type: "integer", format: "int64")
257+
),
258+
],
259+
responses: [
260+
new OA\Response(
261+
response: Response::HTTP_NO_CONTENT,
262+
description: "Speaker removed from promo code successfully"
263+
),
264+
new OA\Response(
265+
response: Response::HTTP_UNAUTHORIZED,
266+
description: "Unauthorized"
267+
),
268+
new OA\Response(
269+
response: Response::HTTP_FORBIDDEN,
270+
description: "Forbidden"
271+
),
272+
new OA\Response(
273+
response: Response::HTTP_NOT_FOUND,
274+
description: "Not found"
275+
),
276+
new OA\Response(
277+
response: Response::HTTP_INTERNAL_SERVER_ERROR,
278+
description: "Server Error"
279+
),
280+
]
281+
)]
282+
public function removeSpeakerFromPromoCode($id, $promo_code_id, $speaker_id, Request $request)
283+
{
284+
try {
285+
$promo_code = \App\Models\Summit\SpeakersSummitRegistrationPromoCode::findOrFail($promo_code_id);
286+
$speaker = \App\Models\Presentation\PresentationSpeaker::findOrFail($speaker_id);
287+
288+
$promo_code->removeOwner($speaker);
289+
290+
return $this->deleted();
291+
} catch (\ModelNotFoundException $ex) {
292+
return $this->error404();
293+
} catch (\Exception $ex) {
294+
\Log::warning($ex);
295+
return $this->error500();
296+
}
297+
}
298+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace App\Swagger\schemas;
4+
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Schema(
8+
schema: "SpeakersSummitRegistrationPromoCodeCSV",
9+
description: "Speakers Summit Registration Promo Code CSV Export",
10+
required: ["id", "code"]
11+
)]
12+
class SpeakersSummitRegistrationPromoCodeCSVSchemas
13+
{
14+
#[OA\Property(description: "Promo Code ID", type: "integer")]
15+
public int $id;
16+
17+
#[OA\Property(description: "Promo Code Value", type: "string")]
18+
public string $code;
19+
20+
#[OA\Property(description: "Description", type: "string", nullable: true)]
21+
public ?string $description;
22+
23+
#[OA\Property(description: "Discount Amount", type: "number")]
24+
public float $discount;
25+
26+
#[OA\Property(description: "Number of Uses", type: "integer")]
27+
public int $number_of_uses;
28+
29+
#[OA\Property(description: "Remaining Quantity", type: "integer")]
30+
public int $remaining_quantity;
31+
32+
#[OA\Property(description: "Owner Speaker Names (pipe separated)", type: "string")]
33+
public string $owner_name;
34+
35+
#[OA\Property(description: "Owner Speaker Emails (pipe separated)", type: "string")]
36+
public string $owner_email;
37+
38+
#[OA\Property(description: "Valid From Date", type: "string", format: "date-time", nullable: true)]
39+
public ?string $valid_from_date;
40+
41+
#[OA\Property(description: "Valid Until Date", type: "string", format: "date-time", nullable: true)]
42+
public ?string $valid_until_date;
43+
44+
#[OA\Property(description: "Is Active", type: "boolean")]
45+
public bool $is_active;
46+
}

0 commit comments

Comments
 (0)