Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns clj-youtube-server.core
(:require [ :as sql]
[compojure.core :refer :all]
[compojure.handler :as handler]
[ring.middleware.json :as middleware]
[ring.adapter.jetty :as ring]
[compojure.route :as route]))
(def spec (or (System/getenv "DATABASE_URL")
(defn db-exists?
(-> (sql/query spec
[(str "select count(*) from information_schema.tables where table_name='" name "'")])
first :count pos?))
(defn create-table
(when-not (db-exists? name)
(sql/db-do-commands spec
(sql/create-table-ddl name [[:comment "varchar(120)"] [:time :int]]))))
(defroutes app-routes
; serve root
(GET "/" [] {:status 200
:body {}})
; serve a specific video id
(GET "/video/:id" [id]
{:status 200
:body {:id id
:comments (get-comments id)}})
(POST "/video"
(let [id (get-in request [:params :id]) comment (get-in request [:params :comment]) time (get-in request [:params :time])]
(create-table id)
(create-comment id comment time)
{:status 200
:body {:id id
:comment comment}}))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.