userRepository->findOneBy([ 'email' => $this->security->getUser()?->getUserIdentifier() ]); if (is_null($userEntity)) { throw new HttpException(Response::HTTP_FORBIDDEN, "Unauthorized."); } $facilityDto = new FacilityDto(); $facilityDto->fillFromArray($request->toArray()); $facilityDto->validate(); $facilityEntity = $this->facilityFactory::create($facilityDto); $this->entityManager->persist($facilityEntity); $this->entityManager->flush(); $facilityDto->id = $facilityEntity->getId(); $facilityDto->createdAt = $facilityEntity->getCreatedAt(); return new JsonResponse( data: [ 'success' => true, 'league' => $facilityDto->toArray() ], status: Response::HTTP_OK ); } }