<?php
namespace App\Controller;
use App\Model\OrganizationModel;
use App\Model\PackageModel;
use App\Service\RedisCache;
use App\Service\EmailService;
use Pimcore\Log\ApplicationLogger;
use Pimcore\Controller\FrontendController;
use Knp\Component\Pager\PaginatorInterface;
use App\Service\PublicUserPermissionService;
use Pimcore\Model\DataObject\Organization;
use Pimcore\Model\DataObject\Package;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Templating\EngineInterface;
use Pimcore\Model\DataObject\Customer;
use Pimcore\Model\DataObject;
use App\Model\UserModel;
use App\Model\ReportLogModel;
use App\Model\PermissionUserGroupModel;
class ApiWebhookController extends FrontendController
{
private $organizationModel;
private $userModel;
private $reportModel;
private $packageModel;
private $permissionUserGroupModel;
public function __construct(
private TokenStorageInterface $tokenStorageInterface,
private JWTTokenManagerInterface $jwtManager,
private PublicUserPermissionService $publicUserPermissionService,
protected TranslatorInterface $translator,
private ApplicationLogger $logger,
private EmailService $emailService,
private EngineInterface $templating,
) {
// header('Content-Type: application/json; charset=UTF-8');
// header("Access-Control-Allow-Origin: *");
$this->publicUserPermissionService = $publicUserPermissionService;
$this->organizationModel = new OrganizationModel();
$this->userModel = new UserModel();
$this->packageModel = new PackageModel($templating);
$this->permissionUserGroupModel = new PermissionUserGroupModel();
$this->reportModel = new ReportLogModel();
}
/**
* @Route("api/webhook/add-ncm-user", methods={"POST"})
*/
public function addNCMUser(Request $request, EngineInterface $templating): JsonResponse
{
try {
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
$user = $response['user'];
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = [
'name',
'email',
'role',
'allowedApiGrpups'
];
// if (isset($params['role']) && ($params['role'] == USER_ROLES['NCM_OPERATOR'])) {
// array_push($requiredParameters, "disallowedApiGroups");
// }
foreach ($requiredParameters as $param) {
if (!isset($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$name = $params['name'];
$email = $params['email'];
$role = isset($params['role']) ? $params['role'] : USER_ROLES['NCM_OPERATOR'];
$userTagId = isset($params['tagId']) ? $params['tagId'] : null;
$isNoExpiry = (isset($params['isNoExpiry']) ? $params['isNoExpiry'] : false);
$password = $params['password'];
$hostName = NCM_ADMIN_HOST_NAME;
$phone = isset($params['phone']) ? $params['phone'] : null;
// $disallowedApiGroupsArray = isset($params['disallowedApiGroups']) ? $params['disallowedApiGroups'] : [];
$allowedApiGrpups = $params['allowedApiGrpups'];
$result = $this->organizationModel->adminAddInviteNCMUser(
$request,
$this->translator,
$email,
$name,
$role,
$userTagId,
$hostName,
$user,
$allowedApiGrpups,
$templating,
$isNoExpiry,
$phone,
$password
);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/edit-ncm-user" , methods={"POST"})
*/
public function editNCMUser(Request $request,): JsonResponse
{
try {
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
$user = $response['user'];
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$requiredParameters = [
'id',
'role'
];
foreach ($requiredParameters as $param) {
if (!isset($params[$param]) || empty($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$customer = Customer::getByEmail($params['email'], true);
if (!$customer instanceof \Pimcore\Model\DataObject\Customer) {
throw new \Exception("User not found");
}
$params['id'] = $customer->getId();
$loggedInUser = Customer::getByEmail($params['loggedInUserEmail'], true);
if (!$loggedInUser instanceof \Pimcore\Model\DataObject\Customer) {
throw new \Exception("User not found");
}
//validate Role first
if (isset($params['role'])) {
$loggedInUserRole = $loggedInUser->getRole()->getName();
if (!array_key_exists($params['role'], USER_ROLES)) {
return $this->json(["success" => false, "message" => $this->translator->trans($params['role'] . "_is_not_available_in_role_list .")]);
} elseif ($loggedInUserRole == USER_ROLES['CLIENT_USER'] && ($params['role'] == USER_ROLES['NCM_OPERATOR'] || $params['role'] == USER_ROLES['NCM_IT'] || $params['role'] == USER_ROLES['CLIENT_ADMIN'])) {
return $this->json(["success" => false, "message" => $this->translator->trans(USER_ROLES[$loggedInUserRole] . "_can_not_add_" . USER_ROLES[$params['role']] . "_role.")]);
} elseif ($loggedInUserRole == USER_ROLES['CLIENT_ADMIN'] && ($params['role'] == USER_ROLES['NCM_IT'] || $params['role'] == USER_ROLES['NCM_OPERATOR'])) {
return $this->json(["success" => false, "message" => $this->translator->trans(USER_ROLES[$loggedInUserRole] . "_can_not_add_" . USER_ROLES[$params['role']] . "._role")]);
} elseif ($loggedInUserRole == USER_ROLES['NCM_OPERATOR'] && ($params['role'] == USER_ROLES['NCM_IT'])) {
return $this->json(["success" => false, "message" => $this->translator->trans(USER_ROLES[$loggedInUserRole] . "_can_not_add_" . USER_ROLES[$params['role']] . "._role")]);
} elseif ($params['role'] == USER_ROLES['CLIENT_ADMIN'] || $params['role'] == USER_ROLES['CLIENT_USER']) {
return $this->json(["success" => false, "message" => $this->translator->trans(USER_ROLES[$params['role']] . "_is_not_available_in_NCM_ROLES")]);
}
}
// Perform parameter validation here
if (!isset($params['id'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans('missing_required_parameters')]);
}
// Perform parameter validation here
if (isset($params['password']) && $loggedInUserRole != USER_ROLES['NCM_IT']) {
return $this->json(['success' => false, 'message' => $this->translator->trans('only_' . USER_ROLES['NCM_IT'] . '_can_change_password')]);
}
$params['loggedInUser'] = $loggedInUser;
// Call the editUser method and get the result
$result = $this->userModel->editNCMUser($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/update-profile", methods={"POST"})
*/
public function updateProfile(Request $request): JsonResponse
{
try {
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
$user = $response['user'];
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
// Perform parameter validation here
if (!isset($params['id']) || !isset($params['name']) || !isset($params['department']) || !isset($params['title'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans('missing_required_parameters')]);
}
$userByEmail = Customer::getByEmail($params['userEmail'], true);
if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
throw new \Exception("User not found");
}
$params["id"] = $userByEmail->getId();
// Call the updateProfile method and get the result
$result = $this->userModel->updateProfile($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/change-password", methods={"POST"})
*/
public function changePassword(Request $request): JsonResponse
{
try {
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
$user = $response['user'];
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$userByEmail = Customer::getByEmail($params['userEmail'], true);
if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
throw new \Exception("User not found");
}
// Perform parameter validation here
if (!isset($params['oldPassword']) || !isset($params['newPassword']) || !isset($params['confirmNewPassword'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans('missing_required_parameters')]);
}
// Call the changePassword method and get the result
$result = $this->userModel->changePassword($userByEmail, $params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/create-organization", methods={"POST"})
*/
public function createOrganization(Request $request)
{
try {
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
$user = $response['user'];
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$id = $params['id'] ?? 0000;
$entExist = Organization::getById($id, true);
if ($entExist instanceof Organization) {
$createNameEn = trim(strip_tags($params['name']));
$entExist->setUniqueId($params['uniqueId']);
$entExist->setName($createNameEn, 'en');
$entExist->setName(isset($params['nameAr']) ? trim(strip_tags($params['nameAr'])) : $createNameEn, 'ar');
$entExist->save();
return $this->json(['success' => false, 'message' => $this->translator->trans("organization_already_exists")]);
}
// Perform parameter validation here
$requiredParameters = [
'clientType',
'name'
];
foreach ($requiredParameters as $param) {
if (!isset($params[$param]) || empty($params[$param])) {
$missingParams[] = $param;
}
}
if (!empty($missingParams)) {
// Throw an exception with a message that includes the missing parameters
$parameterList = implode(", ", $missingParams);
return $this->json(['success' => false, 'message' => sprintf($this->translator->trans("missing_required_parameters: %s"), $parameterList)]);
}
$userByEmail = Customer::getByEmail($params['userEmail'], true);
if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
throw new \Exception("User not found");
}
$packageObj = new Package\Listing();
$packageObj->setLocale('en');
$packageObj->setCondition("packageName = ?", $params['packageName']);
$packageObj->setLimit(1);
$pObj = $packageObj->current();
$params['packageId'] = $pObj ? $pObj->getId() : 16145;
// Call the createOrganization method and get the result
$result = $this->organizationModel->createEntity($request, $params, $userByEmail, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/edit-organization", methods={"POST"})
*/
public function updateOrganization(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (empty($params["uniqueId"])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("Unique ID is required")]);
}
$result = $this->organizationModel->editOrganization($request, $params, $this->packageModel, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/delete-organization", methods={"POST"})
*/
public function deleteOrganization(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (empty($params["uniqueId"])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("Unique ID is required")]);
}
$userByEmail = Customer::getByEmail($params['userEmail'], true);
if (!$userByEmail instanceof \Pimcore\Model\DataObject\Customer) {
throw new \Exception("User not found");
}
$result = $this->organizationModel->deleteOrganization($userByEmail, $params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/get-api-groups", methods={"POST"})
*/
public function getApiGroups(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->packageModel->listReportingApiGroups($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/create-permission-user-group", methods={"POST"})
*/
public function createPermissionUserGroup(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$user = $this->getUser();
$result = $this->permissionUserGroupModel->createPermissionUserGroup(
$params["name"],
$params["description"] ?? '',
$params["apiGroupIds"],
$user,
$this->translator
);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/edit-permission-user-group", methods={"POST"})
*/
public function editPermissionUserGroup(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$user = $this->getUser();
$result = $this->permissionUserGroupModel->editPermissionUserGroup(
$params,
$this->translator
);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/delete-permission-user-group", methods={"POST"})
*/
public function deletePermissionUserGroup(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$user = $this->getUser();
$result = $this->permissionUserGroupModel->deletePermissionUserGroup(
$params,
$this->translator
);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/list-permission-user-groups", methods={"POST"})
*/
public function listPermissionUserGroups(Request $request, PaginatorInterface $paginator)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->permissionUserGroupModel->listPermissionUserGroups($params, $paginator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/add-reporting-user", methods={"POST"})
*/
public function addReportingUser(Request $request)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->userModel->addReportingUser($params, $this->translator);
if ($result['success'] == true) {
return $this->json(['success' => true, 'message' => $this->translator->trans("user_created_successfully")]);
}
return $this->json(['success' => false, 'message' => $result['message']]);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/invite-reporting-user", methods={"POST"})
*/
public function inviteReportingUser(Request $request, EngineInterface $templating)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->userModel->inviteReportingUser($params, $templating, $this->translator);
if ($result['success'] == true) {
return $this->json(['success' => true, 'message' => $this->translator->trans("user_invited_successfully")]);
}
return $this->json(['success' => false, 'message' => $result['message']]);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/resend-reporting-user-invite" , methods={"POST"})
*/
public function resendReportingUserInvite(Request $request, EngineInterface $templating): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
// $response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
// if ($response['success'] !== true) {
// return $this->json($response);
// }
// Perform parameter validation here
if (!isset($params['id'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans('missing_required_parameter_id')]);
}
// Call the resendEwsUserInvite method and get the result
$result = $this->userModel->resendReportingUserInvite($params, $templating, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/list-reporting-users", methods={"POST"})
*/
public function listReportingUsers(Request $request, PaginatorInterface $paginator)
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$result = $this->userModel->listReportingUsers($params, $paginator, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/edit-reporting-user" , methods={"POST"})
*/
public function editReportingUser(Request $request,): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
// Perform parameter validation here
if (!isset($params['id'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans('missing_required_parameter_id')]);
}
// Call the editUser method and get the result
$result = $this->userModel->editReportingUser($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/delete-reporting-user", methods={"POST"})
*/
public function deleteUserReportingUser(Request $request): JsonResponse
{
try {
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
if (!isset($params['id']) || empty($params['id'])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("missing_required_parameter_user_id")]);
}
// Normalize id to array for single or multiple user delete
$params['id'] = is_array($params['id']) ? array_values(array_filter($params['id'])) : [$params['id']];
$result = $this->userModel->deleteUserReportingUser($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/get-latest-report", methods={"POST"})
*/
public function getLatestReport(Request $request): JsonResponse
{
try {
// $response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
// if ($response['success'] !== true) {
// return $this->json($response);
// }
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
// Call the editUser method and get the result
$result = $this->reportModel->getLatestReport($params['reportType'], $this->translator,false);
return $this->json($result);
} catch (\Exception $ex) {
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/assign-bulk-reporting-user-permission-group", name="assign_bulk_reporting_user_permission_group", methods={"POST"})
*/
public function assignBulkReportingUserPermissionGroup(Request $request): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
// Perform parameter validation here
if (!isset($params["userIds"]) || empty($params["userIds"]) || !is_array($params["userIds"])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("User_ids_are_required")]);
}
if (!isset($params["tagId"])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("tag_id_is_required")]);
}
// Call the editUser method and get the result
$result = $this->userModel->assignBulkReportingUserPermissionGroup($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/assign-bulk-reporting-user-tag", name="assign_bulk_reporting_user_tag", methods={"POST"})
*/
public function assignBulkReportingUserTag(Request $request): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
// Perform parameter validation here
if (!isset($params["userIds"]) || empty($params["userIds"]) || !is_array($params["userIds"])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("User_ids_are_required")]);
}
if (!isset($params["tagIds"]) || empty($params["tagIds"]) || !is_array($params["tagIds"])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("Tag_ids_are_required")]);
}
// Call the assignBulkReportingUserTag method and get the result
$result = $this->userModel->assignBulkReportingUserTag($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/create-reporting-tag", name="create_reporting_tag", methods={"POST"})
*/
public function createReportingTag(Request $request): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
// Perform parameter validation here
if (!isset($params["name"]) || empty($params["name"])) {
return $this->json(['success' => false, 'message' => $this->translator->trans("Name_is_required")]);
}
// Call the createReportingTag method and get the result
$result = $this->userModel->createReportingTag($params, $this->translator);
return $this->json($result);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $ex->getMessage()]);
}
}
/**
* @Route("api/webhook/list-reporting-tags", name="list_reporting_tags", methods={"POST"})
*/
public function listReportingTags(Request $request, PaginatorInterface $paginator): JsonResponse
{
try {
$params = json_decode($request->getContent(), true);
$this->translator->setlocale(isset($params["lang"]) ? $params["lang"] : DEFAULT_LOCALE);
$response = $this->publicUserPermissionService->isAuthorized($request, $this->translator);
if ($response['success'] !== true) {
return $this->json($response);
}
// Call the listReportingTags method and get the result
$result = $this->userModel->listReportingTags($params, $this->translator, $paginator);
if ($result['success'] == true) {
return $this->json(['success' => true, 'data' => $result['data'], 'paginationVariables' => $result['paginationVariables']]);
}
return $this->json(['success' => false, 'message' => $result['message'] ?? $this->translator->trans(USER_ERROR_MESSAGE)]);
} catch (\Exception $ex) {
$this->logger->error($ex->getMessage());
return $this->json(['success' => false, 'message' => $this->translator->trans(USER_ERROR_MESSAGE)]);
}
}
}