Guest User

Untitled

a guest
Sep 19th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. public function updateAction(Request $request) : Response
  2. {
  3.  
  4. try {
  5. $data = json_decode($request->getContent(), true);
  6. $em = $this->getDoctrine()->getManager();
  7. $user = $em->getRepository(UserEntity::class)->find($data['id']);
  8. if (!$user) {
  9. throw $this->createNotFoundException(
  10. 'No user found for id '.$data['id']
  11. );
  12. }
  13.  
  14. $user->setPassword($data['password']);
  15. $user->setPassword($data['email']);
  16. $em->persist($user);
  17. $em->flush();
  18. return new JsonResponse(['User update is successfully' => $data['id']], 201);
  19.  
  20. var_dump($data);
  21.  
  22. } catch (Exception $e) {
  23. return $this->fail($e);
  24. }
  25. }
  26.  
  27. namespace AppPortmoneController;
  28.  
  29. use SymfonyComponentHttpFoundationRequest;
  30. use SymfonyComponentHttpFoundationResponse;
  31. use SymfonyComponentHttpFoundationJsonResponse;
  32. use SymfonyComponentRoutingAnnotationRoute;
  33. use SymfonyBundleFrameworkBundleControllerController;
  34. use SymfonyComponentConfigDefinitionExceptionException;
  35. use AppPortmoneEntityUserEntity;
  36.  
  37. namespace AppPortmoneEntity;
  38.  
  39. use AppPortmoneExceptionInvalidSignUpException;
  40.  
  41. use DoctrineORMMapping as ORM;
  42.  
  43. /**
  44. * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
  45. */
  46. class UserEntity
  47. {
  48. /**
  49. * @ORMId()
  50. * @ORMGeneratedValue()
  51. * @ORMColumn(type="integer")
  52. */
  53. private $id;
  54.  
  55. /**
  56. * @ORMColumn(type="string", length=255)
  57. */
  58. private $password;
  59.  
  60. /**
  61. * @ORMColumn(type="string", length=255, unique=true)
  62. */
  63. private $email;
  64.  
  65. public function getId(): ?int
  66. {
  67. return $this->id;
  68. }
  69.  
  70. public function getPassword(): ?string
  71. {
  72. return $this->password;
  73. }
  74.  
  75. public function setPassword(string $password): self
  76. {
  77. $passwordSize = strlen($password);
  78. if($passwordSize < 5 || $passwordSize > 32){
  79. throw new InvalidSignUpException();
  80. }
  81.  
  82. $this->password = $password;
  83.  
  84. return $this;
  85. }
  86.  
  87. public function getEmail(): ?string
  88. {
  89. return $this->email;
  90. }
  91.  
  92. public function setEmail(string $email): self
  93. {
  94. $emailSize = strlen($email);
  95. if($emailSize < 5 || $emailSize > 32){
  96. throw new InvalidSignUpException();
  97. }
  98. $this->email = $email;
  99.  
  100. return $this;
  101. }
Add Comment
Please, Sign In to add comment