@@ -247,7 +247,112 @@ public function create_project(Request $request)
247
247
'uuid ' => $ project ->uuid ,
248
248
'name ' => $ project ->name ,
249
249
'description ' => $ project ->description ,
250
- ])->status (201 );
250
+ ])->setStatusCode (201 );
251
+ }
252
+
253
+ #[OA \Patch(
254
+ summary: 'Update Project ' ,
255
+ description: 'Update Project. ' ,
256
+ path: '/projects/{uuid} ' ,
257
+ security: [
258
+ ['bearerAuth ' => []],
259
+ ],
260
+ tags: ['Projects ' ],
261
+ requestBody: new OA \RequestBody (
262
+ required: true ,
263
+ description: 'Project updated. ' ,
264
+ content: new OA \MediaType (
265
+ mediaType: 'application/json ' ,
266
+ schema: new OA \Schema (
267
+ type: 'object ' ,
268
+ properties: [
269
+ 'name ' => ['type ' => 'string ' , 'description ' => 'The name of the project. ' ],
270
+ 'description ' => ['type ' => 'string ' , 'description ' => 'The description of the project. ' ],
271
+ ],
272
+ ),
273
+ ),
274
+ ),
275
+ responses: [
276
+ new OA \Response (
277
+ response: 201 ,
278
+ description: 'Project updated. ' ,
279
+ content: [
280
+ new OA \MediaType (
281
+ mediaType: 'application/json ' ,
282
+ schema: new OA \Schema (
283
+ type: 'object ' ,
284
+ properties: [
285
+ 'uuid ' => ['type ' => 'string ' , 'example ' => 'og888os ' ],
286
+ 'name ' => ['type ' => 'string ' , 'example ' => 'Project Name ' ],
287
+ 'description ' => ['type ' => 'string ' , 'example ' => 'Project Description ' ],
288
+ ]
289
+ )
290
+ ),
291
+ ]),
292
+ new OA \Response (
293
+ response: 401 ,
294
+ ref: '#/components/responses/401 ' ,
295
+ ),
296
+ new OA \Response (
297
+ response: 400 ,
298
+ ref: '#/components/responses/400 ' ,
299
+ ),
300
+ new OA \Response (
301
+ response: 404 ,
302
+ ref: '#/components/responses/404 ' ,
303
+ ),
304
+ ]
305
+ )]
306
+ public function update_project (Request $ request )
307
+ {
308
+ $ allowedFields = ['name ' , 'description ' ];
309
+
310
+ $ teamId = getTeamIdFromToken ();
311
+ if (is_null ($ teamId )) {
312
+ return invalidTokenResponse ();
313
+ }
314
+
315
+ $ return = validateIncomingRequest ($ request );
316
+ if ($ return instanceof \Illuminate \Http \JsonResponse) {
317
+ return $ return ;
318
+ }
319
+ $ validator = customApiValidator ($ request ->all (), [
320
+ 'name ' => 'string|max:255|nullable ' ,
321
+ 'description ' => 'string|nullable ' ,
322
+ ]);
323
+
324
+ $ extraFields = array_diff (array_keys ($ request ->all ()), $ allowedFields );
325
+ if ($ validator ->fails () || ! empty ($ extraFields )) {
326
+ $ errors = $ validator ->errors ();
327
+ if (! empty ($ extraFields )) {
328
+ foreach ($ extraFields as $ field ) {
329
+ $ errors ->add ($ field , 'This field is not allowed. ' );
330
+ }
331
+ }
332
+
333
+ return response ()->json ([
334
+ 'message ' => 'Validation failed. ' ,
335
+ 'errors ' => $ errors ,
336
+ ], 422 );
337
+ }
338
+ $ uuid = $ request ->uuid ;
339
+ if (! $ uuid ) {
340
+ return response ()->json (['message ' => 'Uuid is required. ' ], 422 );
341
+ }
342
+
343
+ $ project = Project::whereTeamId ($ teamId )->whereUuid ($ uuid )->first ();
344
+ if (! $ project ) {
345
+ return response ()->json (['message ' => 'Project not found. ' ], 404 );
346
+ }
347
+
348
+ $ project ->update ($ request ->only ($ allowedFields ));
349
+
350
+ return response ()->json ([
351
+ 'uuid ' => $ project ->uuid ,
352
+ 'name ' => $ project ->name ,
353
+ 'description ' => $ project ->description ,
354
+ ])->setStatusCode (201 );
355
+
251
356
}
252
357
253
358
#[OA \Delete(
0 commit comments