src/Controller/API/ReleaseController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\API;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use App\Entity\Release;
  8. use App\Auth\TokenAuth;
  9. class ReleaseController extends AbstractController
  10. {
  11.     public function __construct(
  12.         private TokenAuth $tokenAuth,
  13.         private EntityManagerInterface $em,
  14.     ) {
  15.     }
  16.     /**
  17.      * Testing connection with update service
  18.      */
  19.     #[Route('/check_connection'name'release.connection')]
  20.     public function checkConnectionAction()
  21.     {
  22.         $project $this->tokenAuth->getCustomerByToken();
  23.         return new JsonResponse(['connection' => true]);
  24.     }
  25.     /**
  26.      * Testing connection with update service
  27.      */
  28.     #[Route('/check_for_updates'name'release.check_for_updates')]
  29.     public function getLastVersionAction()
  30.     {
  31.         $project $this->tokenAuth->getCustomerByToken()->getProject();
  32.         if (!$project) {
  33.             return new JsonResponse(['version' => '1.0.0''url' => null]);
  34.         }
  35.         $release $this->em
  36.             ->getRepository(Release::class)
  37.             ->getLastReleaseByProject($project);
  38.         if (!$release) {
  39.             return new JsonResponse(['status' => 'not found'404]);
  40.         }
  41.         return new JsonResponse(['version' => $release->getVersion(), 'url' => $release->getPath()]);
  42.     }
  43.     /**
  44.      * Testing connection with update service
  45.      */
  46.     #[Route('/get_all_versions'name'release.get_all_versions')]
  47.     public function getLastVersionsByProjectAction()
  48.     {
  49.         $project $this->tokenAuth->getCustomerByToken()->getProject();
  50.         $releases $this->em
  51.             ->getRepository(Release::class)
  52.             ->findBy(['project' => $project], ['id' => 'desc'], 51);
  53.         if (!count($releases)) {
  54.             return new JsonResponse(['status' => 'not found'404]);
  55.         }
  56.         return new JsonResponse($releases);
  57.     }
  58. }