src/Controller/Api/V1/Profile/RoyaltyAdjust/EarningSongs.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\V1\Profile\RoyaltyAdjust;
  3. use App\Entity\Profile\Profile;
  4. use App\Factory\EntityFactory;
  5. use App\Helpers\FilteringHelper;
  6. use App\Helpers\PaginationHelper;
  7. use App\Responders\CollectionResponder;
  8. use App\Responders\EntityMessageResponder;
  9. use App\Service\AuthenticationService;
  10. use App\Service\RequestDataExtractorService;
  11. use App\Service\Royalties\RoyaltyImporterFileService;
  12. use GuzzleHttp\Exception\GuzzleException;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Component\HttpFoundation\JsonResponse;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  18. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  19. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  20. use Symfony\Component\Security\Core\User\UserInterface;
  21. use Nelmio\ApiDocBundle\Annotation\Model;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  23. use Swagger\Annotations as SWG;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. class EarningSongs
  26. {
  27.     /** @var RequestDataExtractorService */
  28.     private $requestDataExtractorService;
  29.     /** @var EntityFactory */
  30.     private $entityFactory;
  31.     /** @var EventDispatcherInterface */
  32.     private $eventDispatcher;
  33.     /** @var AuthenticationService */
  34.     private $authenticationService;
  35.     /** @var PaginationHelper */
  36.     private $paginationHelper;
  37.     /** @var FilteringHelper */
  38.     private $filteringHelper;
  39.     /** @var RoyaltyImporterFileService */
  40.     private $royaltyImporterFileService;
  41.     /**
  42.      * Create constructor.
  43.      * @param RequestDataExtractorService $requestDataExtractorService
  44.      * @param EntityFactory $entityFactory
  45.      * @param EventDispatcherInterface $eventDispatcher
  46.      * @param AuthenticationService $authenticationService
  47.      * @param PaginationHelper $paginationHelper
  48.      * @param FilteringHelper $filteringHelper
  49.      * @param RoyaltyImporterFileService $royaltyImporterFileService
  50.      */
  51.     public function __construct(
  52.         RequestDataExtractorService $requestDataExtractorService,
  53.         EntityFactory $entityFactory,
  54.         EventDispatcherInterface $eventDispatcher,
  55.         AuthenticationService $authenticationService,
  56.         PaginationHelper $paginationHelper,
  57.         FilteringHelper $filteringHelper,
  58.         RoyaltyImporterFileService $royaltyImporterFileService
  59.     )
  60.     {
  61.         $this->requestDataExtractorService $requestDataExtractorService;
  62.         $this->entityFactory $entityFactory;
  63.         $this->eventDispatcher $eventDispatcher;
  64.         $this->authenticationService $authenticationService;
  65.         $this->paginationHelper $paginationHelper;
  66.         $this->filteringHelper $filteringHelper;
  67.         $this->royaltyImporterFileService $royaltyImporterFileService;
  68.     }
  69.     /**
  70.      * @Route(path="/v1/profile/{id}/earning-songs", methods={"GET"})
  71.      *
  72.      * @SWG\Get(
  73.      *   tags={"Royalty Adjust"}
  74.      * )
  75.      *
  76.      * @SWG\Response(
  77.      *     response=200,
  78.      *     description="Success response"
  79.      * )
  80.      *
  81.      * here garent commnet
  82.      *
  83.      * @param TokenStorageInterface $tokenStorage
  84.      * @param Profile $profile
  85.      * @param Request $request
  86.      * @param CollectionResponder $collectionResponder
  87.      * @param EntityMessageResponder $entityMessageResponder
  88.      * @return JsonResponse
  89.      * @throws GuzzleException
  90.      *
  91.      */
  92.     public function __invoke(
  93.         Profile $profile,
  94.         Request $request,
  95.         TokenStorageInterface $tokenStorage,
  96.         CollectionResponder $collectionResponder,
  97.         EntityMessageResponder $entityMessageResponder
  98.     )
  99.     {
  100.         $token $tokenStorage->getToken();
  101.         if (! $token instanceof TokenInterface || ! $token->getUser() || ! $token->getUser() instanceof UserInterface) {
  102.             throw new AccessDeniedHttpException('Token issue');
  103.         }
  104.         $collection $this->royaltyImporterFileService->getCompositionEarningsByProfile($profile);
  105.         return new JsonResponse(json_encode($collection), Response::HTTP_OK, [], true);
  106.     }
  107. }