<?php
namespace App\Controller\Api\V1\Profile;
use App\Entity\Profile\Profile;
use App\Enums\Constants;
use App\Repository\Profile\ProfileRepository;
use App\Responders\EntityResponder;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
class GetProfilePublicInfo
{
/**
* @var ProfileRepository
*/
private $profileRepository;
/** @var SerializerInterface */
private $serializer;
/**
* @param ProfileRepository $profileRepository
*/
public function __construct(
ProfileRepository $profileRepository,
SerializerInterface $serializer
)
{
$this->serializer = $serializer;
$this->profileRepository = $profileRepository;
}
/**
* @Route(path="/v1/public/profile/{url_name}", methods={"GET"})
*
* @SWG\Get(
* tags={"Public"},
* description="Public endpoint which returns info about signup under profile availability"
* )
*
* @SWG\Response(
* response=200,
* description="Success response"
* )
*
* @ParamConverter("profile", options={"mapping": {"url_name": "urlName"}})
*
* @param Profile $profile
* @param EntityResponder $entityResponder
* @return JsonResponse
*/
public function __invoke(Profile $profile = null, EntityResponder $entityResponder)
{
if ($profile === null) {
$profile = $this->profileRepository->findOneBy(['urlName' => Constants::PROFILE_HORUS_MUSIC_PUBLISHING_URL_NAME]);
}
$data = $this->serializer->serialize($profile, 'json', ['groups' => 'public_info']);
$result = json_decode($data, true);
$result['application'] = "mmpz";
if($profile->getUrlName() === Constants::PROFILE_HORUS_MUSIC_PUBLISHING_INDIA_URL_NAME){
$result['id'] = $profile->getId();
}
return new JsonResponse(json_encode($result), Response::HTTP_OK, [], true);
}
}