Correction norme

master
Xantxo COQUILLARD 3 years ago
parent c8c3b42b0e
commit 706166fa26

@ -2,31 +2,28 @@
namespace App\Composant\User\Domain; namespace App\Composant\User\Domain;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity #[ORM\Entity, ORM\Table(name:"users")]
* @ORM\Table(name="users")
*/
class User class User
{ {
/** #[ORM\Id, ORM\GeneratedValue(strategy: 'AUTO')]
* @ORM\Id() #[ORM\Column(type:Types::INTEGER)]
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private int $id; private int $id;
/** #[ORM\Column(type:Types::STRING, length:255)]
* @ORM\Column(type="string", length=255)
*/
private string $lastname; private string $lastname;
//finir le reste xD
private string $firstname; private string $firstname;
private int $roleId; private int $roleId;
private float $kwhPrice, $hourlyCost;
private float $kwhPrice;
private float $hourlyCost;
public function __construct() public function __construct()
{ {

@ -4,6 +4,5 @@ namespace App\Composant\User\Domain;
interface UserDataMapper interface UserDataMapper
{ {
public function findById(int $id): User;
public function findAll(): array;
} }

@ -0,0 +1,9 @@
<?php
namespace App\Composant\User\Domain;
interface UserRepository
{
public function findById(int $id): User;
public function findAll(): array;
}

@ -4,11 +4,12 @@ namespace App\Composant\User\Infrastructure;
use App\Composant\User\Domain\User; use App\Composant\User\Domain\User;
use App\Composant\User\Domain\UserDataMapper; use App\Composant\User\Domain\UserDataMapper;
use App\Composant\User\Domain\UserRepository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Exception; use Exception;
class DoctrineUser extends ServiceEntityRepository implements UserDataMapper class UserDatabaseAdapter extends ServiceEntityRepository implements UserDataMapper, UserRepository
{ {
public function __construct(ManagerRegistry $registry) public function __construct(ManagerRegistry $registry)

@ -2,27 +2,27 @@
namespace App\Controller; namespace App\Controller;
use App\Composant\User\Infrastructure\DoctrineUser; use App\Composant\User\Infrastructure\UserDatabaseAdapter;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use function dd; use function dd;
class test extends AbstractController class TestController extends AbstractController
{ {
public function __construct() public function __construct()
{ {
} }
#[Route('/foo', name: 'contact')] #[Route('/foo')]
public function index(ManagerRegistry $registry): Response public function index(ManagerRegistry $registry): Response
{ {
$DoctrineUser = new DoctrineUser($registry); $DoctrineUser = new UserDatabaseAdapter($registry);
$User = $DoctrineUser->findById(1); $user = $DoctrineUser->findById(1);
dd($User);
return new Response( return new Response(
"", $user->getId(). " " .$user->getLastname(),
Response::HTTP_OK, Response::HTTP_OK,
['content-type' => 'text/html'] ['content-type' => 'text/html']
); );
Loading…
Cancel
Save