open:post-content.clj

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))


  • open/post-content.clj.txt
  • 마지막으로 수정됨: 2023/07/31 10:29
  • 저자 MORO