From 0b582e2fb0868e7889cb91a463fc9ce3b4bed5d9 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Sat, 30 Sep 2023 23:33:07 +0800 Subject: [PATCH] [back/refactor] remove duplicate request --- src/main/backend/handlers.clj | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/backend/handlers.clj b/src/main/backend/handlers.clj index d1dcd79..57d9de2 100644 --- a/src/main/backend/handlers.clj +++ b/src/main/backend/handlers.clj @@ -174,6 +174,13 @@ "question_id" question-id} (build-paging-next next_url))})))) +(defn build-answer-json + [question-id query] + (let [answers (fetch-hu-answers question-id query)] + (merge + {:answers (mapv build-answer (get answers "data"))} + (process-api-paging question-id (get answers "paging"))))) + (defn fetch-hu-question [request params] (let [question-id (-> request :path-params :id) @@ -199,9 +206,7 @@ (process-json-paging question-id (get-in question-json ["initialState" "question"]))) params) (process-hu-questiion - (merge - {:answers (mapv build-answer (get (fetch-hu-answers question-id query) "data"))} - (process-api-paging question-id (get (fetch-hu-answers question-id query) "paging"))) + (build-answer-json question-id query) params))))) (defn build-api-hu-question