|
3 | 3 | [duct.logger :refer [log]]
|
4 | 4 | [gpml.db.community :as db.community]
|
5 | 5 | [gpml.db.country-group :as db.country-group]
|
| 6 | + [gpml.domain.file :as dom.file] |
6 | 7 | [gpml.handler.responses :as r]
|
| 8 | + [gpml.service.file :as srv.file] |
7 | 9 | [gpml.util.regular-expressions :as util.regex]
|
8 |
| - [integrant.core :as ig])) |
| 10 | + [integrant.core :as ig] |
| 11 | + [medley.core :as medley])) |
9 | 12 |
|
10 | 13 | (def ^:const community-network-types ["organisation" "stakeholder"])
|
11 | 14 | (def ^:const geo-coverage-types ["Transnational" "National" "Global" "Sub-national"])
|
|
163 | 166 | (re-seq #"\w+")
|
164 | 167 | (str/join " & ")))))
|
165 | 168 |
|
| 169 | +(defn- community-member->api-community-member |
| 170 | + [config community-member] |
| 171 | + (let [{files :files member-type :type |
| 172 | + picture-id :picture_id logo-id :logo_id} community-member |
| 173 | + files-w-urls (->> files |
| 174 | + (map dom.file/decode-file) |
| 175 | + (srv.file/add-files-urls config) |
| 176 | + (medley/index-by (comp str :id)))] |
| 177 | + (cond-> community-member |
| 178 | + (= "stakeholder" member-type) |
| 179 | + (assoc :picture (get-in files-w-urls [picture-id :url])) |
| 180 | + |
| 181 | + (= "organisation" member-type) |
| 182 | + (assoc :logo (get-in files-w-urls [logo-id :url]))))) |
| 183 | + |
166 | 184 | (defn get-community-members
|
167 |
| - [{:keys [db logger]} req] |
| 185 | + [{:keys [db logger] :as config} req] |
168 | 186 | (try
|
169 | 187 | (let [conn (:spec db)
|
170 | 188 | query-params (get-in req [:parameters :query])
|
|
176 | 194 | (assoc-in opts [:filters :country] (set (concat
|
177 | 195 | (get-in opts [:filters :country])
|
178 | 196 | geo-coverage-countries))))
|
179 |
| - opts)] |
180 |
| - (r/ok {:results (db.community/get-community-members conn modified-filters) |
| 197 | + opts) |
| 198 | + results (->> (db.community/get-community-members conn modified-filters) |
| 199 | + (map (partial community-member->api-community-member config)))] |
| 200 | + (r/ok {:results results |
181 | 201 | :counts (db.community/get-community-members conn (assoc modified-filters :count-only? true))}))
|
182 | 202 | (catch Throwable t
|
183 | 203 | (let [log-data {:exception-message (ex-message t)
|
|
0 commit comments