API: changed date-format, camelCase instead of snake_case, null values, update and create for customer and project (#718)

This commit is contained in:
Kevin Papst
2019-04-24 18:13:33 +02:00
committed by GitHub
parent 215d4fc8bf
commit 460391136f
61 changed files with 2304 additions and 505 deletions

View File

@@ -11,17 +11,22 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\User;
use App\Repository\Query\UserQuery;
use App\Repository\UserRepository;
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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
* @RouteResource("User")
*
* @Security("is_granted('ROLE_USER')")
*/
class UserController extends BaseApiController
{
@@ -46,22 +51,46 @@ class UserController extends BaseApiController
}
/**
* Returns the collection of all registered users
*
* @SWG\Response(
* response=200,
* description="Returns the collection of all registered users",
* description="Returns the collection of all registered users. Required permission: view_user",
* @SWG\Schema(
* type="array",
* @SWG\Items(ref="#/definitions/UserEntity")
* @SWG\Items(ref="#/definitions/UserCollection")
* )
* )
*
* @Rest\QueryParam(name="visible", requirements="1|2|3", strict=true, nullable=true, description="Visibility status to filter users. Allowed values: 1=visible, 2=hidden, 3=all (default: 1)")
* @Rest\QueryParam(name="orderBy", requirements="id|username|alias|email", strict=true, nullable=true, description="The field by which results will be ordered. Allowed values: id, username, alias, email (default: username)")
* @Rest\QueryParam(name="order", requirements="ASC|DESC", strict=true, nullable=true, description="The result order. Allowed values: ASC, DESC (default: ASC)")
*
* @Security("is_granted('view_user')")
*
* @return Response
*/
public function cgetAction()
public function cgetAction(ParamFetcherInterface $paramFetcher)
{
$data = $this->repository->findAll();
$query = new UserQuery();
$query
->setResultType(UserQuery::RESULT_TYPE_OBJECTS)
->setOrderBy('username')
;
if (null !== ($visible = $paramFetcher->get('visible'))) {
$query->setVisibility($visible);
}
if (null !== ($order = $paramFetcher->get('order'))) {
$query->setOrder($order);
}
if (null !== ($orderBy = $paramFetcher->get('orderBy'))) {
$query->setOrderBy($orderBy);
}
$data = $this->repository->findByQuery($query);
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Collection', 'User']);
@@ -69,24 +98,37 @@ class UserController extends BaseApiController
}
/**
* Return one user entity
*
* @SWG\Response(
* response=200,
* description="Return one user entity",
* description="Return one user entity. Required permission: view_user",
* @SWG\Schema(ref="#/definitions/UserEntity"),
* )
*
* @Security("is_granted('view_user')")
* @SWG\Parameter(
* name="id",
* in="path",
* type="integer",
* description="User ID to fetch",
* required=true,
* )
*
* @param int $id
* @return Response
*/
public function getAction($id)
{
$data = $this->repository->find($id);
if (null === $data) {
$user = $this->repository->find($id);
if (null === $user) {
throw new NotFoundException();
}
$view = new View($data, 200);
if (!$this->isGranted('view', $user)) {
throw new AccessDeniedHttpException('You are not allowed to view this profile');
}
$view = new View($user, 200);
$view->getContext()->setGroups(['Default', 'Entity', 'User']);
return $this->viewHandler->handle($view);