Skip to content

Commit 790ded2

Browse files
committed
more uncommitted stuff
1 parent ddf2391 commit 790ded2

File tree

11 files changed

+99
-24
lines changed

11 files changed

+99
-24
lines changed

products.sql

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
INSERT INTO products (id, name, price) VALUES
2+
('13371018', 'Läsk', 5),
3+
('13371026', 'Godis', 4),
4+
('20005825', 'Lidl Mjölkchoklad', 5),
5+
('20029838', 'Lidl Mjölkchoklad med hasselnötter', 5),
6+
('20449100', 'Lidl Mjölkchoklad frukt och nötter', 5),
7+
('20543372', 'Freeway Orange', 4),
8+
('40111216', 'Bounty', 7),
9+
('76145759', 'Toblerone', 4),
10+
('5000112579321', 'Fanta', 5),
11+
('5000112579376', 'Fanta Lemon', 5),
12+
('5000112579390', 'Fanta Exotic', 5),
13+
('5000112579758', 'Cola', 5),
14+
('5000112579826', 'Cola Zero', 5),
15+
('5000112579925', 'Sprite', 5),
16+
('5000159407236', 'Mars', 7),
17+
('5000159459228', 'Twix', 7),
18+
('5000159461122', 'Snickers', 4),
19+
('5449000009500', 'Cola Cherry', 7),
20+
('5449000096982', 'Cola Vanilj', 7),
21+
('7040110663200', 'Japp', 4),
22+
('7310040018341', 'Guld Nougat', 7),
23+
('7310040020719', 'Center', 7),
24+
('7310040020726', 'Plopp', 7),
25+
('7310040027602', 'Kexchoklad', 4),
26+
('7310040028746', 'Sport Lunch', 7),
27+
('7310070000057', 'Apotekarnes julmust', 6),
28+
('7310070000361', 'Mountain Dew', 7),
29+
('7310070765802', 'Apotekarnes julmust', 4),
30+
('7310070766007', 'Pepsi', 5),
31+
('7310070766090', 'Trocadero (burk),', 5),
32+
('7310070766113', 'Zingo', 5),
33+
('7310350117482', 'Kexchoklad Choklad & Yoghurt', 4),
34+
('7310350117512', 'Sport Lunch Power Break', 3),
35+
('7310350118342', 'Kexchoklad', 6),
36+
('7310401009933', 'Trocadero', 5),
37+
('7310511251604', 'Pigall', 4),
38+
('7310511257507', 'Daim', 4),
39+
('7340131603002', 'NOCCO Citrus/Fläder', 20),
40+
('7340131606003', 'NOCCO Citron/Lime', 20),
41+
('7340131611106', 'NOCCO Apelsin', 20),
42+
('7393714236036', 'Frank', 9),
43+
('7622210406873', 'Japp all nuts', 4),
44+
('7622300386719', 'Dubbelnougat', 4);

project.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
[ring/ring-defaults "0.2.3"]
1313
[ring/ring-json "0.4.0"]
1414
[ring/ring-anti-forgery "1.1.0"]
15+
[digest "1.4.6"]
1516
[compojure "1.5.2"]
1617
[hiccup "1.0.5"]
1718
[garden "1.3.2"]
@@ -24,6 +25,7 @@
2425
[venantius/accountant "0.2.0"
2526
:exclusions [org.clojure/tools.reader]]
2627
[datascript "0.16.1"]
28+
[environ "1.1.0"]
2729
[cljs-http "0.1.43"]]
2830

2931
:plugins [[lein-environ "1.0.2"]

src/clj/frontend/db.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
(ns frontend.db
2-
(require [yesql.core :refer [defqueries]]))
2+
(require [yesql.core :refer [defqueries]]
3+
[environ.core :refer [env]]))
34

45
(def db-spec {:classname "org.postgresql.Driver"
56
:subprotocol "postgresql"
6-
:subname "//localhost:5432/fabian"
7-
:user "fabian"})
7+
:subname (env :stackomat-subname)
8+
:user (env :stackomat-user)
9+
:password (env :stackomat-password)})
810

911
(defqueries "sql/queries.sql"
1012
{:connection db-spec})

src/clj/frontend/handler.clj

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
[ring.middleware.json :refer [wrap-json-response wrap-json-body]]
77
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]]
88
[ring.util.response :refer [response content-type status]]
9+
[digest :refer [sha-256]]
910
[frontend.db :as db]
1011
[config.core :refer [env]]))
1112

1213
(def mount-target
1314
[:div#app
14-
[:h3 "ClojureScript has not been compiled!"]
15-
[:p "please run "
16-
[:b "lein figwheel"]
17-
" in order to start the compiler"]])
15+
[:h3 "Loading..."]])
1816

