@@ -135,13 +135,190 @@ public function environment_details(Request $request)
135
135
if (is_null ($ teamId )) {
136
136
return invalidTokenResponse ();
137
137
}
138
- $ project = Project::whereTeamId ($ teamId )->whereUuid (request ()->uuid )->first ();
139
- $ environment = $ project ->environments ()->whereName (request ()->environment_name )->first ();
138
+ if (! $ request ->uuid ) {
139
+ return response ()->json (['message ' => 'Uuid is required. ' ], 422 );
140
+ }
141
+ if (! $ request ->environment_name ) {
142
+ return response ()->json (['message ' => 'Environment name is required. ' ], 422 );
143
+ }
144
+ $ project = Project::whereTeamId ($ teamId )->whereUuid ($ request ->uuid )->first ();
145
+ $ environment = $ project ->environments ()->whereName ($ request ->environment_name )->first ();
140
146
if (! $ environment ) {
141
147
return response ()->json (['message ' => 'Environment not found. ' ], 404 );
142
148
}
143
149
$ environment = $ environment ->load (['applications ' , 'postgresqls ' , 'redis ' , 'mongodbs ' , 'mysqls ' , 'mariadbs ' , 'services ' ]);
144
150
145
151
return response ()->json (serializeApiResponse ($ environment ));
146
152
}
153
+
154
+ #[OA \Post(
155
+ summary: 'Create Project ' ,
156
+ description: 'Create Project. ' ,
157
+ path: '/projects ' ,
158
+ security: [
159
+ ['bearerAuth ' => []],
160
+ ],
161
+ tags: ['Projects ' ],
162
+ requestBody: new OA \RequestBody (
163
+ required: true ,
164
+ description: 'Project created. ' ,
165
+ content: new OA \MediaType (
166
+ mediaType: 'application/json ' ,
167
+ schema: new OA \Schema (
168
+ type: 'object ' ,
169
+ properties: [
170
+ 'name ' => ['type ' => 'string ' , 'description ' => 'The name of the project. ' ],
171
+ 'description ' => ['type ' => 'string ' , 'description ' => 'The description of the project. ' ],
172
+ ],
173
+ ),
174
+ ),
175
+ ),
176
+ responses: [
177
+ new OA \Response (
178
+ response: 201 ,
179
+ description: 'Project created. ' ,
180
+ content: [
181
+ new OA \MediaType (
182
+ mediaType: 'application/json ' ,
183
+ schema: new OA \Schema (
184
+ type: 'object ' ,
185
+ properties: [
186
+ 'uuid ' => ['type ' => 'string ' , 'example ' => 'og888os ' ],
187
+ 'name ' => ['type ' => 'string ' , 'example ' => 'Project Name ' ],
188
+ 'description ' => ['type ' => 'string ' , 'example ' => 'Project Description ' ],
189
+ ]
190
+ )
191
+ ),
192
+ ]),
193
+ new OA \Response (
194
+ response: 401 ,
195
+ ref: '#/components/responses/401 ' ,
196
+ ),
197
+ new OA \Response (
198
+ response: 400 ,
199
+ ref: '#/components/responses/400 ' ,
200
+ ),
201
+ new OA \Response (
202
+ response: 404 ,
203
+ ref: '#/components/responses/404 ' ,
204
+ ),
205
+ ]
206
+ )]
207
+ public function create_project (Request $ request )
208
+ {
209
+ $ allowedFields = ['name ' , 'description ' ];
210
+
211
+ $ teamId = getTeamIdFromToken ();
212
+ if (is_null ($ teamId )) {
213
+ return invalidTokenResponse ();
214
+ }
215
+
216
+ $ return = validateIncomingRequest ($ request );
217
+ if ($ return instanceof \Illuminate \Http \JsonResponse) {
218
+ return $ return ;
219
+ }
220
+ $ validator = customApiValidator ($ request ->all (), [
221
+ 'name ' => 'string|max:255 ' ,
222
+ 'description ' => 'string|nullable ' ,
223
+ ]);
224
+
225
+ $ extraFields = array_diff (array_keys ($ request ->all ()), $ allowedFields );
226
+ if ($ validator ->fails () || ! empty ($ extraFields )) {
227
+ $ errors = $ validator ->errors ();
228
+ if (! empty ($ extraFields )) {
229
+ foreach ($ extraFields as $ field ) {
230
+ $ errors ->add ($ field , 'This field is not allowed. ' );
231
+ }
232
+ }
233
+
234
+ return response ()->json ([
235
+ 'message ' => 'Validation failed. ' ,
236
+ 'errors ' => $ errors ,
237
+ ], 422 );
238
+ }
239
+
240
+ $ project = Project::create ([
241
+ 'name ' => $ request ->name ,
242
+ 'description ' => $ request ->description ,
243
+ 'team_id ' => $ teamId ,
244
+ ]);
245
+
246
+ return response ()->json ([
247
+ 'uuid ' => $ project ->uuid ,
248
+ 'name ' => $ project ->name ,
249
+ 'description ' => $ project ->description ,
250
+ ])->status (201 );
251
+ }
252
+
253
+ #[OA \Delete(
254
+ summary: 'Delete ' ,
255
+ description: 'Delete project by UUID. ' ,
256
+ path: '/projects/{uuid} ' ,
257
+ security: [
258
+ ['bearerAuth ' => []],
259
+ ],
260
+ tags: ['Projects ' ],
261
+ parameters: [
262
+ new OA \Parameter (
263
+ name: 'uuid ' ,
264
+ in: 'path ' ,
265
+ description: 'UUID of the application. ' ,
266
+ required: true ,
267
+ schema: new OA \Schema (
268
+ type: 'string ' ,
269
+ format: 'uuid ' ,
270
+ )
271
+ ),
272
+ ],
273
+ responses: [
274
+ new OA \Response (
275
+ response: 200 ,
276
+ description: 'Project deleted. ' ,
277
+ content: [
278
+ new OA \MediaType (
279
+ mediaType: 'application/json ' ,
280
+ schema: new OA \Schema (
281
+ type: 'object ' ,
282
+ properties: [
283
+ 'message ' => ['type ' => 'string ' , 'example ' => 'Project deleted. ' ],
284
+ ]
285
+ )
286
+ ),
287
+ ]),
288
+ new OA \Response (
289
+ response: 401 ,
290
+ ref: '#/components/responses/401 ' ,
291
+ ),
292
+ new OA \Response (
293
+ response: 400 ,
294
+ ref: '#/components/responses/400 ' ,
295
+ ),
296
+ new OA \Response (
297
+ response: 404 ,
298
+ ref: '#/components/responses/404 ' ,
299
+ ),
300
+ ]
301
+ )]
302
+ public function delete_project (Request $ request )
303
+ {
304
+ $ teamId = getTeamIdFromToken ();
305
+ if (is_null ($ teamId )) {
306
+ return invalidTokenResponse ();
307
+ }
308
+
309
+ if (! $ request ->uuid ) {
310
+ return response ()->json (['message ' => 'Uuid is required. ' ], 422 );
311
+ }
312
+ $ project = Project::whereTeamId ($ teamId )->whereUuid ($ request ->uuid )->first ();
313
+ if (! $ project ) {
314
+ return response ()->json (['message ' => 'Project not found. ' ], 404 );
315
+ }
316
+ if ($ project ->resource_count () > 0 ) {
317
+ return response ()->json (['message ' => 'Project has resources, so it cannot be deleted. ' ], 400 );
318
+ }
319
+
320
+ $ project ->delete ();
321
+
322
+ return response ()->json (['message ' => 'Project deleted. ' ]);
323
+ }
147
324
}
0 commit comments