forked from EC-CUBE/ec-cube
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #15 from onshopVN/feature-notification
Feature notification
- Loading branch information
Showing
8 changed files
with
559 additions
and
1 deletion.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
app/Customize/Controller/Admin/NotificationController.php
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,102 @@ | ||
<?php | ||
namespace Customize\Controller\Admin; | ||
|
||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Customize\Service\HttpClient; | ||
use Eccube\Repository\BaseInfoRepository; | ||
use Eccube\Entity\BaseInfo; | ||
|
||
class NotificationController extends \Eccube\Controller\AbstractController | ||
{ | ||
/** | ||
* @var BaseInfo | ||
*/ | ||
protected $baseInfo; | ||
|
||
/** | ||
* @var HttpClient | ||
*/ | ||
protected $httpClient; | ||
|
||
/** | ||
* NotificationController constructor. | ||
* @param BaseInfoRepository $baseInfoRepository | ||
* @param HttpClient $httpClient | ||
* @throws \Exception | ||
*/ | ||
public function __construct( | ||
BaseInfoRepository $baseInfoRepository, | ||
HttpClient $httpClient | ||
) { | ||
$this->baseInfo = $baseInfoRepository->get(); | ||
$this->httpClient = $httpClient; | ||
} | ||
|
||
/** | ||
* | ||
* @Route("/%eccube_admin_route%/notification/ajax", name="customize_admin_notification_ajax") | ||
* | ||
* @param Request $request | ||
* @return JsonResponse | ||
*/ | ||
public function ajax(Request $request) | ||
{ | ||
$endpoint = $this->baseInfo->getOsStoreApiEndpoint() . '/api/v1/notifications'; | ||
$headers = [ | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '. $this->baseInfo->getOsStoreAuthToken() | ||
]; | ||
|
||
$queryParams = []; | ||
$targetId = $request->get('targetId', 0); | ||
if ($targetId) { | ||
$queryParams['targetId'] = $targetId; | ||
} | ||
$targetEntity = $request->get('targetEntity', 'frontend_register'); | ||
if ($targetEntity) { | ||
$queryParams['targetEntity'] = $targetEntity; | ||
} | ||
|
||
$pageNum = $request->get('pageNum', 0); | ||
if ($pageNum) { | ||
$queryParams['pageNum'] = $pageNum; | ||
} | ||
|
||
$pageSize = $request->get('pageSize', 10); | ||
if ($pageSize) { | ||
$queryParams['pageSize'] = $pageSize; | ||
} | ||
|
||
if ($queryParams) { | ||
$endpoint .= '?' . http_build_query($queryParams); | ||
} | ||
|
||
$result = $this->httpClient->request($endpoint, $headers); | ||
|
||
return new JsonResponse($result, 200, [], true); | ||
} | ||
|
||
/** | ||
* @Route("/%eccube_admin_route%/notification/ajax/read", name="customize_admin_notification_ajax_read", methods={"PUT"}) | ||
* | ||
* @param Request $request | ||
* @return JsonResponse | ||
*/ | ||
public function ajaxRead(Request $request) | ||
{ | ||
$endpoint = $this->baseInfo->getOsStoreApiEndpoint() . '/api/v1/notifications/' . $request->get('id'); | ||
$headers = [ | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '. $this->baseInfo->getOsStoreAuthToken() | ||
]; | ||
$data = [ | ||
'readAt' => 'now' | ||
]; | ||
$result = $this->httpClient->put($endpoint, $headers, $data); | ||
|
||
return new JsonResponse($result, 200, []); | ||
} | ||
} |
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,54 @@ | ||
<?php | ||
namespace Customize\Controller\Admin; | ||
|
||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\HttpFoundation\JsonResponse; | ||
|
||
class OsController extends \Eccube\Controller\AbstractController | ||
{ | ||
/** | ||
* @var \Eccube\Entity\BaseInfo | ||
*/ | ||
protected $baseInfo; | ||
|
||
/** | ||
* @var \Customize\Service\HttpClient | ||
*/ | ||
protected $httpClient; | ||
|
||
/** | ||
* OsController constructor. | ||
* @param \Eccube\Repository\BaseInfoRepository $baseInfoRepository | ||
* @param \Customize\Service\HttpClient $httpClient | ||
* @throws \Exception | ||
*/ | ||
public function __construct( | ||
\Eccube\Repository\BaseInfoRepository $baseInfoRepository, | ||
\Customize\Service\HttpClient $httpClient | ||
) { | ||
$this->baseInfo = $baseInfoRepository->get(); | ||
$this->httpClient = $httpClient; | ||
} | ||
|
||
/** | ||
* | ||
* @Route("/%eccube_admin_route%/os/ajax", name="customize_admin_os_ajax") | ||
* | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* @return JsonResponse | ||
*/ | ||
public function ajax(\Symfony\Component\HttpFoundation\Request $request) | ||
{ | ||
$endpoint = $this->baseInfo->getOsStoreApiEndpoint() . '/api/v1/me'; | ||
$headers = [ | ||
'Content-Type: application/json', | ||
'Authorization: Bearer '. $this->baseInfo->getOsStoreAuthToken() | ||
]; | ||
|
||
$result = $this->httpClient->request($endpoint, $headers); | ||
$result = json_decode($result, true); | ||
$result['currentVersion'] = env('OS_VERSION') ?: \Eccube\Common\Constant::VERSION; | ||
|
||
return new JsonResponse($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
Oops, something went wrong.