1917
(defn head []
2018
[:head
@@ -44,8 +42,9 @@
4442
(defn list-products []
4543
(make-response (db/list-products)))
4644

45+
4746
(defn handle-pay [request]
48-
(let [user-id (get-in request [:params :user-id])
47+
(let [user-id (sha-256 (get-in request [:params :user-id]))
4948
amount (get-in request [:body :amount])
5049
balance (db/get-balance {:id user-id})]
5150
(if (and (not (nil? balance)) ; check the user exists
@@ -56,7 +55,7 @@
5655
(make-response 403 {:message "Du har inte råd."}))))
5756

5857
(defn handle-add-money [request]
59-
(let [user-id (get-in request [:params :user-id])
58+
(let [user-id (sha-256 (get-in request [:params :user-id]))
6059
amount (get-in request [:body :amount])]
6160
(let [user (db/select-user {:id user-id})]
6261
(if (empty? user)
@@ -66,7 +65,7 @@
6665
:balance (db/get-balance {:id user-id})}))))
6766

6867
(defn get-balance [user-id]
69-
(let [balance (db/get-balance {:id user-id})]
68+
(let [balance (db/get-balance {:id (sha-256 user-id)})]
7069
(make-response {:balance balance})))
7170

7271
(defroutes routes

src/cljc/frontend/#util.cljc#

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
x(ns frontend.util)
2+
3+
(defn foo-cljc [x]
4+
"I don't do a whole lot."
5+
[x]
6+
(println x "Hello, World!"))

src/cljs/frontend/components/cart.cljs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
(ns frontend.components.cart
22
(:require [frontend.events :as events]
3+
[frontend.state :as state]
34
[frontend.components.message :refer [message]]))
45

6+
(defn message-empty? [state]
7+
(or (nil? (:message state))
8+
false))
9+
510
(defn cart-table-head []
611
[:thead
712
[:tr

src/cljs/frontend/components/login.cljs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
(:require [frontend.events :as events]
33
[reagent.core :as r]))
44

5+
(defn focus-login! []
6+
(->> "login"
7+
(.getElementById js/document)
8+
.focus))
9+
510
(defn login-input [state]
6-
(let [user-id (r/atom "")]
11+
(let [user-id (r/atom "")
12+
loginInterval (r/atom nil)]
713
(r/create-class
8-
{:component-did-mount (fn [e]
9-
(->> "login"
10-
(.getElementById js/document)
11-
.focus))
14+
{:component-did-mount (fn [e]
15+
(reset! loginInterval (.setInterval js/window focus-login! 1000))
16+
(focus-login!))
17+
18+
:component-will-unmount
19+
(reset! loginInterval (.clearInterval js/window loginInterval))
20+
1221
:render (fn []
1322
[:form {:class "login-form"
1423
:on-submit (fn [event]

src/cljs/frontend/components/message.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns frontend.components.message
2-
(:require [frontend.events :as events]))
2+
(:require [clojure.string :as string]
3+
[frontend.events :as events]))
34

45
(defn close-message-button [state]
56
[:a {:class "btn btn-default"
@@ -14,7 +15,8 @@
1415
enabled (:enabled msg)
1516
title (:title msg)
1617
type (:type msg)]
17-
(if enabled
18+
(if (and enabled (or (not (string/blank? text))
19+
(not (string/blank? title))))
1820
[:div {:class "message-background row"}
1921
[:div {:class "message-content col-sm-8 col-sm-offset-2"}
2022
[:h2 {:class (cond (= :success type) "text-success"

src/cljs/frontend/components/product-list.cljs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
[:div {:class "form-group"}
4949
[show-all-products should-show-all-products]
5050
[:input {:type "text"
51-
:style {:width "660px" :height "47px"}
5251
:id "barcodeInput"
5352
:class "form-control"
5453
:value @value
@@ -80,11 +79,18 @@
8079

8180
(defn product-list [state]
8281
(let [search-value (r/atom "")
83-
should-show-all-products (r/atom false)]
82+
should-show-all-products (r/atom false)
83+
selectBarcodeInterval (r/atom nil)]
8484
(r/create-class
8585
{:display-name "product-list-with-atom"
86+
8687
:component-did-mount
87-
(fn [e] (.focus (.getElementById js/document "barcodeInput")))
88+
(fn [e]
89+
(reset! selectBarcodeInterval (.setInterval js/window focus-barcode-input! 1000))
90+
(.focus (.getElementById js/document "barcodeInput")))
91+
92+
:component-will-unmount
93+
(reset! selectBarcodeInterval (.clearInterval js/window selectBarcodeInterval))
8894

8995
:reagent-render
9096
(fn [state]

src/cljs/frontend/handlers.cljs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@
108108
[?id :body ?response]]
109109
:function (fn ([state response]
110110
(events/send-event (:channel state)
111-
:pay-not-enough-money
111+
:paid-successfully
112112
:set-message
113113
{:type :success
114114
:title "Betalat!"
115115
:message (str "Du betalade " (.toFixed (:amount response) 2) "")})
116-
state))}
116+
(state/remove-all-chosen-products state)))}
117117

118118
{:name "pay-not-enough-money"
119119
:query '[:find ?response
@@ -184,7 +184,8 @@
184184
{:amount amount}
185185
(events/make-event :add-money :set-message {:title "Laddad!"
186186
:message (str "Du har laddad " amount ".")
187-
:type :success}))
187+
:type :success})
188+
(events/make-event :add-money :change-page {:page :purchase}))
188189
state))}
189190

190191
{:name "set-message"

0 commit comments

Comments
 (0)