# post-content.clj (ns light-poly.pedestal-docker.humor.model.post-content (:require [light-poly.pedestal-docker.util.time-util :refer [now]] [light-poly.pedestal-docker.util.uid-util :refer [uid]] [monger.collection :as mc] [monger.operators :as mo] [light-poly.pedestal-docker.humor.model.post-content :as post-content])) (def post-content-coll "post-content") (defn insert-doc [db {:keys [post-id content-id] :as data}] (let [db-post-content (mc/find-one-as-map db post-content-coll {:post-id post-id :content-id content-id})] (if (some? db-post-content) db-post-content (mc/insert-and-return db post-content-coll (merge data {:_id (uid) :created-at (now) :updated-at (now)}))))) (defn find-by-content-ids [db content-ids] (mc/find-maps db post-content-coll {:content-id {mo/$in content-ids}})) (defn find-media-by-post-ids [db post-ids] (mc/find-maps db post-content-coll {:post-id {mo/$in post-ids} :type {mo/$regex "(video|image)" mo/$options "i"}})) (defn find-docs [db condition] (mc/find-maps db post-content-coll condition))