<?php
namespace App\Controller\Api\V1\Profile\RoyaltyAdjust;
use App\Entity\Profile\Profile;
use App\Factory\EntityFactory;
use App\Helpers\FilteringHelper;
use App\Helpers\PaginationHelper;
use App\Responders\CollectionResponder;
use App\Responders\EntityMessageResponder;
use App\Service\AuthenticationService;
use App\Service\RequestDataExtractorService;
use App\Service\Royalties\RoyaltyImporterFileService;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Nelmio\ApiDocBundle\Annotation\Model;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Swagger\Annotations as SWG;
use Symfony\Component\Routing\Annotation\Route;
class EarningSongs
{
/** @var RequestDataExtractorService */
private $requestDataExtractorService;
/** @var EntityFactory */
private $entityFactory;
/** @var EventDispatcherInterface */
private $eventDispatcher;
/** @var AuthenticationService */
private $authenticationService;
/** @var PaginationHelper */
private $paginationHelper;
/** @var FilteringHelper */
private $filteringHelper;
/** @var RoyaltyImporterFileService */
private $royaltyImporterFileService;
/**
* Create constructor.
* @param RequestDataExtractorService $requestDataExtractorService
* @param EntityFactory $entityFactory
* @param EventDispatcherInterface $eventDispatcher
* @param AuthenticationService $authenticationService
* @param PaginationHelper $paginationHelper
* @param FilteringHelper $filteringHelper
* @param RoyaltyImporterFileService $royaltyImporterFileService
*/
public function __construct(
RequestDataExtractorService $requestDataExtractorService,
EntityFactory $entityFactory,
EventDispatcherInterface $eventDispatcher,
AuthenticationService $authenticationService,
PaginationHelper $paginationHelper,
FilteringHelper $filteringHelper,
RoyaltyImporterFileService $royaltyImporterFileService
)
{
$this->requestDataExtractorService = $requestDataExtractorService;
$this->entityFactory = $entityFactory;
$this->eventDispatcher = $eventDispatcher;
$this->authenticationService = $authenticationService;
$this->paginationHelper = $paginationHelper;
$this->filteringHelper = $filteringHelper;
$this->royaltyImporterFileService = $royaltyImporterFileService;
}
/**
* @Route(path="/v1/profile/{id}/earning-songs", methods={"GET"})
*
* @SWG\Get(
* tags={"Royalty Adjust"}
* )
*
* @SWG\Response(
* response=200,
* description="Success response"
* )
*
* here garent commnet
*
* @param TokenStorageInterface $tokenStorage
* @param Profile $profile
* @param Request $request
* @param CollectionResponder $collectionResponder
* @param EntityMessageResponder $entityMessageResponder
* @return JsonResponse
* @throws GuzzleException
*
*/
public function __invoke(
Profile $profile,
Request $request,
TokenStorageInterface $tokenStorage,
CollectionResponder $collectionResponder,
EntityMessageResponder $entityMessageResponder
)
{
$token = $tokenStorage->getToken();
if (! $token instanceof TokenInterface || ! $token->getUser() || ! $token->getUser() instanceof UserInterface) {
throw new AccessDeniedHttpException('Token issue');
}
$collection = $this->royaltyImporterFileService->getCompositionEarningsByProfile($profile);
return new JsonResponse(json_encode($collection), Response::HTTP_OK, [], true);
}
}