This repository has been archived by the owner on Dec 26, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns isbnnetinclj.models.mongodb | ||
[:require [monger.core :as mg] | ||
[monger.joda-time]]) | ||
|
||
(defn init-db | ||
[] | ||
(mg/connect-via-uri! (System/getenv "MONGOHQ_URL"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns isbnnetinclj.models.requestlog | ||
[:require [isbnnetinclj.models.mongodb] | ||
[monger.collection :as mc]]) | ||
|
||
(defn add-details | ||
[request] | ||
(assoc request :isbn (.substring (:uri request) 1))) | ||
|
||
(def REQUEST_LOG "requestlog") | ||
|
||
(defn add-log | ||
[request] | ||
(mc/insert REQUEST_LOG (add-details request))) | ||
|
||
(defn get-logs | ||
[] | ||
(keep :isbn (mc/find-maps REQUEST_LOG))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
(ns isbnnetinclj.server | ||
(:gen-class) | ||
(:use noir.core) | ||
(:require [noir.server :as server])) | ||
(:require [noir.server] | ||
[noir.request] | ||
[isbnnetinclj.models.requestlog :as requestlog])) | ||
|
||
(server/load-views "src/isbnnetinclj/views/") | ||
(noir.server/load-views "src/isbnnetinclj/views/") | ||
|
||
(defpage "/:isbn" | ||
(defpage isbn-page "/:isbn" | ||
{:keys [isbn]} | ||
(str "ISBN:" isbn)) | ||
(requestlog/add-log (dissoc (noir.request/ring-request) :body)) | ||
(str (noir.request/ring-request))) | ||
|
||
(defn -main [& m] | ||
(let [mode (keyword (or (first m) :dev)) | ||
port (Integer. (get (System/getenv) "PORT" "8080"))] | ||
(server/start port {:mode mode | ||
(mongodb/init-db) | ||
(noir.server/start port {:mode mode | ||
:ns 'isbnnetinclj}))) | ||
|