From 8f65eeb8dec8ad51d4c09b53f9b5ce34f7727a48 Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Sat, 23 Nov 2024 20:04:40 +0100 Subject: refactor(backend): simplify api responses in handlers --- src/backend/tubo/handler.clj | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/backend/tubo/handler.clj b/src/backend/tubo/handler.clj index ab66d0f..ba0b8e6 100644 --- a/src/backend/tubo/handler.clj +++ b/src/backend/tubo/handler.clj @@ -24,35 +24,26 @@ [:script "tubo.core.init();"]]))) (defn search - [{:keys [parameters] :as req}] - (let [{:keys [service-id]} (:path parameters) - {:keys [q]} (:query parameters) - {:strs [contentFilters sortFilter nextPage]} (:query-params req) - content-filters (and contentFilters - (str/split - contentFilters - #","))] - (response (if nextPage - (api/get-search service-id q contentFilters sortFilter nextPage) - (api/get-search service-id q contentFilters sortFilter))))) + [{{{:keys [service-id]} :path {:keys [q]} :query} :parameters + {:strs [contentFilters sortFilter nextPage]} :query-params}] + (response (apply api/get-search + service-id + q + (and contentFilters (str/split contentFilters #",")) + sortFilter + (if nextPage [nextPage] [])))) (defn channel [{{:keys [url]} :path-params {:strs [nextPage]} :query-params}] - (response (if nextPage - (api/get-channel url nextPage) - (api/get-channel url)))) + (response (apply api/get-channel url (if nextPage [nextPage] [])))) (defn playlist [{{:keys [url]} :path-params {:strs [nextPage]} :query-params}] - (response (if nextPage - (api/get-playlist url nextPage) - (api/get-playlist url)))) + (response (apply api/get-playlist url (if nextPage [nextPage] [])))) (defn comments [{{:keys [url]} :path-params {:strs [nextPage]} :query-params}] - (response (if nextPage - (api/get-comments url nextPage) - (api/get-comments url)))) + (response (apply api/get-comments url (if nextPage [nextPage] [])))) (defn services [_] @@ -65,13 +56,10 @@ (defn kiosk [{{{:keys [kiosk-id service-id]} :path} :parameters {:strs [nextPage]} :query-params}] - (response (cond - (and kiosk-id service-id nextPage) (api/get-kiosk kiosk-id - service-id - nextPage) - (and kiosk-id service-id) (api/get-kiosk kiosk-id - service-id) - :else (api/get-kiosk service-id)))) + (response (apply api/get-kiosk + kiosk-id + (into (if service-id [service-id] []) + (if nextPage [nextPage] []))))) (defn stream [{{:keys [url]} :path-params}] -- cgit v1.2.3