Selaa lähdekoodia

ot_admin api controller returns json responses

Olivier Massot 5 vuotta sitten
vanhempi
commit
25bf5cd34e
1 muutettua tiedostoa jossa 33 lisäystä ja 9 poistoa
  1. 33 9
      ot_admin/Classes/Http/ApiController.php

+ 33 - 9
ot_admin/Classes/Http/ApiController.php

@@ -6,7 +6,7 @@ namespace Opentalent\OtAdmin\Http;
 use Opentalent\OtAdmin\Controller\SiteController;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
-use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\JsonResponse;
 use TYPO3\CMS\Core\Http\ServerRequest;
 
 class ApiController implements LoggerAwareInterface
@@ -60,7 +60,7 @@ class ApiController implements LoggerAwareInterface
      * Create the organization's website
      *
      * @param ServerRequest $request
-     * @return HtmlResponse
+     * @return JsonResponse
      * @throws \Exception
      */
     public function createSiteAction(ServerRequest $request) {
@@ -75,7 +75,13 @@ class ApiController implements LoggerAwareInterface
             "OtAdmin API: A new website has been created with root page uid=" . $rootUid .
             " for the organization " . $organizationId));
 
-        return new HtmlResponse("A new website has been created with root page uid=" . $rootUid);
+        return new JsonResponse(
+            [
+                'organization_id' => $organizationId,
+                'msg' => "A new website has been created with root page uid=" . $rootUid,
+                'root_uid' => $rootUid
+            ]
+        );
     }
 
     /**
@@ -85,7 +91,7 @@ class ApiController implements LoggerAwareInterface
      * Update the settings of the organization's website
      *
      * @param ServerRequest $request
-     * @return HtmlResponse
+     * @return JsonResponse
      * @throws \Exception
      */
     public function updateSiteConstantsAction(ServerRequest $request) {
@@ -100,7 +106,13 @@ class ApiController implements LoggerAwareInterface
             "OtAdmin API: The website with root uid " . $rootUid . " has been updated " .
             " (organization: " . $organizationId . ")"));
 
-        return new HtmlResponse("The website with root uid " . $rootUid . " has been updated");
+        return new JsonResponse(
+            [
+                'organization_id' => $organizationId,
+                'msg' => "The website with root uid " . $rootUid . " has been updated",
+                'root_uid' => $rootUid
+            ]
+        );
     }
 
     /**
@@ -110,7 +122,7 @@ class ApiController implements LoggerAwareInterface
      * Proceeds to a soft-deletion of the organization's website
      *
      * @param ServerRequest $request
-     * @return HtmlResponse
+     * @return JsonResponse
      * @throws \Exception
      */
     public function deleteSiteAction(ServerRequest $request) {
@@ -125,7 +137,13 @@ class ApiController implements LoggerAwareInterface
             "OtAdmin API: The website with root uid " . $rootUid . " has been soft-deleted " .
             " (organization: " . $organizationId . ")"));
 
-        return new HtmlResponse("The website with root uid " . $rootUid . " has been soft-deleted. Use the /site/undelete route to restore it.");
+        return new JsonResponse(
+            [
+                'organization_id' => $organizationId,
+                'msg' => "The website with root uid " . $rootUid . " has been soft-deleted. Use the /site/undelete route to restore it.",
+                'root_uid' => $rootUid
+            ]
+        );
     }
 
     /**
@@ -135,7 +153,7 @@ class ApiController implements LoggerAwareInterface
      * Restore a soft-deleted organization's website
      *
      * @param ServerRequest $request
-     * @return HtmlResponse
+     * @return JsonResponse
      * @throws \Exception
      */
     public function undeleteSiteAction(ServerRequest $request) {
@@ -150,6 +168,12 @@ class ApiController implements LoggerAwareInterface
             "OtAdmin API: The website with root uid " . $rootUid . " has been restored " .
             " (organization: " . $organizationId . ")"));
 
-        return new HtmlResponse("The website with root uid " . $rootUid . " has been restored");
+        return new JsonResponse(
+            [
+                'organization_id' => $organizationId,
+                'msg' => "The website with root uid " . $rootUid . " has been restored",
+                'root_uid' => $rootUid
+            ]
+        );
     }
 }