add mailer and notification when suspect values
This commit is contained in:
parent
ef9b4cf421
commit
fcd9279533
|
@ -22,6 +22,7 @@
|
||||||
"symfony/process": "4.4.*",
|
"symfony/process": "4.4.*",
|
||||||
"symfony/security-bundle": "4.4.*",
|
"symfony/security-bundle": "4.4.*",
|
||||||
"symfony/serializer-pack": "*",
|
"symfony/serializer-pack": "*",
|
||||||
|
"symfony/swiftmailer-bundle": "^3.4",
|
||||||
"symfony/translation": "4.4.*",
|
"symfony/translation": "4.4.*",
|
||||||
"symfony/twig-pack": "*",
|
"symfony/twig-pack": "*",
|
||||||
"symfony/validator": "4.4.*",
|
"symfony/validator": "4.4.*",
|
||||||
|
|
|
@ -13,4 +13,5 @@ return [
|
||||||
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
|
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
|
||||||
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
|
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
|
||||||
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
|
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
|
||||||
|
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
|
||||||
];
|
];
|
||||||
|
|
4
config/packages/dev/swiftmailer.yaml
Normal file
4
config/packages/dev/swiftmailer.yaml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# See https://symfony.com/doc/current/email/dev_environment.html
|
||||||
|
swiftmailer:
|
||||||
|
# send all emails to a specific address
|
||||||
|
#delivery_addresses: ['me@example.com']
|
3
config/packages/swiftmailer.yaml
Normal file
3
config/packages/swiftmailer.yaml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
swiftmailer:
|
||||||
|
url: '%env(MAILER_URL)%'
|
||||||
|
spool: { type: 'memory' }
|
2
config/packages/test/swiftmailer.yaml
Normal file
2
config/packages/test/swiftmailer.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
swiftmailer:
|
||||||
|
disable_delivery: true
|
|
@ -14,7 +14,7 @@ class HygrometryApiController extends AbstractController
|
||||||
/**
|
/**
|
||||||
* @Route("/api/hygrometry/create", name="api_hygrometry_create", methods={"POST"})
|
* @Route("/api/hygrometry/create", name="api_hygrometry_create", methods={"POST"})
|
||||||
*/
|
*/
|
||||||
public function create(Request $request, ApiValidator $validator): Response
|
public function create(Request $request, ApiValidator $validator, \Swift_Mailer $mailer): Response
|
||||||
{
|
{
|
||||||
if ('application/json' === $request->getContentType()) {
|
if ('application/json' === $request->getContentType()) {
|
||||||
return $this->json([], 400);
|
return $this->json([], 400);
|
||||||
|
@ -37,6 +37,22 @@ class HygrometryApiController extends AbstractController
|
||||||
$manager->persist($entity);
|
$manager->persist($entity);
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
|
||||||
|
if ($entity->getValue() >= 50) {
|
||||||
|
$message = (new \Swift_Message('[Terrarium] Alerte hygométrie'))
|
||||||
|
->setFrom('terrarium@deblan.fr')
|
||||||
|
->setTo(['simon@deblan.fr', 'jennifer@derago.fr'])
|
||||||
|
->setBody(
|
||||||
|
$this->renderView(
|
||||||
|
'alert/hygrometry.txt.twig',
|
||||||
|
[
|
||||||
|
'entity' => $entity,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$mailer->send($message);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->json([], 201);
|
return $this->json([], 201);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class TemperatureApiController extends AbstractController
|
||||||
/**
|
/**
|
||||||
* @Route("/api/temperature/create", name="api_temperature_create", methods={"POST"})
|
* @Route("/api/temperature/create", name="api_temperature_create", methods={"POST"})
|
||||||
*/
|
*/
|
||||||
public function create(Request $request, ApiValidator $validator): Response
|
public function create(Request $request, ApiValidator $validator, \Swift_Mailer $mailer): Response
|
||||||
{
|
{
|
||||||
if ('application/json' === $request->getContentType()) {
|
if ('application/json' === $request->getContentType()) {
|
||||||
return $this->json([], 400);
|
return $this->json([], 400);
|
||||||
|
@ -37,6 +37,22 @@ class TemperatureApiController extends AbstractController
|
||||||
$manager->persist($entity);
|
$manager->persist($entity);
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
|
||||||
|
if ($entity->getValue() < 25) {
|
||||||
|
$message = (new \Swift_Message('[Terrarium] Alerte température'))
|
||||||
|
->setFrom('terrarium@deblan.fr')
|
||||||
|
->setTo(['simon@deblan.fr', 'jennifer@derago.fr'])
|
||||||
|
->setBody(
|
||||||
|
$this->renderView(
|
||||||
|
'alert/temperature.txt.twig',
|
||||||
|
[
|
||||||
|
'entity' => $entity,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$mailer->send($message);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->json([], 201);
|
return $this->json([], 201);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
17
symfony.lock
17
symfony.lock
|
@ -141,6 +141,9 @@
|
||||||
"config/packages/sensio_framework_extra.yaml"
|
"config/packages/sensio_framework_extra.yaml"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"swiftmailer/swiftmailer": {
|
||||||
|
"version": "v6.2.3"
|
||||||
|
},
|
||||||
"symfony/apache-pack": {
|
"symfony/apache-pack": {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"recipe": {
|
"recipe": {
|
||||||
|
@ -424,6 +427,20 @@
|
||||||
"symfony/stopwatch": {
|
"symfony/stopwatch": {
|
||||||
"version": "v4.4.5"
|
"version": "v4.4.5"
|
||||||
},
|
},
|
||||||
|
"symfony/swiftmailer-bundle": {
|
||||||
|
"version": "2.5",
|
||||||
|
"recipe": {
|
||||||
|
"repo": "github.com/symfony/recipes",
|
||||||
|
"branch": "master",
|
||||||
|
"version": "2.5",
|
||||||
|
"ref": "ae4d22af30bbd484506bc1817c5a3ef72c855b93"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"config/packages/dev/swiftmailer.yaml",
|
||||||
|
"config/packages/swiftmailer.yaml",
|
||||||
|
"config/packages/test/swiftmailer.yaml"
|
||||||
|
]
|
||||||
|
},
|
||||||
"symfony/test-pack": {
|
"symfony/test-pack": {
|
||||||
"version": "v1.0.6"
|
"version": "v1.0.6"
|
||||||
},
|
},
|
||||||
|
|
2
templates/alert/hygrometry.txt.twig
Normal file
2
templates/alert/hygrometry.txt.twig
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Date : {{ entity.date.format('d/m/Y H:i:s') }}
|
||||||
|
Niveau hygrométrique : {{ entity.value }}%
|
2
templates/alert/temperature.txt.twig
Normal file
2
templates/alert/temperature.txt.twig
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
Date : {{ entity.date.format('d/m/Y H:i:s') }}
|
||||||
|
Température : {{ entity.value }}°
|
Loading…
Reference in a new issue