API endpoint for Timesheet entries (#332)

This commit is contained in:
Kevin Papst
2018-11-18 19:43:58 +01:00
committed by GitHub
parent 8cb52e22b1
commit b1c06eed7b
35 changed files with 1073 additions and 118 deletions

View File

@@ -13,13 +13,14 @@ namespace App\API;
use App\Entity\Customer;
use App\Repository\CustomerRepository;
use App\Repository\Query\CustomerQuery;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Request\ParamFetcherInterface;
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandlerInterface;
use Nelmio\ApiDocBundle\Annotation\Model;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Swagger\Annotations as SWG;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
@@ -27,7 +28,7 @@ use Symfony\Component\HttpFoundation\Response;
*
* @Security("is_granted('ROLE_USER')")
*/
class CustomerController extends Controller
class CustomerController extends BaseApiController
{
/**
* @var CustomerRepository
@@ -51,26 +52,35 @@ class CustomerController extends Controller
/**
* @SWG\Response(
* response=200,
* description="Returns the collection of all existing customer",
* @SWG\Schema(ref=@Model(type=Customer::class)),
* response=200,
* description="Returns the collection of all existing customer",
* @SWG\Schema(ref="#/definitions/CustomerCollection"),
* )
* @Rest\QueryParam(name="visible", requirements="\d+", strict=true, nullable=true, description="Visibility status to filter activities (1=visible, 2=hidden, 3=both)")
*
* @return Response
*/
public function cgetAction()
public function cgetAction(ParamFetcherInterface $paramFetcher)
{
$data = $this->repository->findAll();
$query = new CustomerQuery();
$query->setResultType(CustomerQuery::RESULT_TYPE_OBJECTS);
if (null !== ($visible = $paramFetcher->get('visible'))) {
$query->setVisibility($visible);
}
$data = $this->repository->findByQuery($query);
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Collection', 'Customer']);
return $this->viewHandler->handle($view);
}
/**
* @SWG\Response(
* response=200,
* description="Returns one customer entity",
* @SWG\Schema(ref=@Model(type=Customer::class)),
* response=200,
* description="Returns one customer entity",
* @SWG\Schema(ref="#/definitions/CustomerEntity"),
* )
*
* @param int $id
@@ -83,6 +93,7 @@ class CustomerController extends Controller
throw new NotFoundException();
}
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'Customer']);
return $this->viewHandler->handle($view);
}