forked from DATA-DOG/DataDogAuditBundle
-
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.
Merge pull request #4 from ntidev/audit-time-line-api
Adding controllers, services and repository for the api
- Loading branch information
Showing
5 changed files
with
273 additions
and
7 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,39 @@ | ||
<?php | ||
|
||
namespace DataDog\AuditBundle\Controller; | ||
|
||
use AppBundle\Util\DataTable\DataTableOptionsProcessor; | ||
use AppBundle\Util\Rest\DataTableRestResponse; | ||
use AppBundle\Util\Rest\RestResponse; | ||
use DataDog\AuditBundle\Service\AuditLogService; | ||
use JMS\Serializer\SerializationContext; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
/** | ||
* Class AuditLogController | ||
* @package DataDog\AuditBundle\Controller | ||
* @Route("/") | ||
*/ | ||
class AuditLogController extends Controller { | ||
|
||
// REST Methods | ||
/** | ||
* @Route("/rest/getAll", name="nti_rest_audit_log_get_all", options={"expose"=true}, methods={"GET"}) | ||
* @param Request $request | ||
* @return DataTableRestResponse | ||
*/ | ||
public function getAllAction(Request $request) { | ||
$options = DataTableOptionsProcessor::GetOptions($request); | ||
$result = $this->get(AuditLogService::class)->getAll($options); | ||
$logs = json_decode($this->container->get('jms_serializer')->serialize($result["data"], 'json') ,true); | ||
$result["data"] = $logs; | ||
return new DataTableRestResponse($result); | ||
} | ||
|
||
} |
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
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
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
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,39 @@ | ||
<?php | ||
|
||
namespace DataDog\AuditBundle\Service; | ||
|
||
use DataDog\AuditBundle\Entity\AuditLog; | ||
use PHPUnit\Runner\Exception; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Class AuditLogService | ||
* @package DataDog\AuditBundle\Service | ||
*/ | ||
class AuditLogService { | ||
|
||
/** @var ContainerInterface $container */ | ||
private $container; | ||
|
||
/** | ||
* AuditLogService constructor. | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* Get the list of AuditLogs based on the given $options | ||
* | ||
* @param $options | ||
* @return mixed | ||
*/ | ||
public function getAll($options = array()) { | ||
$em = $this->container->get('doctrine')->getManager(); | ||
$logs = $em->getRepository(AuditLog::class)->findByOptions($options); | ||
return $logs; | ||
} | ||
|
||
} |