mirror of
https://framagit.org/tykayn/date-poll-api
synced 2023-08-25 08:23:11 +02:00
update send to user
This commit is contained in:
parent
ac8242a443
commit
4176922500
@ -16,6 +16,7 @@
|
||||
"symfony/console": "4.3.*",
|
||||
"symfony/dependency-injection": "4.3.*",
|
||||
"symfony/dotenv": "4.3.*",
|
||||
"symfony/expression-language": "4.3.*",
|
||||
"symfony/flex": "^1.3.1",
|
||||
"symfony/form": "4.3.*",
|
||||
"symfony/framework-bundle": "4.3.*",
|
||||
|
53
composer.lock
generated
53
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "3131df97f0b3bc59550652b3fbef5a6c",
|
||||
"content-hash": "7dc6a4d93376a4f198327681d2f6fae2",
|
||||
"packages": [
|
||||
{
|
||||
"name": "doctrine/annotations",
|
||||
@ -3825,6 +3825,57 @@
|
||||
],
|
||||
"time": "2019-09-17T09:54:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/expression-language",
|
||||
"version": "v4.3.11",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/expression-language.git",
|
||||
"reference": "fcc3e2085e4832f52bed94d72663962f650dfb23"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/expression-language/zipball/fcc3e2085e4832f52bed94d72663962f650dfb23",
|
||||
"reference": "fcc3e2085e4832f52bed94d72663962f650dfb23",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"symfony/cache": "~3.4|~4.0",
|
||||
"symfony/service-contracts": "^1.1"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.3-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\ExpressionLanguage\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony ExpressionLanguage Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2020-01-04T12:24:57+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/filesystem",
|
||||
"version": "v4.3.10",
|
||||
|
@ -1,3 +1,5 @@
|
||||
sensio_framework_extra:
|
||||
router:
|
||||
annotations: false
|
||||
request:
|
||||
converters: true
|
||||
|
@ -6,8 +6,9 @@ use App\Entity\Owner;
|
||||
use App\Service\MailService;
|
||||
use FOS\RestBundle\Controller\Annotations\Get;
|
||||
use FOS\RestBundle\Controller\Annotations\Route;
|
||||
use Swift_Mailer;
|
||||
use JMS\Serializer\Type\Exception\Exception;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
|
||||
/**
|
||||
* Class DefaultController
|
||||
@ -28,43 +29,50 @@ class DefaultController extends FramadateController {
|
||||
* name = "send_user_polls"
|
||||
* )
|
||||
*
|
||||
* @param $email
|
||||
* @param Swift_Mailer $mailer
|
||||
* @param string $email
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function sendPollsToUser( $email, Swift_Mailer $mailer ) {
|
||||
public function sendPollsToUserAction( string $email ) {
|
||||
$repository = $this->getDoctrine()->getRepository( Owner::class );
|
||||
|
||||
// find user by email
|
||||
$founduser = $repository->findOneBy( [ 'email' => $email ] );
|
||||
|
||||
if ( $founduser ) {
|
||||
$polls = $founduser->getPolls();
|
||||
// find user by email
|
||||
$owner = $repository->findOneByEmail($email);
|
||||
|
||||
if ( $owner ) {
|
||||
$templateVars = [
|
||||
'owner' => $founduser,
|
||||
'polls' => $polls,
|
||||
'title' => 'Mes sondages - ' . $email,
|
||||
'owner' => $owner,
|
||||
'polls' => $owner->getPolls(),
|
||||
'title' => 'Mes sondages - ' . $owner->getEmail(),
|
||||
];
|
||||
|
||||
// send email
|
||||
if ( $this->mail_service->sendOwnerPollsAction( $founduser ) ) {
|
||||
$mailSent = 0;
|
||||
try {
|
||||
$mailSent = $this->sendOwnerPollsAction( $owner );
|
||||
} catch ( Exception $e ) {
|
||||
} catch ( TransportExceptionInterface $e ) {
|
||||
}
|
||||
|
||||
if ( $mailSent ) {
|
||||
return $this->json( [
|
||||
'message' => 'mail succefully sent to user ' . $email,
|
||||
'message' => 'mail succefully sent to user ' . $owner->getEmail(),
|
||||
'data' => '',
|
||||
],
|
||||
200 );
|
||||
} else { // user not found case
|
||||
return $this->json( [
|
||||
'message' => 'no user found for email ' . $email,
|
||||
'data' => '',
|
||||
],
|
||||
400 );
|
||||
}
|
||||
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'no sucess sending email ' . $owner->getEmail(),
|
||||
'data' => '',
|
||||
],
|
||||
400 );
|
||||
}
|
||||
|
||||
return $this->json( [
|
||||
'message' => 'no user found for email ' . $email,
|
||||
'data' => '',
|
||||
],
|
||||
400 );
|
||||
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class FramadateController extends AbstractController {
|
||||
|
||||
private $mail_service;
|
||||
|
||||
public function __construct( \Swift_Mailer $mailer ) {
|
||||
$this->mail_service = $mailer;
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ class IndexController extends FramadateController {
|
||||
* name = "get_default")
|
||||
*/
|
||||
public function indexAction() {
|
||||
return $this->render( 'index.html.twig', [] );
|
||||
|
||||
return $this->json( ["message"=>"welcome to the framadate api, ask /api/v1/doc.json for endpoints"],200);
|
||||
// return $this->render( 'index.html.twig', [] );
|
||||
}
|
||||
}
|
||||
|
@ -280,6 +280,9 @@
|
||||
"symfony/event-dispatcher-contracts": {
|
||||
"version": "v1.1.7"
|
||||
},
|
||||
"symfony/expression-language": {
|
||||
"version": "v4.3.11"
|
||||
},
|
||||
"symfony/filesystem": {
|
||||
"version": "v4.3.5"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user