Skip to content
Snippets Groups Projects
Commit a4f144b8 authored by elise's avatar elise
Browse files

use doctrine to manage entities

parent 9ef9098f
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ namespace App\Application\Actions\User;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use App\Domain\User\User ;
class CreateUserAction extends UserAction
{
......@@ -21,8 +22,9 @@ class CreateUserAction extends UserAction
$mail = $parsedRequestBody['mail'];
$phone = $parsedRequestBody['phone'];
$user = $this->userRepository->createUser($username, $firstname, $lastname, $mail, $phone);
$user = new User(null, $username, $firstname, $lastname, $mail, $phone, 0, null);
$this->em->persist($user);
$this->em->flush();
$this->logger->info("User has been created.");
......
......@@ -4,8 +4,8 @@ declare(strict_types=1);
namespace App\Application\Actions\User;
use App\Application\Actions\Action;
use App\Domain\User\UserRepository;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\EntityManager;
abstract class UserAction extends Action
{
......@@ -18,9 +18,10 @@ abstract class UserAction extends Action
* @param LoggerInterface $logger
* @param UserRepository $userRepository
*/
public function __construct(LoggerInterface $logger, UserRepository $userRepository)
public function __construct(LoggerInterface $logger, EntityManager $em)
{
parent::__construct($logger);
$this->userRepository = $userRepository;
$this->userRepository = $em->getRepository('App\Domain\User\User');
$this->em = $em;
}
}
......@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Application\Actions\User;
use Psr\Http\Message\ResponseInterface as Response;
use App\Domain\User\UserNotFoundException;
class ViewUserAction extends UserAction
{
......@@ -13,8 +14,11 @@ class ViewUserAction extends UserAction
protected function action(): Response
{
$userId = (int) $this->resolveArg('id');
$user = $this->userRepository->findUserOfId($userId);
$user = $this->userRepository->find($userId);
if (!isset($user)) {
throw new UserNotFoundException();
}
$this->logger->info("User of id `${userId}` was viewed.");
return $this->respondWithData($user);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment