src/Controller/Api/V1/Profile/GetProfilePublicInfo.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\V1\Profile;
  3. use App\Entity\Profile\Profile;
  4. use App\Enums\Constants;
  5. use App\Repository\Profile\ProfileRepository;
  6. use App\Responders\EntityResponder;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  8. use Swagger\Annotations as SWG;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Serializer\SerializerInterface;
  14. class GetProfilePublicInfo
  15. {
  16.     /**
  17.      * @var ProfileRepository
  18.      */
  19.     private $profileRepository;
  20.     /** @var SerializerInterface */
  21.     private $serializer;
  22.     /**
  23.      * @param ProfileRepository $profileRepository
  24.      */
  25.     public function __construct(
  26.         ProfileRepository $profileRepository,
  27.         SerializerInterface $serializer
  28.     )
  29.     {
  30.         $this->serializer $serializer;
  31.         $this->profileRepository $profileRepository;
  32.     }
  33.     /**
  34.      * @Route(path="/v1/public/profile/{url_name}", methods={"GET"})
  35.      *
  36.      * @SWG\Get(
  37.      *   tags={"Public"},
  38.      *   description="Public endpoint which returns info about signup under profile availability"
  39.      * )
  40.      *
  41.      * @SWG\Response(
  42.      *     response=200,
  43.      *     description="Success response"
  44.      * )
  45.      *
  46.      * @ParamConverter("profile", options={"mapping": {"url_name": "urlName"}})
  47.      *
  48.      * @param Profile $profile
  49.      * @param EntityResponder $entityResponder
  50.      * @return JsonResponse
  51.      */
  52.     public function __invoke(Profile $profile nullEntityResponder $entityResponder)
  53.     {
  54.         if ($profile === null) {
  55.             $profile $this->profileRepository->findOneBy(['urlName' => Constants::PROFILE_HORUS_MUSIC_PUBLISHING_URL_NAME]);
  56.         }
  57.         $data $this->serializer->serialize($profile'json', ['groups' => 'public_info']);
  58.         $result json_decode($datatrue);
  59.         $result['application'] = "mmpz";
  60.         if($profile->getUrlName() === Constants::PROFILE_HORUS_MUSIC_PUBLISHING_INDIA_URL_NAME){
  61.             $result['id'] = $profile->getId();
  62.         }
  63.         return new JsonResponse(json_encode($result), Response::HTTP_OK, [], true);
  64.     }
  65. }