From e1bf4c09a818cc478ce828ad60399d0fe0bdedbd Mon Sep 17 00:00:00 2001 From: Guillaume Dubost Date: Tue, 23 Jun 2015 12:48:01 +0200 Subject: [PATCH] [FEATURE#19954] Adaptation aux routes sur conversation - Le `findByQueryString` retourne maintenant le bon champ de la response - Ajout des routes `/search` et `/stats` dans le `DumbMethodsProxy` --- src/ConversationManager.php | 2 +- src/DumbMethodsProxy.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ConversationManager.php b/src/ConversationManager.php index 0f12c2e..6f3d1d1 100644 --- a/src/ConversationManager.php +++ b/src/ConversationManager.php @@ -28,7 +28,7 @@ public function findByQueryString($query, $from = 0, $size = 99999) $response = $this->fireRequest($request, $this->app["cookies.authenticator"]); $conversations_array = []; - $conversations = $response["conversations"]["hits"]; + $conversations = $response["hits"]; foreach ($conversations as $conversation) { $conversation_item = new Conversation(); $conversation_item->fromArray($conversation); diff --git a/src/DumbMethodsProxy.php b/src/DumbMethodsProxy.php index 09d0b6c..4876020 100644 --- a/src/DumbMethodsProxy.php +++ b/src/DumbMethodsProxy.php @@ -19,6 +19,10 @@ public function connect(Application $app) $controllers = $app["controllers_factory"]; + //Dumb proxy for stats and search + $controllers->get("/conversations/search", [$this, "conversationSearch"]); + $controllers->get("/conversations/stats", [$this, "conversationStats"]); + //Dumb proxy for messages $controllers->get("/conversations/{conversation}/messages/{message}", [$this, "loadMessage"]); $controllers->get("/conversations/{conversation}/messages", [$this, "loadConversationMessages"]); @@ -40,6 +44,16 @@ public function connect(Application $app) return $controllers; } + public function conversationSearch(Application $app, Request $req) + { + return $this->getRequestWithBody($app, $req, "/conversations"); + } + + public function conversationStats(Application $app, Request $req) + { + return $this->getRequestWithBody($app, $req, "/conversations"); + } + public function loadMessage(Application $app, Request $req) { return $this->doProxyWithoutDatas($app, $req); @@ -114,6 +128,17 @@ public function doProxyWithDatas(Application $app, Request $req) return $response; } + public function getRequestWithBody(Application $app, Request $req, $remove_prefix = "") + { + $path_info = $req->getPathInfo(); + $path_info = str_replace($remove_prefix, "", $path_info); + + $request = $app["conversation_proxy"] + ->createRequest("GET", "{$path_info}?{$req->getQueryString()}", [], $req->request->all()); + $response = self::requestWithJsonResponse($request, $app, $req->cookies->get("authenticator")); + return $response; + } + public static function requestWithJsonResponse(GuzzleRequest $request, Application $app, $cookie) { try {