-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alessandro Bellanda
committed
Mar 2, 2020
0 parents
commit c93556b
Showing
13 changed files
with
685 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
vendor | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 ESC Enterprise Software Consulting | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "escsrl/notification", | ||
"type": "library", | ||
"description": "Simple notification system based on top of Mercure", | ||
"keywords": [ | ||
"mercure", | ||
"symfony", | ||
"symfony-mercure", | ||
"notification" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Alessandro Bellanda", | ||
"email": "a.bellanda@gmail.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"Esc\\Notification\\": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": "^7.3", | ||
"ext-json": "*", | ||
"beberlei/assert": "^3.2", | ||
"doctrine/doctrine-bundle": "^2.0", | ||
"doctrine/orm": "^2.7", | ||
"escsrl/mercure-publisher": "^2.0", | ||
"escsrl/requestparams": "^2.0", | ||
"escsrl/result": "^1.0", | ||
"nesbot/carbon": "^2.30", | ||
"symfony/framework-bundle": "^5.0", | ||
"symfony/security-core": "^5.0", | ||
"symfony/serializer": "^5.0" | ||
}, | ||
"require-dev": {}, | ||
"config": { | ||
"sort-packages": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="Notification test suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Esc\Notification\Controller; | ||
|
||
use Esc\Notification\Repository\NotificationRepository; | ||
use Esc\RequestParams; | ||
use Esc\Result; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class NotificationController extends AbstractController | ||
{ | ||
private $notificationRepository; | ||
private $result; | ||
|
||
public function __construct(NotificationRepository $notificationRepository, Result $result) | ||
{ | ||
$this->notificationRepository = $notificationRepository; | ||
$this->result = $result; | ||
} | ||
|
||
/** | ||
* @Route("/api/notifications", name="read_notifications", methods={"GET"}) | ||
* @param Request $request | ||
* @return JsonResponse | ||
*/ | ||
public function readNotifications(Request $request): JsonResponse | ||
{ | ||
$requestParams = RequestParams::fromRequest($request); | ||
|
||
try { | ||
$this->result->setData($this->notificationRepository->findByCriteria($requestParams)); | ||
$this->result->setTotalRows( | ||
$this->notificationRepository->countByCriteria($requestParams->get('filters')) | ||
); | ||
return $this->json($this->result->toArray()); | ||
} catch (\Exception $e) { | ||
$this->result->setMessage($e->getMessage()); | ||
return $this->json($this->result->toArray(), 400); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
<?php | ||
|
||
namespace Esc\Notification\Entity; | ||
|
||
use Carbon\Carbon; | ||
use DateTime; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity(repositoryClass="Esc\Notification\Repository\NotificationRepository") | ||
* @ORM\HasLifecycleCallbacks | ||
*/ | ||
class Notification | ||
{ | ||
public const SUBMITTED_STATE = 'S'; | ||
public const RUNNING_STATE = 'R'; | ||
public const SUCCESS_STATE = 'D'; | ||
public const ERROR_STATE = 'E'; | ||
|
||
/** | ||
* @ORM\Id() | ||
* @ORM\GeneratedValue() | ||
* @ORM\Column(type="integer") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
private $title; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=80, nullable=true) | ||
*/ | ||
private $subTitle; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255, nullable=true) | ||
*/ | ||
private $message; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=1) | ||
*/ | ||
private $status; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255, nullable=true) | ||
*/ | ||
private $link; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255, nullable=true) | ||
*/ | ||
private $externalLink; | ||
|
||
/** | ||
* @ORM\Column(type="string", length=255) | ||
*/ | ||
private $username; | ||
|
||
/** | ||
* @var DateTime | ||
* @ORM\Column(name="created", type="datetime") | ||
*/ | ||
private $created; | ||
|
||
/** | ||
* @var DateTime | ||
* @ORM\Column(name="updated", type="datetime", nullable=true) | ||
*/ | ||
private $updated; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getMessage(): ?string | ||
{ | ||
return $this->message; | ||
} | ||
|
||
public function setMessage(?string $message): self | ||
{ | ||
$this->message = $message; | ||
|
||
return $this; | ||
} | ||
|
||
public function getSubTitle(): ?string | ||
{ | ||
return $this->subTitle; | ||
} | ||
|
||
public function setSubTitle(?string $subTitle): self | ||
{ | ||
$this->subTitle = $subTitle; | ||
|
||
return $this; | ||
} | ||
|
||
public function getStatus(): ?string | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function setStatus(string $status): self | ||
{ | ||
$this->status = $status; | ||
|
||
return $this; | ||
} | ||
|
||
public function getLink(): ?string | ||
{ | ||
return $this->link; | ||
} | ||
|
||
public function setLink(?string $link): self | ||
{ | ||
$this->link = $link; | ||
|
||
return $this; | ||
} | ||
|
||
public function getExternalLink(): ?string | ||
{ | ||
return $this->externalLink; | ||
} | ||
|
||
public function setExternalLink(?string $externalLink): self | ||
{ | ||
$this->externalLink = $externalLink; | ||
|
||
return $this; | ||
} | ||
|
||
public function getUsername(): ?string | ||
{ | ||
return $this->username; | ||
} | ||
|
||
public function setUsername(string $username): self | ||
{ | ||
$this->username = $username; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getCreated(): \DateTime | ||
{ | ||
return $this->created; | ||
} | ||
|
||
/** | ||
* @return \DateTime|null | ||
*/ | ||
public function getUpdated(): ?\DateTime | ||
{ | ||
return $this->updated; | ||
} | ||
|
||
/** | ||
* @ORM\PrePersist | ||
* @return void | ||
*/ | ||
public function onPrePersist(): void | ||
{ | ||
$this->created = Carbon::now(); | ||
} | ||
|
||
/** | ||
* @ORM\PreUpdate | ||
* @return void | ||
*/ | ||
public function onPreUpdate(): void | ||
{ | ||
$this->updated = Carbon::now(); | ||
} | ||
|
||
public function getTitle(): ?string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function setTitle(string $title): self | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
} |
Oops, something went wrong.