Permalink
Browse files

next step of adding db - still no persistance

  • Loading branch information...
1 parent b70cb22 commit a067a184f271757b1c0631aa366bce6cb0d57735 @verdammelt committed Mar 31, 2012
View
@@ -3,3 +3,4 @@ pom.xml
/lib/
/classes/
.lein-deps-sum
+pg
@@ -0,0 +1,3 @@
+(ns defdrink.models.shout
+ (:require [clojure.java.jdbc :as sql]))
+
@@ -0,0 +1,7 @@
+(ns defdrink.models.drinks
+ (:require [clojure.java.jdbc :as sql]))
+
+(defn all []
+ [])
+
+(defn insert [name])
@@ -0,0 +1,14 @@
+(ns defdrink.models.migration
+ (:require [clojure.java.jdbc :as sql]))
+
+(defn create-drinks []
+ (sql/with-connection (System/getenv "DATABASE_URL")
+ (sql/create-table :drinks
+ [:id :serial "PRIMARY KEY"]
+ [:name :varchar "NOT NULL"])))
+
+(defn -main []
+ (print "Migrating database...") (flush)
+ (create-drinks)
+ (println " done."))
+
@@ -0,0 +1,33 @@
+(ns defdrink.views.drinks
+ (:require
+ [defdrink.models.drinks :as drinks]
+ [defdrink.views.common :as common])
+ (:use [noir.core :as noir]
+ [hiccup.core :as html]
+ [hiccup.form-helpers :as form]))
+
+(noir/defpartial new-drink-form []
+ (label "name" "Drink Name:")
+ (text-field "name" "")
+ (form/submit-button "(defdrink)"))
+
+(noir/defpartial display-drink [{:keys [id name]}]
+ [:li {:id id} [:h3 name]])
+
+(noir/defpartial list-of-drinks []
+ (let [drinks (drinks/all)]
+ (common/layout
+ [:h1 "All Known Drinks:"]
+ [:ul#drinks
+ (map display-drink drinks)])))
+
+(defpage "/drinks" {}
+ (common/layout
+ (form/form-to [:post "/drinks" ]
+ (new-drink-form))
+ (list-of-drinks)))
+
+(defpage [:post "/drinks"] {:keys [name]}
+ (drinks/insert name)
+ (render "/drinks"))
+
@@ -1,30 +1,19 @@
(ns defdrink.views.welcome
(:require [defdrink.views.common :as common])
- (:use [noir.core :as noir]
- [hiccup.core :as html]
- [hiccup.form-helpers :as form]))
+ (:use
+ [hiccup.page-helpers :as html]
+ [noir.core :as noir]))
(noir/defpartial welcome-text []
- [:div
- [:p "(defdrink) will help you choose drinks based upon what you have in your liquor cabinet."]
+ [:div
+ [:p "(defdrink) will help you choose drinks based upon what you have in your liquor cabinet."]
- [:p "It will let you define what you have in your cabinet, to rate cocktails (so that ones you don't like one be suggested and ones you love will be suggested first"]
+ [:p "It will let you define what you have in your cabinet, to rate cocktails (so that ones you don't like one be suggested and ones you love will be suggested first"]
- [:p "Let's start simply. You can add the names of drinks and (defdrink) will remember them"]])
+ [:p "Let's start simply. You can add the names of drinks and (defdrink) will remember them"]])
-(noir/defpartial new-drink-form []
- (label "name" "Drink Name:")
- (text-field "name" "")
- (form/submit-button "(defdrink)")
- )
+(noir/defpage "/welcome" []
+ (common/layout
+ (welcome-text)
+ (html/link-to "/drinks" "Bartender - pour me a drink.")))
-
-(noir/defpage "/welcome" []
- (common/layout
- (welcome-text)
- (form/form-to [:post "/welcome"]
- (new-drink-form))
- ))
-
-(noir/defpage [:post "/welcome"] []
- (render "/welcome"))

0 comments on commit a067a18

Please sign in to comment.