Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function updateAction(Request $request) : Response
- {
- try {
- $data = json_decode($request->getContent(), true);
- $em = $this->getDoctrine()->getManager();
- $user = $em->getRepository(UserEntity::class)->find($data['id']);
- if (!$user) {
- throw $this->createNotFoundException(
- 'No user found for id '.$data['id']
- );
- }
- $user->setPassword($data['password']);
- $user->setPassword($data['email']);
- $em->persist($user);
- $em->flush();
- return new JsonResponse(['User update is successfully' => $data['id']], 201);
- var_dump($data);
- } catch (Exception $e) {
- return $this->fail($e);
- }
- }
- namespace AppPortmoneController;
- use SymfonyComponentHttpFoundationRequest;
- use SymfonyComponentHttpFoundationResponse;
- use SymfonyComponentHttpFoundationJsonResponse;
- use SymfonyComponentRoutingAnnotationRoute;
- use SymfonyBundleFrameworkBundleControllerController;
- use SymfonyComponentConfigDefinitionExceptionException;
- use AppPortmoneEntityUserEntity;
- namespace AppPortmoneEntity;
- use AppPortmoneExceptionInvalidSignUpException;
- use DoctrineORMMapping as ORM;
- /**
- * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
- */
- class UserEntity
- {
- /**
- * @ORMId()
- * @ORMGeneratedValue()
- * @ORMColumn(type="integer")
- */
- private $id;
- /**
- * @ORMColumn(type="string", length=255)
- */
- private $password;
- /**
- * @ORMColumn(type="string", length=255, unique=true)
- */
- private $email;
- public function getId(): ?int
- {
- return $this->id;
- }
- public function getPassword(): ?string
- {
- return $this->password;
- }
- public function setPassword(string $password): self
- {
- $passwordSize = strlen($password);
- if($passwordSize < 5 || $passwordSize > 32){
- throw new InvalidSignUpException();
- }
- $this->password = $password;
- return $this;
- }
- public function getEmail(): ?string
- {
- return $this->email;
- }
- public function setEmail(string $email): self
- {
- $emailSize = strlen($email);
- if($emailSize < 5 || $emailSize > 32){
- throw new InvalidSignUpException();
- }
- $this->email = $email;
- return $this;
- }
Add Comment
Please, Sign In to add comment