<?php
namespace App\Controller\Api;
use App\Model\Enum\AccessControl;
use App\Controller\AbstractController;
use App\Entity\Tiers;
use App\Traits\Autowired\Manager\TiersManagerTrait;
use GollumSF\RestBundle\Annotation\Serialize;
use GollumSF\RestBundle\Annotation\Unserialize;
use GollumSF\RestBundle\Annotation\Validate;
use GollumSF\RestDocBundle\Annotation\ApiDescribe;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/api/tierses")
* @ApiDescribe(Tiers::class)
*/
class TiersController extends AbstractController {
use TiersManagerTrait;
/**
* @Route("", methods="GET")
* @IsGranted(AccessControl::API_GET_TIERS, subject="current_user")
* @Serialize(groups="tiers_getc")
* @ApiDescribe(
* request={
* "parameters"={
* "filters"={
* "in"="query",
* "required"=false,
* "type"="string",
* "example"="{""type"":"""",""name"":"""",""company"":"""",""remarques"":"""",""phone1"":"""",""phone2"":"""",""createdAt"":{""mode"":""equal"",""equal"":null,""start"":null,""end"":null}}"
* }
* }
* }
* )
*/
public function list() {
return $this->tiersManager->apiFindBy();
}
/**
* @Route("/{id}", methods="GET", requirements={"id"="\d+"})
* @IsGranted(AccessControl::API_GET_TIERS, subject="current_user")
* @Serialize(groups="tiers_get")
*/
public function find(Tiers $tiers) {
return $tiers;
}
/**
* @Route("", methods="POST")
* @IsGranted(AccessControl::API_POST_TIERS, subject="current_user")
* @Unserialize("tiers", groups="tiers_post")
* @Validate({ "tiers_post" })
* @Serialize(groups="tiers_get")
*
*/
public function post(Tiers $tiers) {
return $tiers;
}
/**
* @Route("/{id}", methods="PUT", requirements={"id"="\d+"})
* @IsGranted(AccessControl::API_PUT_TIERS, subject="current_user")
* @Unserialize("tiers", groups="tiers_put")
* @Validate({ "tiers_put" })
* @Serialize(groups="tiers_get")
*
*/
public function put(Tiers $tiers) {
return $tiers;
}
/**
* @Route("/{id}", methods="DELETE", requirements={"id"="\d+"})
* @IsGranted(AccessControl::API_DELETE_TIERS, subject="current_user")
* @Serialize(groups="tiers_get")
*
*/
public function delete(Tiers $tiers) {
return $this->tiersManager->delete($tiers);
}
/**
* @Route("/attestation/{id}/{year}", methods="GET", requirements={"id"="\d+"})
* @IsGranted(AccessControl::API_GET_TIERS, subject="current_user")
* @Serialize(groups="tiers_get")
*
*/
public function attestation(Tiers $tiers, string $year) {
$host = $this->getParameter('database_host');
$port = $this->getParameter('database_port');
$user = $this->getParameter('database_user');
$pass = $this->getParameter('database_password');
$db = $this->getParameter('database_name');
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset;port=$port";
return $this->tiersManager->getPrestation($tiers, $year, $dsn, $user, $pass);
}
}