@@ -360,4 +360,138 @@ public function delete($id)
360360 'message ' => 'Application deleted ' ,
361361 ], 200 );
362362 }
363+
364+ /**
365+ * @OA\Patch(
366+ * path="/apps/{id}/activate",
367+ * tags={"Applications"},
368+ * summary="Activate an application by ID",
369+ * operationId="activateApplication",
370+ * security={},
371+ * deprecated=true,
372+ * @OA\Parameter(
373+ * name="id",
374+ * in="path",
375+ * required=true,
376+ * description="ID of the application to activate",
377+ * @OA\Schema(type="integer", format="int64")
378+ * ),
379+ * @OA\Response(
380+ * response=200,
381+ * description="Successful response",
382+ * @OA\JsonContent(
383+ * type="object",
384+ * @OA\Property(property="data", type="array", @OA\Items(type="object"))
385+ * )
386+ * )
387+ * )
388+ */
389+ public function activate ($ id )
390+ {
391+ try {
392+ $ application = $ this ->repo ->find ($ id );
393+ } catch (\Exception $ e ) {
394+ Log::error ('Application not found ' , ['message ' => $ e ->getMessage ()]);
395+
396+ return response ()->json ([
397+ 'status ' => 404 ,
398+ 'error_message ' => 'Application does not exist ' ,
399+ 'errors ' => ['No matching Application ' ],
400+ ], 404 );
401+ }
402+
403+ if ($ application ->tenant_id !== $ this ->tenantId ) {
404+ return response ()->json ([
405+ 'status ' => 403 ,
406+ 'error_message ' => 'Application does not belong to tenant ' ,
407+ 'errors ' => ['Application does not belong to tenant ' ],
408+ ], 403 );
409+ }
410+
411+ try {
412+ $ this ->repo ->updateWithIdAndInput ($ id , ['is_active ' => true ]);
413+ } catch (\Exception $ e ) {
414+ Log::error ('Application not activated ' , ['message ' => $ e ->getMessage ()]);
415+
416+ return response ()->json ([
417+ 'status ' => 500 ,
418+ 'error_message ' => 'Unable to activate Application ' ,
419+ 'errors ' => [$ e ->getMessage ()],
420+ ], 500 );
421+ }
422+
423+ $ application = $ this ->repo ->find ($ id );
424+
425+ $ resource = new \League \Fractal \Resource \Item ($ application , new ApplicationTransformer ());
426+ $ response = $ this ->manager ->createData ($ resource );
427+
428+ return response ()->json ($ response ->toArray (), 200 );
429+ }
430+
431+ /**
432+ * @OA\Patch(
433+ * path="/apps/{id}/deactivate",
434+ * tags={"Applications"},
435+ * summary="Deactivate an application by ID",
436+ * operationId="deactivateApplication",
437+ * security={},
438+ * deprecated=true,
439+ * @OA\Parameter(
440+ * name="id",
441+ * in="path",
442+ * required=true,
443+ * description="ID of the application to deactivate",
444+ * @OA\Schema(type="integer", format="int64")
445+ * ),
446+ * @OA\Response(
447+ * response=200,
448+ * description="Successful response",
449+ * @OA\JsonContent(
450+ * type="object",
451+ * @OA\Property(property="data", type="array", @OA\Items(type="object"))
452+ * )
453+ * )
454+ * )
455+ */
456+ public function deactivate ($ id )
457+ {
458+ try {
459+ $ application = $ this ->repo ->find ($ id );
460+ } catch (\Exception $ e ) {
461+ Log::error ('Application not found ' , ['message ' => $ e ->getMessage ()]);
462+
463+ return response ()->json ([
464+ 'status ' => 404 ,
465+ 'error_message ' => 'Application does not exist ' ,
466+ 'errors ' => ['No matching Application ' ],
467+ ], 404 );
468+ }
469+
470+ if ($ application ->tenant_id !== $ this ->tenantId ) {
471+ return response ()->json ([
472+ 'status ' => 403 ,
473+ 'error_message ' => 'Application does not belong to tenant ' ,
474+ 'errors ' => ['Application does not belong to tenant ' ],
475+ ], 403 );
476+ }
477+
478+ try {
479+ $ this ->repo ->updateWithIdAndInput ($ id , ['is_active ' => false ]);
480+ } catch (\Exception $ e ) {
481+ Log::error ('Application not deactivated ' , ['message ' => $ e ->getMessage ()]);
482+
483+ return response ()->json ([
484+ 'status ' => 500 ,
485+ 'error_message ' => 'Unable to deactivate Application ' ,
486+ 'errors ' => [$ e ->getMessage ()],
487+ ], 500 );
488+ }
489+
490+ $ application = $ this ->repo ->find ($ id );
491+
492+ $ resource = new \League \Fractal \Resource \Item ($ application , new ApplicationTransformer ());
493+ $ response = $ this ->manager ->createData ($ resource );
494+
495+ return response ()->json ($ response ->toArray (), 200 );
496+ }
363497}
0 commit comments