Commit dd1da501 authored by Laura Heimann's avatar Laura Heimann

Notification API call & documentation

parent 8f045a16
html {
font-size: 12px !important;
}
.sidebar {
overflow-y: scroll;
}
.sidebar-group {
margin-top: 25px;
}
......
html {
font-size: 12px !important;
}
.sidebar {
overflow-y: scroll;
}
.sidebar-group {
margin-top: 25px;
}
......
......@@ -141,6 +141,17 @@ class APIDocsController extends AbstractController
return $this->render('apidocs/connect/profile.html.twig', $data);
}
/**
* @Route("/api/docs/connect/notifications", name="api.docs.connect.notifications")
*/
public function connectNotifications(Request $request)
{
$em = $this->getDoctrine()->getManager();
$data = [];
return $this->render('apidocs/connect/notifications.html.twig', $data);
}
/**
* @Route("/api/docs/connect/reviews", name="api.docs.connect.reviews")
*/
......
<?php
namespace App\Controller\API\Connect;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpClient\HttpClient;
use App\Entity\User;
use App\Entity\Connection;
use App\Entity\ConnectApp;
use App\Entity\UserNotification;
class APIConnectNotificationsController extends AbstractController
{
/**
* @Route("/api/connect/notifications", name="api.connect.notifications")
* @Route("/api/connect/notifications/")
*/
public function getNotifications(Request $request)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$connectToken = $request->query->get('connectToken');
if($connectToken == "") {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 403, 'data' => []]);
return $response;
}
$connection = $em->getRepository(Connection::class)->findOneBy(array('connectToken' => $connectToken));
if($connection) {
foreach($connection->getUser()->getUserNotifications() as $notification) {
$data[] = $notification->getJSON();
}
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => $data]);
return $response;
} else {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 403, 'data' => []]);
return $response;
}
}
/**
* @Route("/api/connect/clearNotification", name="api.connect.clearNotification")
* @Route("/api/connect/clearNotification/")
*/
public function clearNotifications(Request $request)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$connectToken = $request->query->get('connectToken');
$notificationIDToClear = $request->query->get('notificationID');
if($connectToken == "" || $notificationIDToClear = "") {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 403, 'data' => []]);
return $response;
}
$connection = $em->getRepository(Connection::class)->findOneBy(array('connectToken' => $connectToken));
if($connection) {
$notificationToClear = $em->getRepository(UserNotification::class)->findOneBy(array('id' => $notificationIDToClear, 'user' => $connection->getUser()));
if($notificationToClear) {
$em->remove($notificationToClear);
$em->flush();
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => []]);
return $response;
} else {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 404, 'data' => []]);
return $response;
}
} else {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 403, 'data' => []]);
return $response;
}
}
/**
* @Route("/api/connect/clearAllNotifications", name="api.connect.clearAllNotifications")
* @Route("/api/connect/clearAllNotifications/")
*/
public function clearAllNotifications(Request $request)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$connectToken = $request->query->get('connectToken');
if($connectToken == "") {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 403, 'data' => []]);
return $response;
}
$connection = $em->getRepository(Connection::class)->findOneBy(array('connectToken' => $connectToken));
if($connection) {
$notificationsToClear = $em->getRepository(UserNotification::class)->findBy(array('user' => $connection->getUser()));
foreach($notificationsToClear as $notificationToClear) {
$em->remove($notificationToClear);
$em->flush();
}
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => []]);
return $response;
} else {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 403, 'data' => []]);
return $response;
}
}
}
......@@ -123,6 +123,12 @@
</span>
Profile
</a>
<a href="{{ path('api.docs.connect.notifications') }}" class="sidebar-link sidebar-link-with-icon {% if app.request.attributes.get('_route') == 'api.docs.connect.notifications' %}active{% endif %}">
<span class="sidebar-icon">
<i class="mdi mdi-bell" aria-hidden="true"></i>
</span>
Notifications
</a>
<a href="{{ path('api.docs.connect.reviews') }}" class="sidebar-link sidebar-link-with-icon {% if app.request.attributes.get('_route') == 'api.docs.connect.reviews' %}active{% endif %}">
<span class="sidebar-icon">
<i class="mdi mdi-thumbs-up-down" aria-hidden="true"></i>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment